feat(pymongo): introduce db.operation, refactor db.statement, refactor span name
#3606
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.
Description
This change updates the opentelemetry-instrumentation-pymongo to better align with OpenTelemetry semantic conventions and the behavior of other language instrumentations (e.g. NodeJS, Ruby, etc.).
see https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts
The key changes are:
db.operationattribute is now used to record the MongoDB command name (e.g.find,insert).db.statementattribute is no longer populated by default. It is only recorded if thecapture_statement = Trueoption is passed to the instrumentor.{db_name}.{command}to{db_name}.{collection}.{command}when a collection is present.Invalid type in attribute sequence when using sessionsThis provides more consistent and conventional telemetry data for MongoDB operations.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
The existing unit tests in instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py have been updated to reflect these changes.
Specifically, the tests now verify:
db.operationis correctly set with the command name.db.statementis not present on the span by default.capture_statement = Trueis enabled,db.statementis correctly populated with the full command statement.All tests were run and passed using the project's tox configuration:
tox -e test-pymongoDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.