Socket
Socket
Sign inDemoInstall

@opentelemetry/propagator-b3

Package Overview
Dependencies
3
Maintainers
3
Versions
114
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @opentelemetry/propagator-b3

OpenTelemetry B3 propagator provides context propagation for systems that are using the B3 header format


Version published
Weekly downloads
2.3M
increased by2.43%
Maintainers
3
Install size
2.55 MB
Created
Weekly downloads
 

Package description

What is @opentelemetry/propagator-b3?

The @opentelemetry/propagator-b3 npm package is used for B3 propagation format which is a convention for passing trace context information across service boundaries. It supports both single-header and multi-header encoding. This package is part of the OpenTelemetry project which provides a collection of tools, APIs, and SDKs to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) to help analyze a software's performance and behavior.

What are @opentelemetry/propagator-b3's main functionalities?

B3 Propagation

This feature allows the user to extract and inject B3 propagation headers. The B3Propagator can be set as the global propagator in OpenTelemetry.

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

// Use the B3Propagator for extracting and injecting
propagation.setGlobalPropagator(new B3Propagator());

B3 Multi-header Propagation

This feature supports the B3 multi-header propagation format, which uses multiple headers to transmit tracing information. It is useful when interacting with systems that expect B3 headers in multiple header format.

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

// Use the B3MultiPropagator for extracting and injecting with multi-header support
propagation.setGlobalPropagator(new B3MultiPropagator());

Other packages similar to @opentelemetry/propagator-b3

Changelog

Source

1.24.0

:rocket: (Enhancement)

  • feat(sdk-trace-base): log resource attributes in ConsoleSpanExporter #4605 @pichlermarc
  • feat(propagator-aws-xray): moved AWS Xray propagator from contrib 4603 @martinkuba
  • feat(resources): new experimental detector ServiceInstanceIdDetectorSync that sets the value for service.instance.id as random UUID. #4608 @maryliag

:bug: (Bug Fix)

  • fix(sdk-trace-web): fix invalid timings in span events #4486 @Abinet18
  • fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser #4561 @trentm

Readme

Source

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}
  • {TraceId}

    • Required
    • Encoded as 32 or 16 lower-hex characters
    • 16 character traceIds will be converted to 32 characters by left-padding with 0s to conform with the OpenTelemetry specification
  • {SpanId}

    • Required
    • Encoded as 16 lower-hex characters
  • {ParentSpanId}

    • Optional
    • Used to support the Zipkin functionality where the client and server spans that make up an HTTP request share the same id
    • Not propagated by this library
  • {SamplingState} - Single-header

    • Optional
    • Valid values
      • 1 - Accept
      • 0 - Deny
      • d - Debug
      • Absent - Defer sampling decision
  • {SamplingState} - Multi-header

    • Optional
    • Valid values
      • 1 - Accept
      • 0 - Deny
  • {Flags} - Multi-header

    • Optional
    • Debug is encoded as X-B3-Flags: 1. Absent or any other value can be ignored. Debug implies an accept decision, so don't also send the X-B3-Sampled header.

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.

Keywords

FAQs

Last updated on 24 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc