Connect trace context with database commands

This guide describes how to extend database telemetry with trace context propagation using OpenTelemetry for Node.js.

Check compatibility and requirements

Before enabling trace context propagation, review the required runtime, configuration, and database conditions. These prerequisites ensure that OpenTelemetry features can operate correctly and safely in your environment.

Runtime compatibility

Trace context propagation is supported only under specific runtime conditions:

  • Requires Node.js version 18 or higher.
  • Applies exclusively to applications using Microsoft SQL Server with the tedious driver.
  • The only supported instrumentation is for tedious. No other database instrumentations are available at this time.

Configuration option

To enable trace context propagation for Microsoft SQL Server in OpenTelemetry for Node.js, set the following configuration option:

Table 1. Trace context configuration
Configuration optionDefault valueDescription
enableTraceContextPropagation falseEnables trace context propagation using SET CONTEXT_INFO for the current connection.
This uses the SET CONTEXT_INFO command to set trace context information for the current connection, which results in an additional round-trip to the database.

Enable trace context propagation

To activate trace context propagation:

  1. Confirm that your application meets the compatibility requirements listed above.
  2. Use the tedious driver to connect to Microsoft SQL Server.
  3. Configure the OpenTelemetry instrumentation with enableTraceContextPropagation: true
  4. Execute database commands within an active trace context.
Once enabled, trace context information will be embedded in the connection context, allowing SQL commands to be linked to the current trace.
Note: This guide focuses on enabling trace context propagation. For guidance on analyzing database spans or correlating SQL activity with traces, refer to APM documentation.