Skip to content

JAVA-6222 Support trace context propagation to the server#2022

Open
nhachicha wants to merge 49 commits into
mongodb:mainfrom
nhachicha:nabil_otel_context
Open

JAVA-6222 Support trace context propagation to the server#2022
nhachicha wants to merge 49 commits into
mongodb:mainfrom
nhachicha:nabil_otel_context

Conversation

@nhachicha

@nhachicha nhachicha commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

nhachicha added 30 commits June 1, 2026 18:51
Spec proposal (OP_MSG section kind 3, W3C traceparent, hello tracingSupport
negotiation) plus driver-sync POC design to validate it.
Executed end-to-end against mongodb-mongo-master ee3a67f8 (9.0.0-alpha0):
ServerSpanLinkageProseTest passes. Confirmed real server parameters
(featureFlagOtelTraceSampling, openTelemetryTracingSampling BSON doc,
opentelemetryTraceDirectory) and NDJSON export format. Fixed the prose
test to assert operation-span parentage: the driver injects the
traceparent from the OperationContext's operation span (per design 3.1),
so the server span is a sibling of the client command span.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds W3C traceparent propagation support to the server via a new OP_MSG telemetry section (wire version 29+), integrating with Micrometer tracing while keeping micrometer-tracing optional and guarded to avoid classpath linkage errors.

Changes:

  • Add OP_MSG kind-3 telemetry section encoding ({otel: {traceparent: ...}}) when a traced command span is available and the server wire version supports it.
  • Extend Micrometer tracing integration with TraceContext#traceParent() and a classpath guard to safely operate without micrometer-tracing present.
  • Add unit tests covering traceparent formatting/validation, classpath-absence safety, and command message telemetry section encoding/ordering.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gradle/libs.versions.toml Adds a Micrometer tracing library alias to support optional tracing integration.
driver-core/build.gradle.kts Adds optional micrometer-tracing plus tracing test dependencies for new unit tests.
driver-core/src/test/unit/com/mongodb/internal/observability/micrometer/MicrometerTraceParentTest.java Verifies traceparent formatting/validation and no-linkage-error behavior when tracing is absent.
driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageOtelTraceContextTest.java Validates telemetry section encoding, ordering vs sequences, and command reconstruction behavior.
driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java Introduces wire version constant for server 9.0 / wire version 29.
driver-core/src/main/com/mongodb/internal/observability/micrometer/TracingManager.java Uses CommandMessage helpers instead of needing the encoded command document to populate tracing context.
driver-core/src/main/com/mongodb/internal/observability/micrometer/TraceContext.java Adds traceParent() API for W3C context propagation.
driver-core/src/main/com/mongodb/internal/observability/micrometer/Span.java Clarifies scope open/close semantics and no-op close behavior.
driver-core/src/main/com/mongodb/internal/observability/micrometer/MicrometerTracer.java Implements traceParent() with optional-dependency guard and validation to avoid emitting rejected traceparents.
driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java Ensures encoding can attach telemetry section by passing the tracing span into message encoding.
driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java Adds telemetry-section encoding + helpers (getCommandName, getGetMoreCursorId) and updates command reconstruction to ignore telemetry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java Outdated
Comment thread driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java:38

  • LATEST_WIRE_VERSION is still set to the 8.0 value even though this PR introduces NINE_DOT_ZERO_WIRE_VERSION. This makes the constant name misleading and causes unit tests that use LATEST_WIRE_VERSION to stop representing the newest supported wire version.
    // Server 9.0 (WIRE_VERSION_90 = 29). Minimum wire version for the OP_MSG telemetry
    // section (OTel trace-context propagation, DRIVERS-3454).
    public static final int NINE_DOT_ZERO_WIRE_VERSION = 29;
    public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION;

Comment thread gradle/libs.versions.toml Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java:37

  • LATEST_WIRE_VERSION is now inconsistent with the newly introduced NINE_DOT_ZERO_WIRE_VERSION constant. Keeping it pinned to 8.0 makes test utilities and any future uses of LATEST_WIRE_VERSION silently exclude wire version 29 features (like OP_MSG telemetry).
    // Server 9.0 (WIRE_VERSION_90 = 29). Minimum wire version for the OP_MSG telemetry
    // section (OTel trace-context propagation, DRIVERS-3454).
    public static final int NINE_DOT_ZERO_WIRE_VERSION = 29;
    public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION;

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

driver-core/src/main/com/mongodb/internal/operation/ServerVersionHelper.java:38

  • LATEST_WIRE_VERSION is now inconsistent with the newly added NINE_DOT_ZERO_WIRE_VERSION constant (the file comments call 9.0 / wire version 29 the minimum for telemetry support, but LATEST_WIRE_VERSION still points at 8.0 / 25). This makes the meaning of “latest” ambiguous for test setups that import LATEST_WIRE_VERSION.

Consider either updating LATEST_WIRE_VERSION to NINE_DOT_ZERO_WIRE_VERSION, or adjusting naming/docs to clarify why 8.0 remains the “latest” for the driver/test suite.

    // Server 9.0 (WIRE_VERSION_90 = 29). Minimum wire version for the OP_MSG telemetry
    // section (OTel trace-context propagation, DRIVERS-3454).
    public static final int NINE_DOT_ZERO_WIRE_VERSION = 29;
    public static final int LATEST_WIRE_VERSION = EIGHT_DOT_ZERO_WIRE_VERSION;

driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java:221

  • Javadoc has an unbalanced parenthesis: “(first key of the command document.” should be “(first key of the command document).”
     * The command name (first key of the command document. Available before {@code encode()} runs, unlike

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@nhachicha
nhachicha requested a review from rozza July 23, 2026 14:50
@nhachicha
nhachicha marked this pull request as ready for review July 23, 2026 14:50
@nhachicha
nhachicha requested a review from a team as a code owner July 23, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants