@zendesk/retrace
Version:
define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API
40 lines (39 loc) • 3.56 kB
TypeScript
import type { SpanAndAnnotation } from './spanAnnotationTypes';
import type { FinalTransition } from './Trace';
import type { TraceRecording } from './traceRecordingTypes';
import type { RelationSchemasBase, TraceContext } from './types';
/**
* ### Deriving SLIs and other metrics from a trace
*
* ℹ️ It is our recommendation that the primary way of creating duration metrics would be to derive them from data in the trace.
*
* Instead of the traditional approach of capturing isolated metrics imperatively in the code,
* the **trace** model allows us the flexibility to define and compute any number of metrics from the **trace recording**.
*
* We can distinguish the following types of metrics:
*
* 1. **Duration of a Computed Span** — the time between any two **spans** that appeared in the **trace**. For example:
* 1. _time between the user’s click on a ticket_ and _everything in the ticket page has fully rendered with content_ (duration of the entire operation)
* 2. _time between the user’s click on a ticket_ and _the moment the first piece of the ticket UI was displayed_ (duration of a segment of the operation)
*
* 2. **Computed Values** — any numerical value derived from the **spans** or their attributes. For example:
* 1. _The total number of times the log component re-rendered while loading the ticket_
* 2. _The total number of requests made while loading the ticket_
* 3. _The total number of iframe apps were initialized while loading the ticket_
*/
export declare function getComputedValues<SelectedRelationNameT extends keyof RelationSchemasT, RelationSchemasT extends RelationSchemasBase<RelationSchemasT>, const VariantsT extends string>(context: TraceContext<SelectedRelationNameT, RelationSchemasT, VariantsT>): TraceRecording<SelectedRelationNameT, RelationSchemasT>['computedValues'];
export declare function getComputedSpans<SelectedRelationNameT extends keyof RelationSchemasT, RelationSchemasT extends RelationSchemasBase<RelationSchemasT>, const VariantsT extends string>(context: TraceContext<SelectedRelationNameT, RelationSchemasT, VariantsT>, finalState?: {
completeSpanAndAnnotation?: SpanAndAnnotation<RelationSchemasT>;
cpuIdleSpanAndAnnotation?: SpanAndAnnotation<RelationSchemasT>;
}): TraceRecording<SelectedRelationNameT, RelationSchemasT>['computedSpans'];
type ChildrenMap = Map<string, string[]>;
type SpanMap<RelationSchemasT extends RelationSchemasBase<RelationSchemasT>> = ReadonlyMap<string, SpanAndAnnotation<RelationSchemasT>>;
interface PropagationConfig<RelationSchemasT extends RelationSchemasBase<RelationSchemasT>> {
/** attribute keys that flow *downward* unless child overrides */
heritableSpanAttributes?: readonly string[];
/** stops errors bubbling *upward* if true */
shouldSuppressErrorStatusPropagation: (spanAndAnnotation: SpanAndAnnotation<RelationSchemasT>) => boolean;
}
export declare function propagateStatusAndAttributes<const RelationSchemasT extends RelationSchemasBase<RelationSchemasT>>(idToSpanAndAnnotationMap: SpanMap<RelationSchemasT>, children: ChildrenMap, cfg: PropagationConfig<RelationSchemasT>): void;
export declare function createTraceRecording<const SelectedRelationNameT extends keyof RelationSchemasT, const RelationSchemasT extends RelationSchemasBase<RelationSchemasT>, const VariantsT extends string>(context: TraceContext<SelectedRelationNameT, RelationSchemasT, VariantsT>, transition: FinalTransition<RelationSchemasT>): TraceRecording<SelectedRelationNameT, RelationSchemasT>;
export {};