OpenTelemetry Propagator B3

NPM Published Version Apache License

The OpenTelemetry b3 propagator package provides multiple propagator implementations for systems using the b3 context format. See the b3 specification for complete details.

B3 Formats

Single-Header Format:

b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}

Multi-Header Format:

X-B3-TraceId: {TraceId}
X-B3-SpanId: {SpanId}
X-B3-ParentSpanId: {ParentSpanId}
X-B3-Sampled: {SamplingState}

B3 Propagation

The default B3Propagator implements b3 propagation according to the OpenTelemetry specification. It extracts b3 context from multi and single header encodings and injects context using the single-header b3 encoding by default. The inject encoding can be changed to multi-header via configuration. See the examples below.

B3 Single-Header Configuration

const api = require('@opentelemetry/api');
const { B3Propagator } = require('@opentelemetry/propagator-b3');

api.propagation.setGlobalPropagator(new B3Propagator());

B3 Multi-Header Configuration

const api = require('@opentelemetry/api');
const { B3Propagator, B3InjectEncoding } = require('@opentelemetry/propagator-b3');

api.propagation.setGlobalPropagator(
  new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER })
);

B3 Single and Multi-Header Configuration

The B3Propagator always extracts both the single and multi-header b3 encodings. If you need to inject both encodings this can accomplished using a composite propagator.

const api = require('@opentelemetry/api');
const { CompositePropagator } = require('@opentelemetry/core');
const { B3Propagator, B3InjectEncoding } = require('@opentelemetry/propagator-b3');
api.propagation.setGlobalPropagator(
  new CompositePropagator({
    propagators: [
      new B3Propagator(),
      new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),
    ],
  })
);

License

Apache 2.0 - See LICENSE for more information.