Skip to content

feat(gcp): Add span streaming support to GCP Cloud Functions integration#6440

Merged
ericapisani merged 4 commits into
masterfrom
py-2324-migrate-gcp
Jun 2, 2026
Merged

feat(gcp): Add span streaming support to GCP Cloud Functions integration#6440
ericapisani merged 4 commits into
masterfrom
py-2324-migrate-gcp

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented May 28, 2026

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.

Fixes PY-2324 and #6022

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
@ericapisani ericapisani requested a review from a team as a code owner May 28, 2026 19:25
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 28, 2026

PY-2324

@ericapisani ericapisani marked this pull request as draft May 28, 2026 19:26
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

Codecov Results 📊

88635 passed | ⏭️ 6007 skipped | Total: 94642 | Pass Rate: 93.65% | Execution Time: 294m 47s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +5
Passed Tests 📈 +5
Failed Tests
Skipped Tests

All tests are passing successfully.

❌ Patch coverage is 14.81%. Project has 2330 uncovered lines.
❌ Project coverage is 89.92%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/gcp.py 14.81% ⚠️ 23 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    89.96%    89.92%    -0.04%
==========================================
  Files          191       191         —
  Lines        23092     23109       +17
  Branches      7938      7948       +10
==========================================
+ Hits         20773     20779        +6
- Misses        2319      2330       +11
- Partials      1309      1307        -2

Generated by Codecov Action

Comment thread sentry_sdk/integrations/gcp.py
@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run
@sentry review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 38121a2. Configure here.

@ericapisani ericapisani marked this pull request as ready for review June 1, 2026 13:49
Comment thread sentry_sdk/integrations/gcp.py Outdated
Comment on lines 203 to 209
"function_name": environ.get("FUNCTION_NAME"),
"function_entry_point": environ.get("ENTRY_POINT"),
"function_identity": environ.get("FUNCTION_IDENTITY"),
"function_region": environ.get("FUNCTION_REGION"),
"function_project": environ.get("GCP_PROJECT"),
"execution_duration_in_millis": execution_duration_in_millis,
"configured_timeout_in_seconds": configured_timeout,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these (name, entry point, identity, region, project, maybe execution time?) look like they'd make sense as attributes in span first. Don't know if OTel/we already have conventions for them, but might be worth adding.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these don't have an OTEL equivalent but I've added a number of them to our conventions as part of getsentry/sentry-conventions#403

There's also some that I've dropped, which I've outlined in a thread here

The addition of the execution time will be an interesting one - I think we'd need to handle it similar to another integration that had some trickiness around the setting of a span's end timestamp after that span had been completed 🤔

I've held off on adding this value for now though because I'm not convinced it's worth adding at this time - there's nothing that I could find in hex that indicates that users are creating alerts, dashboards, etc. with this value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In full agreement re: execution time (not worth it right now) and the dropped attrs.

I was mostly curious about the ones you've added to the conventions -- why not set them on spans in this integration?

Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏🏻 🚀

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c3bbc45. Configure here.

attributes={
"sentry.op": OP.FUNCTION_GCP,
"sentry.origin": GcpIntegration.origin,
"sentry.span.source": SegmentSource.COMPONENT,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent enum value usage for span attribute

Low Severity

SegmentSource.COMPONENT is passed directly as an attribute value, while the equivalent code in the aiohttp integration uses SegmentSource.ROUTE.value to extract the plain string. While SegmentSource is a str enum so both work today, passing the enum member rather than .value is inconsistent with the established pattern and could behave unexpectedly if serialization logic changes.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c3bbc45. Configure here.

@ericapisani ericapisani merged commit c3aab39 into master Jun 2, 2026
144 checks passed
@ericapisani ericapisani deleted the py-2324-migrate-gcp branch June 2, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants