Skip to content

Fix Mongo stable DB span names#18987

Merged
trask merged 6 commits into
open-telemetry:mainfrom
trask:mongo-stable-span-name-pr18982
Jun 15, 2026
Merged

Fix Mongo stable DB span names#18987
trask merged 6 commits into
open-telemetry:mainfrom
trask:mongo-stable-span-name-pr18982

Conversation

@trask

@trask trask commented Jun 14, 2026

Copy link
Copy Markdown
Member

Updates Mongo instrumentation to use the shared DB client attributes and span naming paths for stable database semantic conventions, while keeping legacy db.mongodb.collection emission in a Mongo-specific extractor. This preserves old Mongo span names and old semconv compatibility without adding a Mongo-specific collection hook to the shared DB extractor.

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

This PR updates MongoDB instrumentation to generate stable DB span names via the shared DB client span name extractor, while preserving legacy Mongo span naming and legacy collection attributes during the semconv migration. It builds on #18989 by moving Mongo collection extraction into the shared DbClientAttributesGetter path and wiring old collection attribute emission through the shared DB attributes extractor builder.

Changes:

  • Delegate Mongo stable span naming to DbClientSpanNameExtractor, while keeping legacy span-name behavior when stable semconv is disabled.
  • Move Mongo collection-name extraction into MongoDbAttributesGetter#getDbCollectionName and remove the bespoke MongoAttributesExtractor.
  • Extend DB client semconv utilities to support an optional “old semconv collection” attribute and to prefer collection name over namespace for stable span names.

Reviewed changes

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

Show a summary per file
File Description
instrumentation/mongo/mongo-common/testing/src/main/java/io/opentelemetry/instrumentation/mongo/testing/AbstractMongoClientTest.java Updates Mongo test expectations for stable semconv span names to omit db namespace when collection is available.
instrumentation/mongo/mongo-3.1/library/src/test/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoSpanNameExtractorTest.java Updates test setup for the simplified MongoSpanNameExtractor constructor.
instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoSpanNameExtractor.java Delegates stable span naming to DbClientSpanNameExtractor and uses shared collection getter for legacy names.
instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoInstrumenterFactory.java Switches to configured DbClientAttributesExtractor (including old collection attribute emission) and removes Mongo-specific attributes extractor wiring.
instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoDbAttributesGetter.java Adds getDbCollectionName implementation (command-aware collection extraction) for shared DB client semconv support.
instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoAttributesExtractor.java Removes Mongo-specific attributes extractor in favor of shared DB client attribute extraction.
instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractorTest.java Updates/extends tests for stable vs old semconv operation sourcing and collection-vs-namespace preference.
instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java Adds coverage for configurable old-semconv collection attribute emission and new stable collection attribute extraction.
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesGetter.java Documents and enforces that SQL instrumentations shouldn’t override operation/collection getters (computed by extractor).
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java Uses getDbCollectionName() as the primary stable target and aligns old semconv naming to use getDbOperation().
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java Introduces getDbOperation() (deprecated) and getDbCollectionName() to support old semconv migration and stable collection naming.
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorBuilder.java Adds deprecated configuration for emitting an old-semconv collection attribute key.
instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java Emits stable db.collection.name, supports optional old-semconv collection attribute emission, and switches old db.operation to getDbOperation().

@trask trask force-pushed the mongo-stable-span-name-pr18982 branch 3 times, most recently from 67c0797 to d307ac2 Compare June 15, 2026 04:10
@trask trask force-pushed the mongo-stable-span-name-pr18982 branch from d307ac2 to 2094916 Compare June 15, 2026 14:54

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 9 out of 9 changed files in this pull request and generated no new comments.

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 6 out of 6 changed files in this pull request and generated no new comments.

@trask trask marked this pull request as ready for review June 15, 2026 17:10
@trask trask requested a review from a team as a code owner June 15, 2026 17:10
@trask trask enabled auto-merge (squash) June 15, 2026 18:35
@trask trask merged commit 4593933 into open-telemetry:main Jun 15, 2026
95 checks passed
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.

3 participants