Skip to content

[SVLS-7168] Create GCP PubSub Push Subscriptions Plugin#6260

Merged
BridgeAR merged 1 commit intomasterfrom
nina.rei/SVLS-7168/gcp-push-pubsub-plugin
Dec 22, 2025
Merged

[SVLS-7168] Create GCP PubSub Push Subscriptions Plugin#6260
BridgeAR merged 1 commit intomasterfrom
nina.rei/SVLS-7168/gcp-push-pubsub-plugin

Conversation

@nina9753
Copy link
Copy Markdown
Contributor

@nina9753 nina9753 commented Aug 11, 2025

What does this PR do?

This PR adds comprehensive support for Google Cloud Pub/Sub push subscriptions, enabling distributed tracing for messages delivered via HTTP webhooks. Unlike pull subscriptions, where the application pulls for messages using the SDK, push subscriptions have GCP Pub/Sub POST messages directly to an HTTP endpoint.

New Plugin: pubsub-push-subscription.js

  • Creates pubsub.delivery spans for incoming push subscription HTTP requests
  • Intercepts HTTP requests with GCP-specific headers:
  • Extracts trace context from message attributes (injected by producer)
  • Parses message metadata (subscription name, topic, publish time)
  • Finishes span when HTTP response completes

Modified: packages/datadog-instrumentations/src/http.js

  • So the push subscription plugin must subscribe to apm:http:server:request:start before the HTTP server plugin
    • Detect Pub/Sub push requests early
    • Create pubsub.delivery span as active parent
    • Ensure web framework spans (Express, Fastify, etc.) become children of the delivery span

Next PR in the batch is #6782

Motivation

An inferred span for the push subscription HTTP POST request to the Cloud Run service from a pub/sub topic
Example full Push Distributed Trace of a cloud run service triggering another service using a push subscription

Plugin Checklist

Additional Notes

Critical for Distributed Tracing: When creating or updating a GCP Pub/Sub push subscription, you must include the --push-no-wrapper-write-metadata flag to enable trace context propagation. By default, GCP Pub/Sub wraps push messages in a JSON envelope and does not include message attributes as HTTP headers. We do not currently read the req.body for pubsub distributed tracing

Additional information can be found in this doc

image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 11, 2025

Overall package size

Self size: 4.39 MB
Deduped: 5.21 MB
No deduping: 5.21 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.0 | 68.46 kB | 797.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 57.07965% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.49%. Comparing base (4b40f00) to head (89ad695).
⚠️ Report is 42 commits behind head on master.

Files with missing lines Patch % Lines
...oogle-cloud-pubsub/src/pubsub-push-subscription.js 7.40% 75 Missing ⚠️
...datadog-plugin-google-cloud-pubsub/src/producer.js 56.86% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6260      +/-   ##
==========================================
- Coverage   84.77%   84.49%   -0.29%     
==========================================
  Files         522      523       +1     
  Lines       22233    22445     +212     
==========================================
+ Hits        18849    18964     +115     
- Misses       3384     3481      +97     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nina9753 nina9753 marked this pull request as draft August 11, 2025 17:43
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Aug 11, 2025

Benchmarks

Benchmark execution time: 2025-12-20 19:33:31

Comparing candidate commit 89ad695 in PR branch nina.rei/SVLS-7168/gcp-push-pubsub-plugin with baseline commit 4b40f00 in branch master.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 288 metrics, 30 unstable metrics.

scenario:plugin-http-server-querystring-obfuscation-22

  • 🟥 execution_time [+34.626ms; +38.625ms] or [+5.265%; +5.873%]

scenario:plugin-http-server-querystring-obfuscation-24

  • 🟥 execution_time [+32.084ms; +35.046ms] or [+5.387%; +5.884%]

Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

This is quite a big PR, if you like, we could set up a sync call to go through the changes to review the PR :)

Comment thread packages/datadog-instrumentations/src/body-parser.js Outdated
@nina9753 nina9753 marked this pull request as draft August 27, 2025 17:56
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Sep 10, 2025

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

🧪 1 Test failed

OpenFeature "before all" hook for "should not crash build after installing with yarn" from OpenFeature (Datadog) (Fix with Cursor)
Command failed: yarn
error https://registry.yarnpkg.com/@datadog/pprof/-/pprof-5.13.1.tgz: Request failed "500 Internal Server Error"
error Error: ENOENT: no such file or directory, open '/home/runner/.cache/yarn/v6/npm-@datadog-pprof-5.13.1-51c540d75cf4471806db65d0686cbe0a96125ce2-integrity/node_modules/@datadog/pprof/.yarn-metadata.json'

Error: Command failed: yarn
error https://registry.yarnpkg.com/@datadog/pprof/-/pprof-5.13.1.tgz: Request failed "500 Internal Server Error"
error Error: ENOENT: no such file or directory, open '/home/runner/.cache/yarn/v6/npm-@datadog-pprof-5.13.1-51c540d75cf4471806db65d0686cbe0a96125ce2-integrity/node_modules/@datadog/pprof/.yarn-metadata.json'

    at genericNodeError (node:internal/errors:985:15)
    at wrappedFn (node:internal/errors:539:14)
...

ℹ️ Info

❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 89ad695 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch from 1d06808 to df5b0e9 Compare October 29, 2025 15:02
Comment thread packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js Outdated
Comment thread packages/datadog-instrumentations/src/shared-channels.js Outdated
@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch 2 times, most recently from b596491 to 5a13644 Compare November 4, 2025 21:22
@nina9753 nina9753 marked this pull request as ready for review November 4, 2025 21:43
@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@DataDog DataDog deleted a comment from chatgpt-codex-connector Bot Nov 4, 2025
@nina9753
Copy link
Copy Markdown
Contributor Author

nina9753 commented Nov 4, 2025

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/datadog-instrumentations/src/google-cloud-pubsub.js Outdated
Comment thread packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js Outdated
@nina9753 nina9753 requested a review from BridgeAR November 17, 2025 15:13
@nina9753
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js Outdated
Comment thread packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js Outdated
Comment thread packages/datadog-instrumentations/src/google-cloud-pubsub.js Outdated
@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch from 6b7abdb to d237c98 Compare November 17, 2025 21:10
@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch 3 times, most recently from a15deff to 89ae84f Compare December 20, 2025 19:04
@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch from 426a3af to 4efa08d Compare December 20, 2025 19:11
@nina9753 nina9753 requested review from a team as code owners December 20, 2025 19:11
@nina9753 nina9753 force-pushed the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch from 4efa08d to 89ad695 Compare December 20, 2025 19:23
@nina9753 nina9753 requested a review from BridgeAR December 22, 2025 12:26
@BridgeAR BridgeAR merged commit 39facdd into master Dec 22, 2025
848 of 849 checks passed
@BridgeAR BridgeAR deleted the nina.rei/SVLS-7168/gcp-push-pubsub-plugin branch December 22, 2025 12:29
dd-octo-sts Bot pushed a commit that referenced this pull request Jan 12, 2026
* Add plugin for GCP PubSub Push Subscriptions
* feat: add producer-side batch message handling with span linking
* feat: add span linking from delivery span to pubsub.request
* feat: add span linking and batch metadata to pull-based consumer

- Collect span links from messages 2-N (first becomes parent)
- Extract parent context from first message trace context
- Create pubsub.request span with span links metadata
- Inject batch metadata into all messages (_dd.pubsub_request.*, _dd.batch.*)
- Add 128-bit trace ID support (_dd.p.tid)
- Add operation tag for batched vs single requests
- HTTP plugin now checks if a delivery span is active in storage
- If found, uses delivery span as parent for http.request
- Ensures proper span hierarchy for push subscriptions
- Extract pubsub.request span ID from message attributes
- Add span link correlation tags
- Calculate delivery duration from publish start time
- Add batch size and index tags for batched messages
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jan 12, 2026
nina9753 added a commit that referenced this pull request Jan 15, 2026
* Add plugin for GCP PubSub Push Subscriptions
* feat: add producer-side batch message handling with span linking
* feat: add span linking from delivery span to pubsub.request
* feat: add span linking and batch metadata to pull-based consumer

- Collect span links from messages 2-N (first becomes parent)
- Extract parent context from first message trace context
- Create pubsub.request span with span links metadata
- Inject batch metadata into all messages (_dd.pubsub_request.*, _dd.batch.*)
- Add 128-bit trace ID support (_dd.p.tid)
- Add operation tag for batched vs single requests
- HTTP plugin now checks if a delivery span is active in storage
- If found, uses delivery span as parent for http.request
- Ensures proper span hierarchy for push subscriptions
- Extract pubsub.request span ID from message attributes
- Add span link correlation tags
- Calculate delivery duration from publish start time
- Add batch size and index tags for batched messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants