UNPKG

@zendesk/retrace

Version:

define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API

48 lines (47 loc) 3.09 kB
import type { SpanMatch } from './matchSpan'; import type { DraftTraceConfig, StartTraceConfig } from './spanTypes'; import { type CompleteTraceDefinition, type ComputedSpanDefinitionInput, type ComputedValueDefinitionInput, type DraftTraceContext, type RelationSchemasBase, type TraceDefinitionModifications, type TraceManagerUtilities, type TraceModifications, type TransitionDraftOptions } from './types'; /** * Tracer can create draft traces and start traces */ export declare class Tracer<const SelectedRelationNameT extends keyof RelationSchemasT, const RelationSchemasT extends RelationSchemasBase<RelationSchemasT>, const VariantsT extends string> { private definition; private rootTraceUtilities; constructor(definition: CompleteTraceDefinition<SelectedRelationNameT, RelationSchemasT, VariantsT>, rootTraceUtilities: TraceManagerUtilities<RelationSchemasT>); /** * @returns The ID of the trace. */ start: (input: StartTraceConfig<RelationSchemasT[SelectedRelationNameT], VariantsT>, definitionModifications?: TraceDefinitionModifications<SelectedRelationNameT, RelationSchemasT, VariantsT>) => string | undefined; createDraft: (input: Omit<DraftTraceConfig<RelationSchemasT[SelectedRelationNameT], VariantsT>, "relatedTo">, definitionModifications?: TraceDefinitionModifications<SelectedRelationNameT, RelationSchemasT, VariantsT>) => string | undefined; private createDraftInternal; interrupt: ({ error }?: { error?: Error; }) => void; /** * Adds additional required spans or debounce spans to the current trace *only*. * Note: This recreates the Trace instance with the modified definition and replays all the spans. */ addRequirementsToCurrentTraceOnly: (definitionModifications: TraceDefinitionModifications<SelectedRelationNameT, RelationSchemasT, VariantsT>) => void; transitionDraftToActive: (inputAndDefinitionModifications: TraceModifications<SelectedRelationNameT, RelationSchemasT, VariantsT>, opts?: TransitionDraftOptions) => void; private getCurrentTraceInternal; /** * @returns The current Trace's context if it exists anywhere in the trace tree, * and matches the Tracer's definition. */ getCurrentTrace: () => DraftTraceContext<SelectedRelationNameT, RelationSchemasT, VariantsT> | undefined; private getCurrentTraceOrWarn; /** * Dynamically add a computed span to the trace definition. * Will apply to any trace created *after* calling this function. */ defineComputedSpan: (definition: ComputedSpanDefinitionInput<SelectedRelationNameT, RelationSchemasT, VariantsT> & { name: string; }) => void; /** * Dynamically add a computed value to the trace definition. * Will apply to any trace created *after* calling this function. */ defineComputedValue: <const MatchersT extends SpanMatch<SelectedRelationNameT, RelationSchemasT, VariantsT>[]>(definition: ComputedValueDefinitionInput<SelectedRelationNameT, RelationSchemasT, VariantsT, MatchersT> & { name: string; }) => void; }