Conversation
8b5305f to
71c8901
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Reauthentication can reuse an ended command span and stale traceparent, while some bulk metadata and authentication tests are incomplete.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds W3C trace-context propagation from PyMongo command spans to MongoDB server spans via OP_MSG telemetry sections.
Changes:
- Adds Payload Type 3 encoding across Python and C paths.
- Pre-creates command spans and handles encoding failures.
- Adds wire-format and server-span integration tests.
File summaries
| File | Description |
|---|---|
pymongo/_otel.py |
Builds traceparents and telemetry sections. |
pymongo/_telemetry.py |
Supports pre-created command spans. |
pymongo/message.py |
Encodes telemetry sections and reserves batch space. |
pymongo/_cmessagemodule.c |
Adds C encoder support. |
pymongo/asynchronous/command_runner.py |
Creates spans before command encoding. |
pymongo/synchronous/command_runner.py |
Synchronous generated counterpart. |
pymongo/asynchronous/cursor_base.py |
Propagates traceparents for cursor commands. |
pymongo/synchronous/cursor_base.py |
Synchronous generated counterpart. |
pymongo/asynchronous/bulk.py |
Propagates traceparents for collection bulk writes. |
pymongo/synchronous/bulk.py |
Synchronous generated counterpart. |
pymongo/asynchronous/client_bulk.py |
Propagates traceparents for client bulk writes. |
pymongo/synchronous/client_bulk.py |
Synchronous generated counterpart. |
test/test_message.py |
Tests telemetry wire encoding and size reservation. |
test/asynchronous/test_otel.py |
Adds async tracing and server-span tests. |
test/test_otel.py |
Synchronous generated tracing tests. |
Review details
Suppressed comments (1)
pymongo/asynchronous/bulk.py:377
- The pre-created span captured
cmdbefore batch splitting, so it never sees the selected operation documents thatwrite_commandadds afterward. This regressesdb.query.textfor acknowledged collection bulk writes; refresh it fromto_sendbefore handing the span to the command runner.
msg = cast(bytes, msg)
- Files reviewed: 15/15 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8af1edf to
b6f0072
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Trace flags need validation to prevent malformed wire context, and the asynchronous polling tests perform blocking operations.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 2
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The retry prose test must skip environments that do not support the failCommand failpoint.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 1
- Review effort level: Balanced
Omit the telemetry section when span trace flags exceed one byte, because ":02x" only pads to a minimum width and would push the traceparent past 55 characters. Make the server-span prose helpers async: offload trace-directory reads with run_in_executor and await asyncio.sleep between polls. The sync mirror keeps the blocking forms.
Prose test 6 configures a failpoint but only checked the server version, so it failed on servers without test commands. Guard it with require_failCommand_fail_point, matching the other failpoint tests.
243b7b4 to
046cb84
Compare
The spec renumbered the server trace-context prose tests to 7/8/9 after inserting the error.type tests as 5/6. Rename the methods to match.
The spec numbers the two error.type prose tests 5 and 6, ahead of the server trace-context tests. Rename the methods to match.
There was a problem hiding this comment.
🟢 Approval recommended
The implementation satisfies the propagation requirements with broad coverage; identified test-name mismatches are non-blocking.
Review details
Suppressed comments (2)
test/asynchronous/test_otel.py:1258
- The method name labels this as prose test 8, while the docstring and specification define the retry-attempt case as prose test 6. Align the name so
-k prose_6selects the expected coverage.
async def test_prose_8_one_server_span_per_retry_attempt(self):
test/asynchronous/test_otel.py:1306
- This is prose test 7 according to the docstring and specification, not prose test 9. The mismatched name makes the auth/monitoring exclusion test difficult to select by its documented number.
async def test_prose_9_no_trace_context_for_auth_monitoring(self):
- Files reviewed: 16/16 changed files
- Comments generated: 1
- Review effort level: Balanced
| await asyncio.sleep(0.5) | ||
|
|
||
| @async_client_context.require_version_min(9, 0) | ||
| async def test_prose_7_server_spans_join_driver_trace(self): |
There was a problem hiding this comment.
This will need to be adjusted after #3000 is merged
PYTHON-5855
Sixth in the OpenTelemetry stack, on top of #3000. Base is
PYTHON-5947-otel-5-error-type.PYTHON-5947-otel-1-operationsPYTHON-5947-otel-2-transactionsPYTHON-5947-otel-3-unifiedPYTHON-5947-otel-4-getmorePYTHON-5947-otel-5-error-typeerror.typecommand span attributePYTHON-5855-traceparentImplements DRIVERS-3454 (mongodb/specifications#1966). The driver attaches the command span's W3C traceparent to each command as an
OP_MSGPayload Type 3 telemetry section, so server spans join the driver's trace as children of the exact command or retry attempt that produced them.Changes in this PR
{"otel": {"traceparent": "<55-char value>"}}to every Python and C encode path.maxWireVersionis at least 29, and the command span yields a valid traceparent.maxMessageSizeBytes.Test Plan
test/test_message.py::TestTelemetrySectionassert the type-3 section is last and well-formed on the C and pure-Python encoders, that it is absent without a traceparent, and that batch splitting reserves its size.test/test_message.pyplus the otel suites (test_otel.py,test_otel_getmore.py,test_otel_transactions.py,test_open_telemetry_unified.py, async and sync): 267 passed, 37 skipped against a MongoDB 9.1 standalone started with the OpenTelemetry file exporter (OTEL=1).OTEL_TRACE_DIRand assert the parent linkage to the driver command spans. They skip whenOTEL_TRACE_DIRis unset.ruffandjust typingare clean.Checklist
Checklist for Author
Checklist for Reviewer