Fix Mongo stable DB span names#18987
Merged
Merged
Conversation
d836ada to
536afa5
Compare
Contributor
There was a problem hiding this comment.
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#getDbCollectionNameand remove the bespokeMongoAttributesExtractor. - 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(). |
67c0797 to
d307ac2
Compare
d307ac2 to
2094916
Compare
laurit
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates Mongo instrumentation to use the shared DB client attributes and span naming paths for stable database semantic conventions, while keeping legacy
db.mongodb.collectionemission 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.