Interface for OpenTelemetry trace operations. This interface provides span creation, context management, and trace provider operations that are common across different SDK implementations (Core, AISKU, etc.).

3.4.0

interface ITraceHost<CfgType> {
    config: CfgType;
    getActiveSpan(createNew?: boolean): IReadableSpan;
    getTraceCtx(createNew?: boolean): IDistributedTraceContext;
    getTraceProvider(): ITraceProvider;
    setActiveSpan(span: IReadableSpan): ISpanScope<ITraceHost<IConfiguration>>;
    setTraceCtx(newTraceCtx: IDistributedTraceContext): void;
    startSpan(name: string, options?: IOTelSpanOptions, parent?: IDistributedTraceContext): IReadableSpan;
}

Type Parameters

Hierarchy (view full)

Properties

config: CfgType

Methods

  • Return the current active span, if no trace provider is available null will be returned but when a trace provider is available a span instance will always be returned, even if there is no active span (in which case a non-recording span will be returned).

    Parameters

    • OptionalcreateNew: boolean

      Optional flag to create a non-recording span if no active span exists, defaults to true. When false, returns the existing active span or null without creating a non-recording span, which can improve performance when only checking if an active span exists.

    Returns IReadableSpan

    The current active span or null if no trace provider is available or if createNew is false and no active span exists

    3.4.0

  • Start a new span with the given name and optional parent context.

    Note: This method only creates and returns the span. It does not automatically set the span as the active trace context. Context management should be handled separately using setTraceCtx() if needed.

    Parameters

    • name: string

      The name of the span

    • Optionaloptions: IOTelSpanOptions

      Options for creating the span (kind, attributes, startTime)

    • Optionalparent: IDistributedTraceContext

      Optional parent context. If not provided, uses the current active trace context

    Returns IReadableSpan

    A new span instance, or null if no trace provider is available

    3.4.0