Setu-TS
    Preparing search index...

    Interface ITelemetryService

    Telemetry service — the primary API for creating spans.

    The withSpan method is the only manual span-creation API; it ensures every span is ended in a finally block to prevent leaks.

    0.2.0

    interface ITelemetryService {
        activeSpanContext?(): SpanContext | undefined;
        withSpan<T>(
            name: string,
            fn: (span: ISpan) => Promise<T>,
            options?: SpanOptions,
        ): Promise<T>;
    }

    Implemented by

    Index
    • Reports the identifiers of the span that is active RIGHT NOW, so a signal emitted outside any span-creating call — a log record, most of all — can name the trace it belongs to.

      This is the read that joins a log line to a span. withSpan hands its own span to its callback and nothing else, so without this a consumer that is merely running inside a span has no way to ask which one; every signal the framework emits is individually good and mutually unjoinable.

      Optional, and its ABSENCE is reported rather than substituted. A service that cannot see an active span omits the method, and a consumer then enriches nothing rather than emitting empty identifiers that would join a record to a trace that does not exist. Returning undefined from an implemented method is the narrower answer: "I can see, and nothing is running".

      Implementations must not throw: a caller on the logging path cannot usefully handle a failure to describe the trace, and turning the observability read into an availability fault is strictly worse than emitting an unjoined record. Callers guard anyway (a replaceable capability can be anything), but the contract is no-throw.

      Returns SpanContext | undefined

      The active span's identifiers, or undefined when no span is active — including when span activation is switched off (contextPropagation: false), since nothing is then active to report

      0.5.0

    • Creates a span, runs the callback, and ends the span.

      The span is guaranteed to be ended exactly once, even if the callback throws. The callback receives an ISpan that it can attach attributes to.

      Type Parameters

      • T

        The return type of the callback

      Parameters

      • name: string

        The span name

      • fn: (span: ISpan) => Promise<T>

        Callback receiving the span; its return value is forwarded

      • Optionaloptions: SpanOptions

        Optional span options (kind, attributes, parentContext, root)

      Returns Promise<T>

      The value returned by fn

      const telemetry = ctx.services.get<ITelemetryService>(CAPABILITIES.TELEMETRY);
      const result = await telemetry.withSpan('create-order', async (span) => {
      span.setAttribute('order.id', orderId);
      return await orderService.create(orderId);
      });