feat(pymongo): Add span streaming support#6253
Conversation
Add span streaming support to the PyMongo integration, mirroring the pattern used in the asyncpg integration. When trace_lifecycle=stream is enabled, spans are emitted using the new StreamedSpan API with OTel-style attributes. The legacy code path is preserved for non-streaming clients. Fixes PY-2349 Fixes #6047
|
bugbot run |
|
@sentry review |
Codecov Results 📊✅ 146 passed | Total: 146 | Pass Rate: 100% | Execution Time: 22.27s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 6.67%. Project has 14358 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 34.96% 34.94% -0.02%
==========================================
Files 190 190 —
Lines 22052 22069 +17
Branches 7408 7420 +12
==========================================
+ Hits 7709 7711 +2
- Misses 14343 14358 +15
- Partials 807 807 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b8ddc07. Configure here.
|
|
||
| data: "Dict[str, Any]" = {"operation_ids": {}} | ||
| data["operation_ids"]["operation"] = event.operation_id | ||
| data["operation_ids"]["request"] = event.request_id |
There was a problem hiding this comment.
These are also kept for legacy reasons, are being removed for streamed spans.
sentrivana
left a comment
There was a problem hiding this comment.
Looking good, but we're using some deprecated attributes here, I've highlighted the ones I noticed but please have another look at the rest we're setting on the span first path as well 🙏🏻 Approving to not block.
| if type(span) is StreamedSpan: | ||
| span.status = SpanStatus.OK |
There was a problem hiding this comment.
OK is the default value for StreamedSpans, so technically we don't need to set it here
| if db_name is not None: | ||
| data[SPANDATA.DB_NAME] = db_name |
There was a problem hiding this comment.
IIRC this is deprecated and superseded by SPANDATA.DB_NAMESPACE, so we should use that in span first
| "db.name": event.database_name, | ||
| SPANDATA.DB_SYSTEM: "mongodb", | ||
| SPANDATA.DB_DRIVER_NAME: "pymongo", | ||
| SPANDATA.DB_OPERATION: event.command_name, |
There was a problem hiding this comment.
| SPANDATA.DB_OPERATION: event.command_name, | |
| SPANDATA.DB_OPERATION_NAME: event.command_name, |
https://getsentry.github.io/sentry-conventions/attributes/db/#db-operation
| if has_span_streaming_enabled(client.options): | ||
| span_first_data = { | ||
| "db.name": event.database_name, | ||
| SPANDATA.DB_SYSTEM: "mongodb", |
There was a problem hiding this comment.
| SPANDATA.DB_SYSTEM: "mongodb", | |
| SPANDATA.DB_SYSTEM_NAME: "mongodb", |

Add span streaming support to the PyMongo integration. The legacy code path is preserved unchanged for non-streaming clients.
Fixes PY-2349
Fixes #6047