@zendesk/retrace
Version:
define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API
66 lines (65 loc) • 4.96 kB
TypeScript
import type { Observable } from 'rxjs';
import type { AllPossibleAddSpanToRecordingEvents, AllPossibleDefinitionModifiedEvents, AllPossibleRequiredSpanSeenEvents, AllPossibleStateTransitionEvents, AllPossibleTraceStartEvents } from './debugTypes';
import { type SpanMatch } from './matchSpan';
import type { ProcessedSpan } from './spanAnnotationTypes';
import { type ComponentRenderSpan, type ConvenienceSpan, type ErrorSpan, type ErrorSpanInput, type PerformanceEntrySpan, type PerformanceEntrySpanInput, type RenderSpanInput, type Span } from './spanTypes';
import { TickParentResolver } from './TickParentResolver';
import { Tracer } from './Tracer';
import type { AllPossibleTraceContexts, ComputedValueDefinitionInput, RelationSchemasBase, ReportErrorFn, TraceDefinition, TraceManagerConfig } from './types';
/**
* Class representing the centralized trace manager.
* Usually you'll have a single instance of this class in your app.
*/
export declare class TraceManager<const RelationSchemasT extends RelationSchemasBase<RelationSchemasT>> {
private currentTrace;
private eventSubjects;
get currentTraceContext(): AllPossibleTraceContexts<RelationSchemasT, string> | undefined;
tickParentResolver: TickParentResolver<RelationSchemasT> | undefined;
constructor({ enableTickTracking, ...configInput }: Omit<TraceManagerConfig<RelationSchemasT>, 'reportWarningFn'> & {
reportWarningFn?: ReportErrorFn<RelationSchemasT>;
});
/**
* Subscribe to events from a trace and forward them to the TraceManager subjects
*/
private subscribeToTraceEvents;
/**
* Observable for events from all traces
* @param event The event type to observe
* @returns An Observable that emits events of the specified type from all traces
*/
when(event: 'trace-start'): Observable<AllPossibleTraceStartEvents<RelationSchemasT>>;
when(event: 'state-transition'): Observable<AllPossibleStateTransitionEvents<RelationSchemasT>>;
when(event: 'required-span-seen'): Observable<AllPossibleRequiredSpanSeenEvents<RelationSchemasT>>;
when(event: 'add-span-to-recording'): Observable<AllPossibleAddSpanToRecordingEvents<RelationSchemasT>>;
when(event: 'definition-modified'): Observable<AllPossibleDefinitionModifiedEvents<RelationSchemasT>>;
private utilities;
createTracer<const SelectedRelationNameT extends keyof RelationSchemasT, const VariantsT extends string, const ComputedValueTuplesT extends {
[K in keyof ComputedValueTuplesT]: SpanMatch<NoInfer<SelectedRelationNameT>, RelationSchemasT, NoInfer<VariantsT>>[];
}>(traceDefinition: TraceDefinition<SelectedRelationNameT, RelationSchemasT, VariantsT, {
[K in keyof ComputedValueTuplesT]: ComputedValueDefinitionInput<NoInfer<SelectedRelationNameT>, RelationSchemasT, NoInfer<VariantsT>, ComputedValueTuplesT[K]>;
}>): Tracer<SelectedRelationNameT, RelationSchemasT, VariantsT>;
/**
* Internal use only.
* Use createAndProcessSpan to create a valid span, and process it immediately.
* @internal
*/
processSpan<SpanT extends Span<RelationSchemasT>>(inputSpan: SpanT, isEndingSpan?: boolean): ProcessedSpan<RelationSchemasT, SpanT>;
ensureCompleteSpan<SpanT extends Span<RelationSchemasT>>({ parentSpan, parentSpanMatcher, ...partialSpan }: ConvenienceSpan<RelationSchemasT, SpanT>): SpanT;
endSpan<SpanT extends Span<RelationSchemasT>>(startSpan: SpanT, { parentSpanMatcher, parentSpan, ...endSpanAttributes }?: Partial<Omit<ConvenienceSpan<RelationSchemasT, SpanT>, 'id'>>): ProcessedSpan<RelationSchemasT, SpanT>;
processErrorSpan(partialSpan: ErrorSpanInput<RelationSchemasT>): ProcessedSpan<RelationSchemasT, ErrorSpan<RelationSchemasT>>;
createAndProcessSpan<SpanT extends Span<RelationSchemasT>>(partialSpan: ConvenienceSpan<RelationSchemasT, SpanT>): ProcessedSpan<RelationSchemasT, SpanT>;
makePerformanceEntrySpan(partialSpan: PerformanceEntrySpanInput<RelationSchemasT>): PerformanceEntrySpan<RelationSchemasT>;
makeRenderSpan(partialSpan: RenderSpanInput<RelationSchemasT>): ComponentRenderSpan<RelationSchemasT>;
startRenderSpan({ kind, ...startSpanInput }: Omit<RenderSpanInput<RelationSchemasT>, 'type'> & {
kind?: 'component' | 'hook';
}): ProcessedSpan<RelationSchemasT, ComponentRenderSpan<RelationSchemasT>>;
endRenderSpan(startSpan: ComponentRenderSpan<RelationSchemasT>, endSpanAttributes?: Partial<ComponentRenderSpan<RelationSchemasT>> & {
duration: number;
}): ProcessedSpan<RelationSchemasT, ComponentRenderSpan<RelationSchemasT>>;
/**
* Finds the first span matching the provided SpanMatch in the parent hierarchy
* of the given Span, starting with the span itself and traversing up
* through its parents.
*/
findSpanInParentHierarchy(span: Span<RelationSchemasT>, spanMatch: SpanMatch<keyof RelationSchemasT, RelationSchemasT, any>): Span<RelationSchemasT> | undefined;
}