feat(gcp): Add span streaming support to GCP Cloud Functions integration#6440
feat(gcp): Add span streaming support to GCP Cloud Functions integration#6440ericapisani wants to merge 1 commit into
Conversation
Migrate GCP integration to support spans-first tracing via the span streaming API. The integration now supports both: - Span streaming (new trace lifecycle) - Traditional transaction-based approach (fallback) Add request attributes to spans including headers, HTTP method, and query string. Include cloud provider context and segment source in span metadata. Add comprehensive tests for span streaming functionality including error handling, trace context propagation, and PII filtering for query strings. Depends on getsentry/sentry-conventions#403 being merged first. Fixes PY-2324 Fixes #6022
Codecov Results 📊✅ 446 passed | Total: 446 | Pass Rate: 100% | Execution Time: 1m 9s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14925 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 34.86% 34.84% -0.02%
==========================================
Files 190 190 —
Lines 22890 22906 +16
Branches 7834 7842 +8
==========================================
+ Hits 7981 7981 —
- Misses 14909 14925 +16
- Partials 829 829 —Generated by Codecov Action |
| if should_send_default_pii() and hasattr(gcp_event, "query_string"): | ||
| additional_attributes["url.query"] = gcp_event.query_string.decode( | ||
| "utf-8" | ||
| ) |
There was a problem hiding this comment.
Unhandled UnicodeDecodeError in query_string.decode() crashes GCP function invocations
If gcp_event.query_string contains non-UTF-8 bytes (e.g. ?q=foo%80bar), the .decode("utf-8") call raises an unhandled UnicodeDecodeError that propagates outside the try/except block and the capture_internal_exceptions context, causing the entire GCP function invocation to fail due to Sentry instrumentation. Use decode("utf-8", errors="replace") to be safe.
Evidence
- Lines 103–106 are outside the
with capture_internal_exceptions():block (which ends aftertimeout_thread.start()) and outside thetry/except Exceptionblock that starts only insidewith span_ctx:. - A
UnicodeDecodeErrorthrown here escapes thewith sentry_sdk.isolation_scope()context manager entirely and propagates back to the GCP framework. - The existing event processor at line 223–224 does the same decode, but it runs inside a registered event processor callback which Sentry wraps with
capture_internal_exceptionsinternally. - The new span-streaming code path at lines 103–106 has no such protection, making it a new failure mode introduced by this diff.
Suggested fix: Use errors='replace' to avoid crashing on malformed query strings.
| if should_send_default_pii() and hasattr(gcp_event, "query_string"): | |
| additional_attributes["url.query"] = gcp_event.query_string.decode( | |
| "utf-8" | |
| ) | |
| additional_attributes["url.query"] = gcp_event.query_string.decode( | |
| "utf-8", errors="replace" | |
| ) |
Identified by Warden find-bugs · 6FG-4J5
Migrate GCP integration to support spans-first tracing via the span streaming API.
The integration now supports both:
Add request attributes to spans including headers, HTTP method, and query string.
Include cloud provider context and segment source in span metadata.
Add comprehensive tests for span streaming functionality including error handling,
trace context propagation, and PII filtering for query strings.
Fixes PY-2324 and #6022