/** * @module * This module provides functions for creating spans. */ import type { SpanKind } from "@opentelemetry/api"; import { Level } from "./level.js"; /** * The AnonymousSpanId type represents a span ID produced by an unknown (anonymous) subscriber. It is a branded type, and * the `__anonymousSpanId` property does not exist at runtime. */ export type AnonymousSpanId = { __anonymousSpanId?: true; }; /** * Additional span data can be passed to the `OpenTelemetrySubscriber`. */ export type OpenTelemetrySubscriberData = { /** * The [OpenTelemetry Span Kind](https://opentelemetry.io/docs/concepts/signals/traces/#span-kind) */ kind?: SpanKind; }; /** * Additional subscriber specific span data. */ export interface SubscriberData extends Record { /** * Additional span data for the `FmtSubscriber` */ fmt?: never; /** * Additional span data for the `JsonSubscriber` */ json?: never; /** * Additional span data for the `OpenTelemetrySubscriber` */ otel?: OpenTelemetrySubscriberData; } /** * The SpanAttributes type represents the information which is passed to subscribers when a span is created. */ export type SpanAttributes = { isSpan: true; level: Level; message: string; fields?: Record; subscriberData?: SubscriberData; }; /** * The EnteredSpan type represents a span which has been entered. Entered spans are compatible with the stage 3 * [explicit resource management proposal](https://github.com/tc39/proposal-explicit-resource-management). */ export type EnteredSpan = { /** * Exits the span. */ exit: () => void; /** * Record a field on the span. */ record(key: string, value: unknown): EnteredSpan; [Symbol.dispose]: () => void; }; /** * The Span type represents a span which has not yet been entered. */ export type Span = { /** * @internal * The ID of the span. This is an opaque value which is used by the subscriber to identify the span. */ _id?: TSpanId; /** * Enters the span. */ enter(): EnteredSpan; /** * Record a field on the span. */ record(key: string, value: unknown): Span; }; /** * Creates a new span and passes it to the current subscriber. * * @param level The level of the span * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function span(level: Level, message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new trace level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function traceSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new debug level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function debugSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new info level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function infoSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new warn level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function warnSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new error level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function errorSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Creates a new critical level span and passes it to the current subscriber. * * @param message The message of the span * @param fields The fields of the span (optional additional information) * @param subscriberData Optional subscriber specific data relating to the span. * @returns An unentered span */ export declare function criticalSpan(message: string, fields?: Record, subscriberData?: TSubscriberData): Span; /** * Returns the current entered span. If no span is currently entered, `undefined` is returned. * * @returns The current entered span or `undefined` */ export declare function currentSpan(): EnteredSpan | undefined; //# sourceMappingURL=span.d.ts.map