Repository navigation
Conversation
af27973 to
a2af1e1
Compare
c544ac0 to
89a5b2c
Compare
size-limit report 📦Compared: e7eedd7 (PR test merge using develop at d4a4e81) Against: ca4fc32 (develop) · base run #62950
|
3bba67e to
4eea4c9
Compare
|
bugbot run |
|
bugbot run |
1 similar comment
|
bugbot run |
a9a04bc to
d53b981
Compare
8e34dd6 to
f97d8a2
Compare
…elteKit's root span
… the tunnel outside init
… init or framework defaults Framework SDKs report tunnel options and the base path once with setManagedTunnelDefaults, and ServerRuntimeClient applies them when it's created, so per-request clients get the span filters before their first span starts. The span filters move out of the base Client into the server client, and the server-only helpers move to @sentry/core/server.
The core tunnel handler now streams the envelope to Sentry instead of buffering it, so the forwarded body is a stream.
The paths only depend on the client's tunnel options and DSN, so they're derived when the managed tunnel is settled and read per request. This drops the path cache, which the browser never needed, and the options forms of `isTunnelRequest` and `getTunnelPaths`.
The matcher forwarded through the public handler, which resolved the allowed DSNs again on every request. The client now stores them next to the tunnel paths, and the own DSN is passed explicitly, so a client without a DSN never picks up another client's. The header line is parsed as JSON directly, since it's all the handler reads.
… streamed body Next.js's edge runtime in dev rejects a Content-Length header on a streamed fetch body, so every forward failed with a 500. Relay takes the chunked upload.
They're derived per client, so core keeps them in its own map instead of on the public options type.
#25515's 411 and 413 checks run before the header line is read, so an oversized or unlengthed request is rejected without reading its body.
… ignore a root one
…ne written with a secret key still matches
feae0ed to
98ff881
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 98ff881. Configure here.
Lms24
left a comment
There was a problem hiding this comment.
Given @JPeer264 thorough review, I mainly focused on the forwarding logic itself and had some suggestions for the max size check and forwarding more headers.
I'm +1 for making the browser- and server-specific options browser/server client specific to avoid confusion.
| /** | ||
| * Bounds what one tunnel request may send. SDK envelopes stay far below it. | ||
| */ | ||
| export const MAX_TUNNEL_BODY_SIZE = 20 * 1024 * 1024; |
There was a problem hiding this comment.
m: I know this already existed prior to the PR but given we now stream the request and we don't need to read the entire body, wdyt about removing this limit and just passing back a 413 response from Relay if the envelope was too large?
The 64 KB header limit should make it safe to raise the body limit.
Relay's limit currently is 200MB, so alternatively we can also increase it to that.
There was a problem hiding this comment.
Yep, this wasn't part of the stack but was included to match develop. Agreed on dropping it, I prefer Sentry controls that since we stream the body, so the user's server doesn't pay for buffering it anymore.
Pushed it in b29bdaf
| }); | ||
| } | ||
|
|
||
| function forwardHeaders(request: Request): Record<string, string> { |
There was a problem hiding this comment.
m: we probably also should forward the user agent of the client so that relay can the parse browser and version from it, wdyt?
more specifically, we should forward these headers, including client hints: https://github.com/getsentry/relay/blob/7a1a88fe1c85d1d4d4fac453a7a078bb02a5849d/relay-event-normalization/src/normalize/user_agent.rs#L117-L122
There was a problem hiding this comment.
Oh absolutely, really good catch!
| }); | ||
| } | ||
|
|
||
| function forwardHeaders(request: Request): Record<string, string> { |
There was a problem hiding this comment.
Related, we probably should also forward the Origin and Referer headers, as Relay otherwise skips the allowed domains check: https://github.com/getsentry/relay/blob/7a1a88fe1c85d1d4d4fac453a7a078bb02a5849d/relay-server/src/services/projects/project/info.rs#L215-L234
There was a problem hiding this comment.
Good catch, I forgot about these and the other other ones below. Thanks!

Overview
SDK Tunnel is a feature that allows client SDKs (e.g: browser) to send their requests through an endpoint that lives on the user's own application that forwards to Sentry. This bypasses adblockers and similar extensions.
Tunnels could be configured as a fixed endpoint defined by the user (defaulted to
/monitoring) but that usually ends up in global adblocker lists. Alternatively, users can tell the SDK to use a random endpoint to bypass that.Previously the tunnel logic mostly lived in client bundles and in server frameworks build time, this had two issues:
This stack of PRs re-works the idea by moving to more stable yet random URL generation based on the client's DSN and moves the tunnel handling into the runtime of the core SDK.
Meaning tunneling now is a core SDK capability rather than a meta framework feature.
Here is how it looks for users:
And a tunneled request goes like this: the framework hook calls
handleTunnelRequestIfMatched, if the path matches it checks the envelope's DSN against the allowed ones and forwards it to Sentry, otherwise the request continues as normal.This PR
This sets up the core for the new tunnel mechanism that the rest of the stack will be implemented against, it does the following:
It also sets up a couple of key decisions that will carry over throughout the stack:
/appas a base path our tunnels handlers will expect that prefix.allowedDSNson the server, this correction only applies if the client and server share the same DSN, if there is a different DSN involved then it is on the user to configure that correctly. Will work on documenting this.Reviewing the stack
This PR and #25200 are where the actual behavior lives so these need the closest look, mainly
forwardEnvelopeand the base path handling intunnel.ts.The framework PRs all follow the same pattern: find the earliest request hook the framework gives us, call the core handler there, and pass the framework's base path along. They are small, so ideally whoever knows that framework best picks it up:
sentryHandleunder the app's base path #25415#25414 is tests only, and Next.js #25424 is on hold, I will split it up before it's ready.