fix(browser): Enrich graphqlClient spans for relative URLs#20370
Merged
fix(browser): Enrich graphqlClient spans for relative URLs#20370
Conversation
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>
Contributor
size-limit report 📦
|
Contributor
There was a problem hiding this comment.
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
urlspan attribute whenurl.full/http.urlare absent (relative fetch URLs). - Add/extend tests to cover enrichment behavior for absolute URLs, relative URLs, missing URL attributes, and non-
http.clientspans.
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.
mydea
approved these changes
Apr 17, 2026
nicohrubec
approved these changes
Apr 17, 2026
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>
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.
The
graphqlClientIntegrationdidn’t enrich spans for GraphQL requests to relative URLs because the handler usedurl.fullorhttp.urlto identify the request URL.However, in
packages/core/src/fetch.ts:382-386, the fetch instrumentation only setshttp.urlfor non-relative URLs and never setsurl.full. Therefore, for relative endpoints,httpUrlwasundefined, failed theisStringguard, 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(orurl.full) for relative URLs ingetFetchSpanAttributeswhich is dangerous becausehttp.urlis a span attribute many users filter, group, alert, and build dashboards on.With this change, the
endpointsmatcher now sees the relative path (e.g./graphql) instead of an absolute URL. If a user configuredendpointswith 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 (wasundefined).closes #20292