Skip to content

MongoDB traces - update semantic conventions to v1.39.0#4791

Merged
Kielek merged 70 commits intoopen-telemetry:mainfrom
aviralgarg05:fix/mongodb-semconv-1.39.0
Feb 16, 2026
Merged

MongoDB traces - update semantic conventions to v1.39.0#4791
Kielek merged 70 commits intoopen-telemetry:mainfrom
aviralgarg05:fix/mongodb-semconv-1.39.0

Conversation

@aviralgarg05
Copy link
Copy Markdown
Contributor

MongoDB - update semantic convention to v1.39.0 (#4786)

Why

OpenTelemetry Semantic Conventions have standardized database attribute names to ensure consistency across different language implementations. Specifically, the attribute db.system has been transitioned to db.system.name in the stable semantic conventions (finalized in v1.30.0 and kept in v1.39.0). This PR aligns the .NET AutoInstrumentation with these standards.

What

  • Code Change: Updated DbSystem constant from "db.system" to "db.system.name" in src/OpenTelemetry.AutoInstrumentation/Instrumentations/DatabaseAttributes.cs.
  • Test Alignment: Updated test/IntegrationTests/MongoDBTests.cs to expect the new db.system.name attribute in emitted spans.
  • Changelog: Added an entry to CHANGELOG.md under the "Unreleased" section.

Tests

  • Static Analysis: Verified that MongoDBInstrumentation.cs uses the DatabaseAttributes.Keys.DbSystem constant, ensuring the change propagates automatically.
  • Mock Collector Verification: Updated the integration test assertions to validate that the spans now correctly contain db.system.name.
  • Global Search: Performed a codebase-wide grep to ensure no other hardcoded strings of "db.system" were missed in the src or test directories.

Checklist

  • CHANGELOG.md is updated.
  • New features are covered by tests.

@aviralgarg05 aviralgarg05 requested a review from a team as a code owner January 19, 2026 14:04
Comment thread CHANGELOG.md Outdated
@ysolomchenko
Copy link
Copy Markdown
Contributor

ActivitySource should also provide link to the schema
example PR how to do it: open-telemetry/opentelemetry-dotnet-contrib#3680

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

ActivitySource should also provide link to the schema example PR how to do it: open-telemetry/opentelemetry-dotnet-contrib#3680

Resolved and implemented!

Copy link
Copy Markdown
Contributor

@ysolomchenko ysolomchenko left a comment

Choose a reason for hiding this comment

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

The following attributes should be set at span creation time rather than during execution.
https://github.com/open-telemetry/semantic-conventions/blob/v1.39.0/docs/db/mongodb.md?plain=1#L69

Comment thread src/OpenTelemetry.AutoInstrumentation/Instrumentations/DatabaseAttributes.cs Outdated
@Kielek Kielek changed the title fix(mongodb): update semantic conventions to v1.39.0 MongoDB traces - update semantic conventions to v1.39.0 Jan 22, 2026
Comment thread src/OpenTelemetry.AutoInstrumentation/Instrumentations/DatabaseAttributes.cs Outdated
lmolkova added a commit to open-telemetry/semantic-conventions that referenced this pull request Jan 23, 2026
These attributes are not present on the formal span definition and having then in the examples is misleading - e.g. open-telemetry/opentelemetry-dotnet-instrumentation#4791 (comment)
Copy link
Copy Markdown
Member

@Kielek Kielek left a comment

Choose a reason for hiding this comment

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

You have some issues with the tests.
What is more, I think it would be great to adjust expectations to cover new attributes.

@lachmatt
Copy link
Copy Markdown
Contributor

SIG: @aviralgarg05 can you check the CI failures?

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

SIG: @aviralgarg05 can you check the CI failures?

Yes I will fix them

@Kielek Kielek requested a review from ysolomchenko January 29, 2026 10:55
Comment thread CHANGELOG.md Outdated
Copy link
Copy Markdown
Member

@Kielek Kielek left a comment

Choose a reason for hiding this comment

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

@aviralgarg05 thank you for the PR, I have pushed some direct feedback on your branch. I hope you are fine with these changes.

There is couple leftovers to be handled.

@Kielek Kielek requested a review from lmolkova January 30, 2026 09:22
Comment thread test/IntegrationTests/MongoDBTests.cs
@aviralgarg05
Copy link
Copy Markdown
Contributor Author

I have fixed and resolved the comments.

Comment thread .github/instructions/codacy.instructions.md Outdated
@ysolomchenko
Copy link
Copy Markdown
Contributor

I have fixed and resolved the comments.

It would be good to add tests for the error trace as well, since we have new logic here.
(You should update the test application for this)

@aviralgarg05
Copy link
Copy Markdown
Contributor Author

aviralgarg05 commented Feb 2, 2026

Added tests for MongoDB error traces:

  • New test: SubmitsTracesWithErrorDetails validates error handling
  • Test app updated with --trigger-error flag
  • ValidateErrorSpan checks error.type, exception events, and error status
  • RunWithError triggers MongoCommandException for testing

Comment thread test/IntegrationTests/MongoDBTests.cs Outdated
@ysolomchenko
Copy link
Copy Markdown
Contributor

@aviralgarg05 can you check why the tests are failing and fix them?

Updates db.system to db.system.name in accordance with OpenTelemetry Semantic Conventions v1.39.0 (open-telemetry#4786).
@ysolomchenko
Copy link
Copy Markdown
Contributor

I have tried multiple times to fix this one failing test. If you could go through it pls @ysolomchenko

This is not related to your changes. It’s just a flaky test that fails sometimes.

Comment thread test/IntegrationTests/NoCodeTests.cs
- Remove unrelated NoCodeTests.cs

- Remove QueryWireProtocol instrumentation

- Use DuckTyping for MongoCommandException.Code
QueryWireProtocol is valid for MongoDB versions earlier than 3.5
@ysolomchenko
Copy link
Copy Markdown
Contributor

ysolomchenko commented Feb 4, 2026

@aviralgarg05 I don’t have privileges to add direct commits, so I created them on my branch. Could you add them to this PR? It should fix the CI issues.
ysolomchenko@8cfe399
ysolomchenko@1ead8bf
ysolomchenko@7db5ccc
ysolomchenko@02263ad

Comment thread CHANGELOG.md Outdated
Comment thread test/IntegrationTests/MongoDBTests.cs Outdated
Status codes are integers, not strings. Updated the test validation
to check IntValue > 0 instead of checking StringValue.
Copy link
Copy Markdown
Contributor

@ysolomchenko ysolomchenko left a comment

Choose a reason for hiding this comment

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

LGTM

@Kielek Kielek enabled auto-merge (squash) February 16, 2026 09:52
@Kielek Kielek merged commit 39e1008 into open-telemetry:main Feb 16, 2026
51 of 52 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.

7 participants