/** * Minimal subset of `@opentelemetry/api` types used by the SDK 2.0 tracing layer. * * The SDK doesn't `import` `@opentelemetry/api` directly — it stays an OPTIONAL * peer dependency. Consumers BYO the module and pass it via `ClientOptions.otel`, * or the SDK reads it from the global `@opentelemetry/api` registry by trying a * dynamic resolve. Either way, only this surface is touched, so the SDK compiles * and runs without `@opentelemetry/api` installed. * * Shape mirrors `@opentelemetry/api@1.x`: * - `OTelSpan` ↔ `Span` * - `OTelTracer` ↔ `Tracer` * - `OTelContext` ↔ `Context` (opaque from our side) * - `OTelContextAPI` ↔ `ContextAPI` * - `OTelTraceAPI` ↔ `TraceAPI` * - `OTelAPI` ↔ the module object * * If a consumer hasn't configured OTel globally and doesn't pass `otel`, the SDK * no-ops cleanly — no warnings, no bundled fallback TracerProvider. */ /** * SpanContext shape — the serializable identity of a span. Returned by * `OTelSpan.spanContext()`; what we serialize into a W3C `traceparent`. */ export interface OTelSpanContext { /** 32 lowercase hex characters (128 bits). */ readonly traceId: string; /** 16 lowercase hex characters (64 bits). */ readonly spanId: string; /** 1 byte (bitmap) — sampled flag is bit 0. */ readonly traceFlags: number; /** Optional vendor-specific propagation data. The OTel TraceState exposes `serialize()`. */ readonly traceState?: { serialize(): string; } | undefined; /** True if the SpanContext was extracted from a remote parent. */ readonly isRemote?: boolean; } export interface OTelSpan { /** Returns the immutable identity of this span. Usable even after the span ends. */ spanContext(): OTelSpanContext; /** Sets a single attribute. Returns `this` for chaining. */ setAttribute(key: string, value: string | number | boolean): this; /** Sets the span's status. `ERROR` is sticky relative to `OK`. */ setStatus(status: { code: number; message?: string; }): this; /** Records an exception as a span event. */ recordException(exception: Error | string): void; /** Adds a span event. */ addEvent(name: string, attributes?: Record): this; /** Updates the span's name post-creation. */ updateName?(name: string): this; /** Whether the span is recording (sampled). Used to short-circuit attribute work. */ isRecording(): boolean; /** Marks the end of the span. */ end(endTime?: number): void; } export interface OTelSpanOptions { readonly attributes?: Record; readonly startTime?: number; /** Span kind hint (CLIENT = 2 — what the SDK uses for outbound network ops). Optional. */ readonly kind?: number; } export interface OTelTracer { /** * Start a span without making it active. Caller is responsible for ending it * and (if desired) activating its context. */ startSpan(name: string, options?: OTelSpanOptions, context?: OTelContext): OTelSpan; /** * Start a span and run `fn` in a context where this span is active. The * SDK uses the 2-arg overload (no explicit options) and the 3-arg overload * (with options) — it does NOT use the 4-arg context-pinning form. */ startActiveSpan unknown>(name: string, fn: F): ReturnType; startActiveSpan unknown>(name: string, options: OTelSpanOptions, fn: F): ReturnType; } export type OTelContext = object; export interface OTelContextAPI { /** Currently-active context. */ active(): OTelContext; /** Run `fn` with `context` as the active context. */ with ReturnType>(context: OTelContext, fn: F, thisArg?: ThisParameterType, ...args: A): ReturnType; } export interface OTelTraceAPI { /** Get a tracer for the SDK. */ getTracer(name: string, version?: string): OTelTracer; /** Currently-active span (if any). */ getActiveSpan(): OTelSpan | undefined; /** Span attached to the given context (if any). */ getSpan(context: OTelContext): OTelSpan | undefined; /** Attach a span to a context. */ setSpan(context: OTelContext, span: OTelSpan): OTelContext; } /** * The OTel API surface the SDK needs. Pass the real `@opentelemetry/api` module * (or a compatible subset) via `ClientOptions.otel`. The SDK also auto-resolves * the global module via dynamic `import('@opentelemetry/api')` when it isn't * passed explicitly; if neither path produces an API, the tracing layer no-ops. */ export interface OTelAPI { trace: OTelTraceAPI; context: OTelContextAPI; SpanStatusCode: { readonly OK: number; readonly ERROR: number; readonly UNSET?: number; }; SpanKind?: { readonly INTERNAL: number; readonly CLIENT: number; readonly SERVER: number; readonly PRODUCER: number; readonly CONSUMER: number; }; } //# sourceMappingURL=types.d.ts.map