feat(sanic): Support span streaming#6319
Conversation
Codecov Results 📊✅ 282 passed | Total: 282 | Pass Rate: 100% | Execution Time: 40.11s All tests are passing successfully. ❌ Patch coverage is 9.52%. Project has 15310 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
d266281 to
950a311
Compare
ca346f8 to
d10461b
Compare
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 d10461b. Configure here.
d10461b to
9e8d40b
Compare
9e8d40b to
e9d3bf6
Compare
The `_unsampled_statuses` option is not respected for span streaming since we currently don't allow tail-based sampling in the new system.
e9d3bf6 to
0f32453
Compare
ericapisani
left a comment
There was a problem hiding this comment.
Some small things but otherwise LGTM. Approving so as not to block it from merging
| span.set_attribute(SPANDATA.HTTP_STATUS_CODE, response_status) | ||
| span.status = "error" if response_status >= 400 else "ok" | ||
|
|
||
| span._end() |
There was a problem hiding this comment.
We have a public end method that we can use here instead of the private _end (and the public method calls _end under the hood giving us the same outcome)
| if urlparts.query: | ||
| attributes[SPANDATA.HTTP_QUERY] = urlparts.query | ||
|
|
||
| attributes[SPANDATA.URL_FULL] = request.url |
There was a problem hiding this comment.
This appears to now be treated as PII, so would need to also be gated behind should_send_default_pii()
There was a problem hiding this comment.
I think the PII designation in conventions is enforced in Relay and not the SDK
| i.payload | ||
| for i in items | ||
| if i.type == "span" | ||
| and i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" |
There was a problem hiding this comment.
Because this is specifically looking for segments, this filter may be too broad since any child span originating from the integration would be returned. To be safe, it might be worth adding a check on the _is_segment property and confirming that it's True
| span.set_attribute(SPANDATA.HTTP_STATUS_CODE, response_status) | ||
| span.status = "error" if response_status >= 400 else "ok" | ||
|
|
||
| span._end() |
There was a problem hiding this comment.
| span._end() | |
| span.end() |
sentrivana
left a comment
There was a problem hiding this comment.
Looks good, couple small things _end -> end and TransactionSource -> SegmentSource
| with capture_internal_exceptions(): | ||
| scope = sentry_sdk.get_current_scope() | ||
| route_name = route.name.replace(request.app.name, "").strip(".") | ||
| scope.set_transaction_name(route_name, source=TransactionSource.COMPONENT) |
There was a problem hiding this comment.
There's a SegmentSource too for the streaming path. Would be good to use that if span streaming is enabled
| sanic_route = sanic_route[len(sanic_app_name) + 1 :] | ||
|
|
||
| scope.set_transaction_name( | ||
| sanic_route, source=TransactionSource.COMPONENT |
There was a problem hiding this comment.
Here too we should do SegmentSource if streaming
| ) | ||
| else: | ||
| scope.set_transaction_name( | ||
| rv[0].__name__, source=TransactionSource.COMPONENT |
| if i.type == "span" | ||
| and i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" |
There was a problem hiding this comment.
If you do capture_items("span"), there won't be anything but spans in the list, so no need to check explicitly
| if i.type == "span" | |
| and i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | |
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" |
| if i.type == "span" | ||
| and i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" |
There was a problem hiding this comment.
| if i.type == "span" | |
| and i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" | |
| if i.payload["attributes"].get("sentry.origin") == "auto.http.sanic" |

The
_unsampled_statusesoption is not respected for span streaming since we currently don't allow tail-based sampling in the new system.Issues