PYTHON-5947 Add OpenTelemetry operation spans - #2991
Open
blink1073 wants to merge 5 commits into
Open
Conversation
blink1073
force-pushed
the
PYTHON-5947-otel-1-operations
branch
3 times, most recently
from
August 17, 2026 23:09
4a8db0c to
ba21bb8
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
blink1073
force-pushed
the
PYTHON-5947-otel-1-operations
branch
11 times, most recently
from
August 18, 2026 12:02
c841c9f to
4e0c468
Compare
Give every public API call an operation span containing one command span per command sent to the server, per the OpenTelemetry driver specification. The span covers all retry attempts of one _retry_internal call, so retries appear as sibling command spans rather than being collapsed into one. killCursors and endSessions bypass the retry layer and start their spans at the call site instead, as does an unacknowledged client bulk write, which never reaches the command-span code that would fill in its namespace. Cursor-creating operations (find, aggregate, listCollections, listIndexes) are covered here, but only for the command that creates the cursor. Spans for caller-driven getMores come in a later change, as do transaction spans. _otel.py also takes over the specification's naming and attribute rules, so _telemetry.py deals only with span lifecycles and a specification change need not touch it. Namespace parsing moves to helpers_shared._split_namespace.
blink1073
force-pushed
the
PYTHON-5947-otel-1-operations
branch
from
August 18, 2026 12:55
4e0c468 to
6638ae1
Compare
Lead with the condition rather than the bare adjective.
The vendored unified spec fixtures it pointed at arrive in a later change, so the note described tests absent from this one.
…d test Evergreen only runs on PRs whose base is a configured branch, so the upper PRs in this stack get no Evergreen coverage, and the otel tests only run in Evergreen's otel variant. Add a temporary GitHub Actions job that runs them on every branch in the stack, against a replica set so the transaction span tests are included. Remove the job before merging. Also drop test_operation_name_normalizes_enum_operation. All 22 vendored fixtures assert db.operation.name with literal values, so the _Op formatting regression it guards fails them loudly, and adding a test here only to delete it once the fixtures land is churn.
|
Semgrep found 2 GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. 🛟 Help? Slack #semgrep-help or go/semgrep-help. Resolution Options:
|
…the end The mutable-action-tag scanners reported two findings in test_minimum, which this branch does not touch: inserting the otel job mid-file shifted those lines by 31 and the diff-based scan attributed them to this change. Appending the job instead leaves every pre-existing line where it was. Pin the job's own actions to commit hashes so the newly added lines do not trip the same rule. drivers-evergreen-tools has no pinned use elsewhere in this file, so v1.0.1 is spelled out; its commit is the same one master points at, so the topology input this job relies on is unchanged.
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.
PYTHON-5947
First of four PRs splitting #2964. Base is
otel; review in order.PYTHON-5947-otel-1-operationsPYTHON-5947-otel-2-transactionsPYTHON-5947-otel-3-unifiedPYTHON-5947-otel-4-getmoreChanges in this PR
Adds one span per public API call, containing one command span per command sent to the server, per the OpenTelemetry driver specification. Without it a retried operation's command spans share no parent, so a reader cannot tell which attempts belong to the same call.
killCursors,endSessions, and unacknowledged client bulk writes get operation spans too.find,aggregate,listCollections,listIndexes) are covered, but only for the command that creates the cursor. Caller-drivengetMores arrive in PR 4.0,False,""). This affected structured command logging as well as spans.Opt-in: no behavior change unless the
tracingclient option orOTEL_PYTHON_INSTRUMENTATION_MONGODB_ENABLEDis set. With tracing off there is no added allocation per command.Around 1,000 of the added lines are
just synchrooutput and another ~745 are tests.Test Plan
just lintclean.Checklist
Checklist for Author
Checklist for Reviewer