@tigorhutasuhut/telemetry-js - v0.7.3
    Preparing search index...

    Function injectContext

    • Inject trace context into an arbitrary value using the globally registered textmap propagator.

      • If value is a non-null object, propagation fields (traceparent, tracestate, etc.) are merged into a shallow copy and the augmented object is returned.
      • For any other type the value is returned unchanged.

      Type Parameters

      • T = unknown

      Parameters

      • value: T

        The value to (potentially) augment with trace context.

      • Optionalopts: InjectContextOptions

        Optional settings (e.g. explicit Context).

      Returns Carrier<T>

      The original value (non-objects) or a new object with propagation fields added.

      // Object — trace context is injected from the active context
      const params = injectContext({ userId: "abc" });
      // => { userId: "abc", traceparent: "00-…", tracestate: "…" }

      // Explicit context
      const params = injectContext({ userId: "abc" }, { context: parentCtx });

      // Non-object — returned as-is
      const str = injectContext("hello");
      // => "hello"