Conversation
HazAT
approved these changes
Nov 21, 2025
Member
HazAT
left a comment
There was a problem hiding this comment.
Makes sense, I wonder tho why this/what changed compared to before
Member
|
Shouldn’t this be be resolved upstream in Sentry? |
Member
Author
You're totally right. I'll see why this is actually needed. |
This was referenced Nov 26, 2025
JPeer264
added a commit
to getsentry/sentry-javascript
that referenced
this pull request
Dec 2, 2025
(closes #18360) ## Problem In getsentry/sentry-mcp#652 we had to manually wait for the flush to ensure that async operations completed before the response was sent. This was caused by the MCP server streaming data after the actual request has been finished. When using the Cloudflare SDK with MCP servers (or other streaming APIs), spans created during the streaming phase were not being flushed properly because the `flush()` method would complete before these async spans finished. ## Solution During the request, when a span is created for the streaming call, we now register listeners on the CloudflareClient for `spanStart` and `spanEnd` events. The client tracks all pending spans and waits for them to complete before flushing. Specifically: - Added `_pendingSpans` Set to track active span IDs - Created a promise-based mechanism (`_spanCompletionPromise`) to wait for all spans to complete - Modified the `flush()` method to wait for pending spans before calling `super.flush()` - Added a timeout (default 5 seconds) to prevent indefinite waiting ## Test Added a comprehensive E2E test application (`cloudflare-mcp`) that: - Sets up a Cloudflare Worker with an MCP server - Registers a tool that creates spans during execution - Verifies that both the HTTP request span and the MCP tool call span are properly sent to Sentry - Validates span relationships (parent/child) and trace IDs The test confirms that spans are now flushed correctly without manual intervention.
dcramer
pushed a commit
that referenced
this pull request
Dec 2, 2025
In #652 we had to manually add the flush, which should actually be done by the Cloudflare SDK. This has now landed in `10.28.0` (via [this PR](getsentry/sentry-javascript#18334)) and no manual flushing has to be done anymore. Just to be sure sure I verified on top if everything has been sent locally. This is a trace from my local deployment: https://sentry-sdks.sentry.io/explore/traces/trace/434f1b1e8655444c875bce5c66645376/?fov=0%2C291&node=span-84a7a24ae593ee49&project=4510380305022976&source=traces&statsPeriod=15m&targetId=a505468e10176600×tamp=1764689933 I recommend to review this PR [without whitespaces enabled](https://github.com/getsentry/sentry-mcp/pull/663/files?w=1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Events which hold attributes such as
organization.slugormcp.*were not flushed correctly.sentry-mcp/packages/mcp-core/src/server.ts
Lines 281 to 286 in ce3ec0f
With this it will re-add these missing events, as it will wait with
waitUntilthat these events are flushed within the tool call.Example of a tool call event