import { AttributeValue, Span as OtelSpan, Tracer as OtelTracer } from '@opentelemetry/api'; import { destructor } from '@synnaxlabs/x'; import { Environment, EnvironmentFilter } from './environment'; import { Meta } from './meta'; /** Carrier is an entitty that can carry trace metadata across process bounds */ export type Carrier = Record; /** Function that executes under the given span */ export type SpanF = (span: Span) => unknown; /** * Tracer wraps an opentelemetry tracer to provide an opinionated intreface * for tracing within the Synnax stack. */ export declare class Tracer { private meta; private readonly otelTracer?; private readonly filter; constructor(tracer?: OtelTracer, filter?: EnvironmentFilter); child(meta: Meta): Tracer; debug(key: string): destructor.Destructor; debug(key: string, f: F): ReturnType; bench(key: string): destructor.Destructor; bench(key: string, f: F): ReturnType; prod(key: string): destructor.Destructor; prod(key: string, f: F): ReturnType; trace(key: string, env: Environment): destructor.Destructor; trace(key: string, env: Environment, f: F): ReturnType; trace(key: string, env: Environment, f?: F): ReturnType | destructor.Destructor; /** * Injects metadata about the current trace into the provided carrier. This metadata * can be parsed on the other side of a network or IPC request to allow the trace to * propagate across services. * * @param carrier - The carrier to inject the metadata into. */ propagate(carrier: Carrier): void; /** Tracer implementation that does nothing */ static readonly NOOP: Tracer; } /** A span in a trace that can be used to track function execution */ export interface Span { /** * The key identifying the span. This is the name of the key * passed into the tracing method combined with the path of the * instrumentation that started the span. For example, take the * instrumentation titled 'synnax' and call to trace with 'test. * The span key would be 'synnax.test'. */ key: string; /** * If the error is not null, records the error in the span and sets * its status to error. */ recordError: (error?: Error | null) => void; /** * Sets the given key-value pair as an attribute on the span. */ set: (key: string, value: AttributeValue) => void; } export declare class _Span implements Span { key: string; private readonly otel; constructor(key: string, span: OtelSpan); set(key: string, value: AttributeValue): void; recordError(error?: Error | null): void; start(): void; end(): void; } /** Span implementation that does nothing */ export declare class NoopSpan implements Span { key: string; constructor(key: string); set(): void; recordError(_?: Error | null): void; } //# sourceMappingURL=trace.d.ts.map