Skip to content

fix(browser): Enrich graphqlClient spans for relative URLs#20370

Merged
logaretm merged 1 commit intodevelopfrom
awad/js-2166-enrich-graphql-spans-for-relative-urls
Apr 17, 2026
Merged

fix(browser): Enrich graphqlClient spans for relative URLs#20370
logaretm merged 1 commit intodevelopfrom
awad/js-2166-enrich-graphql-spans-for-relative-urls

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented Apr 16, 2026

The graphqlClientIntegration didn’t enrich spans for GraphQL requests to relative URLs because the handler used url.full or http.url to identify the request URL.

However, in packages/core/src/fetch.ts:382-386, the fetch instrumentation only sets http.url for non-relative URLs and never sets url.full. Therefore, for relative endpoints, httpUrl was undefined, failed the isString guard, and the enrichment bailed out silently.

By addingspanAttributes['url'] as a third option. Scoped to the graphqlClient integration, this ensures enrichment happens and it's only scoped to the gql integration.

The alternative was to populate http.url (or url.full) for relative URLs in getFetchSpanAttributes which is dangerous because http.url is a span attribute many users filter, group, alert, and build dashboards on.

With this change, the endpoints matcher now sees the relative path (e.g. /graphql) instead of an absolute URL. If a user configured endpoints with an absolute-URL regex and uses relative fetches, that pattern won't match the relative form. However this changes nothing today because it never worked before (was undefined).

closes #20292

Fall back to the `url` span attribute when `url.full`/`http.url` are
absent. The fetch instrumentation only sets `http.url` for absolute URLs
(see `getFetchSpanAttributes` in packages/core/src/fetch.ts), so
relative endpoints like `/graphql` previously bailed out of the
graphqlClient enrichment and never received `graphql.document` or the
updated span name.

Fixes #20292

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 16, 2026

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.78 kB - -
@sentry/browser - with treeshaking flags 24.27 kB - -
@sentry/browser (incl. Tracing) 43.65 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 45.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 48.58 kB - -
@sentry/browser (incl. Tracing, Replay) 82.79 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.29 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.49 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 99.74 kB - -
@sentry/browser (incl. Feedback) 42.59 kB - -
@sentry/browser (incl. sendFeedback) 30.45 kB - -
@sentry/browser (incl. FeedbackAsync) 35.45 kB - -
@sentry/browser (incl. Metrics) 27.07 kB - -
@sentry/browser (incl. Logs) 27.2 kB - -
@sentry/browser (incl. Metrics & Logs) 27.89 kB - -
@sentry/react 27.53 kB - -
@sentry/react (incl. Tracing) 45.92 kB - -
@sentry/vue 30.61 kB - -
@sentry/vue (incl. Tracing) 45.49 kB - -
@sentry/svelte 25.8 kB - -
CDN Bundle 28.46 kB - -
CDN Bundle (incl. Tracing) 44.73 kB - -
CDN Bundle (incl. Logs, Metrics) 29.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 45.81 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.73 kB - -
CDN Bundle (incl. Tracing, Replay) 81.68 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 82.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 87.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 88.27 kB - -
CDN Bundle - uncompressed 83.12 kB - -
CDN Bundle (incl. Tracing) - uncompressed 133.75 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.17 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 250.99 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 254.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 263.9 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 267.29 kB - -
@sentry/nextjs (client) 48.44 kB - -
@sentry/sveltekit (client) 44.09 kB - -
@sentry/node-core 57.94 kB +0.02% +6 B 🔺
@sentry/node 174.78 kB +0.01% +5 B 🔺
@sentry/node - without tracing 97.89 kB +0.03% +21 B 🔺
@sentry/aws-serverless 115.12 kB +0.01% +9 B 🔺

View base workflow run

@logaretm logaretm marked this pull request as ready for review April 16, 2026 19:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes graphqlClientIntegration span enrichment for GraphQL requests sent to relative URLs in the browser by expanding which span attribute is used to determine the request URL.

Changes:

  • Extend GraphQL span enrichment URL detection to fall back to the url span attribute when url.full / http.url are absent (relative fetch URLs).
  • Add/extend tests to cover enrichment behavior for absolute URLs, relative URLs, missing URL attributes, and non-http.client spans.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/browser/src/integrations/graphqlClient.ts Adds spanAttributes['url'] fallback so relative-URL fetch spans can be matched/enriched.
packages/browser/test/integrations/graphqlClient.test.ts Adds handler-level tests validating enrichment for absolute vs relative URLs and negative cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@logaretm logaretm merged commit 9ee1f77 into develop Apr 17, 2026
347 of 349 checks passed
@logaretm logaretm deleted the awad/js-2166-enrich-graphql-spans-for-relative-urls branch April 17, 2026 13:28
andreiborza pushed a commit that referenced this pull request Apr 20, 2026
The `graphqlClientIntegration` didn’t enrich spans for GraphQL requests
to relative URLs because the handler used `url.full` or `http.url` to
identify the request URL.

However, in `packages/core/src/fetch.ts:382-386`, the fetch
instrumentation only sets `http.url` for non-relative URLs and never
sets `url.full`. Therefore, for relative endpoints, `httpUrl` was
`undefined`, failed the `isString` guard, and the enrichment bailed out
silently.

By adding`spanAttributes['url']` as a third option. Scoped to the
graphqlClient integration, this ensures enrichment happens and it's only
scoped to the gql integration.

The alternative was to populate `http.url` (or `url.full`) for relative
URLs in `getFetchSpanAttributes` which is dangerous because `http.url`
is a span attribute many users filter, group, alert, and build
dashboards on.

With this change, the `endpoints` matcher now sees the relative path
(e.g. `/graphql`) instead of an absolute URL. If a user configured
`endpoints` with an absolute-URL regex and uses relative fetches, that
pattern won't match the relative form. However this changes nothing
today because it never worked before (was `undefined`).

closes #20292

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

graphqlClientIntegration does not enrich spans for relative URLs

4 participants