feat(chalice): Add span streaming support to Chalice integration#6503
2 issues
find-bugs: Found 2 issues (1 medium, 1 low)
Medium
Missing `continue_trace` call before `start_span` breaks distributed tracing in streaming path - `sentry_sdk/integrations/chalice.py:122-135`
In the streaming path, sentry_sdk.traces.continue_trace(headers) is never called before start_span, so incoming sentry-trace/traceparent/baggage headers from HTTP requests are never propagated — every Chalice invocation starts a fresh, unconnected trace instead of joining the upstream trace. Add sentry_sdk.traces.continue_trace(headers) before the start_span call (mirroring the GCP integration at gcp.py:133).
Low
_get_lambda_span_attributes crashes when invoked_function_arn is None (chalice local) - `tests/integrations/chalice/test_chalice.py:104-106`
In sentry_sdk/integrations/chalice.py, _get_lambda_span_attributes calls invoked_arn.split(':') without a null guard. In real AWS Lambda the runtime always populates invoked_function_arn, but chalice.app.LambdaContext (used by chalice local) leaves it as None by default. When span streaming is enabled (trace_lifecycle=stream) and running under chalice local, both streaming paths (EventSourceHandler.__call__ and _get_view_function_response.wrapped_view_function) call _get_lambda_span_attributes outside capture_internal_exceptions, so the resulting AttributeError: 'NoneType' object has no attribute 'split' propagates and crashes the handler. Production AWS Lambda is unaffected. Fix by defaulting to an empty string: invoked_arn = aws_context.invoked_function_arn or ''.
⏱ 10m 37s · 1.0M in / 51.1k out · $1.73
Annotations
Check warning on line 135 in sentry_sdk/integrations/chalice.py
sentry-warden / warden: find-bugs
Missing `continue_trace` call before `start_span` breaks distributed tracing in streaming path
In the streaming path, `sentry_sdk.traces.continue_trace(headers)` is never called before `start_span`, so incoming `sentry-trace`/`traceparent`/`baggage` headers from HTTP requests are never propagated — every Chalice invocation starts a fresh, unconnected trace instead of joining the upstream trace. Add `sentry_sdk.traces.continue_trace(headers)` before the `start_span` call (mirroring the GCP integration at `gcp.py:133`).