-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: Emit low-cardinality http.client span names for fetch and XHR #23682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chargome
wants to merge
6
commits into
develop
Choose a base branch
from
charlygomez/js-3412-http-client-fetch-xhr
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f56b80d
feat: Emit low-cardinality http.client span names for fetch and XHR
chargome bdcfbb5
fix: Strip userinfo from browser outgoing request names and attributes
chargome 138a751
feat: Resolve relative outgoing-request URLs to the page domain
chargome 937a144
Merge remote-tracking branch 'origin/develop' into incorporate-pr-236…
chargome ad9e54c
test: Remove pageload-span race from relative-URL streamed tests
chargome 5385238
test: Drop redundant spanStreamingIntegration from new streamed suites
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
10 changes: 10 additions & 0 deletions
10
...ages/browser-integration-tests/suites/tracing/request/fetch-relative-url-streamed/init.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration()], | ||
| tracesSampleRate: 1, | ||
| autoSessionTracking: false, | ||
| }); |
1 change: 1 addition & 0 deletions
1
...s/browser-integration-tests/suites/tracing/request/fetch-relative-url-streamed/subject.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fetch('/test-req/0').then(fetch('/test-req/1').then(fetch('/test-req/2'))); |
39 changes: 39 additions & 0 deletions
39
...ages/browser-integration-tests/suites/tracing/request/fetch-relative-url-streamed/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest, TEST_HOST } from '../../../../utils/fixtures'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('names spans for relative fetch requests after the page domain', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const spansPromise = waitForStreamedSpans( | ||
| page, | ||
| spans => spans.filter(s => getSpanOp(s) === 'http.client').length >= 3, | ||
| ); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const requestSpans = (await spansPromise) | ||
| .filter(s => getSpanOp(s) === 'http.client') | ||
| .sort((a, b) => | ||
| (a.attributes!['url.full']!.value as string).localeCompare(b.attributes!['url.full']!.value as string), | ||
| ); | ||
|
|
||
| expect(requestSpans).toHaveLength(3); | ||
|
|
||
| requestSpans.forEach((span, index) => | ||
| expect(span).toMatchObject({ | ||
| // A relative URL has no domain of its own, so it resolves against the page origin. | ||
| name: 'GET sentry-test.io', | ||
| attributes: expect.objectContaining({ | ||
| 'http.request.method': { type: 'string', value: 'GET' }, | ||
| 'url.full': { type: 'string', value: `${TEST_HOST}/test-req/${index}` }, | ||
| 'url.domain': { type: 'string', value: 'sentry-test.io' }, | ||
| 'server.address': { type: 'string', value: 'sentry-test.io' }, | ||
| type: { type: 'string', value: 'fetch' }, | ||
| }), | ||
| }), | ||
| ); | ||
| }); |
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
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
10 changes: 10 additions & 0 deletions
10
...ckages/browser-integration-tests/suites/tracing/request/xhr-relative-url-streamed/init.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration()], | ||
| tracesSampleRate: 1, | ||
| autoSessionTracking: false, | ||
| }); |
11 changes: 11 additions & 0 deletions
11
...ges/browser-integration-tests/suites/tracing/request/xhr-relative-url-streamed/subject.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const xhr_1 = new XMLHttpRequest(); | ||
| xhr_1.open('GET', '/test-req/0'); | ||
| xhr_1.send(); | ||
|
|
||
| const xhr_2 = new XMLHttpRequest(); | ||
| xhr_2.open('GET', '/test-req/1'); | ||
| xhr_2.send(); | ||
|
|
||
| const xhr_3 = new XMLHttpRequest(); | ||
| xhr_3.open('GET', '/test-req/2'); | ||
| xhr_3.send(); |
39 changes: 39 additions & 0 deletions
39
...ckages/browser-integration-tests/suites/tracing/request/xhr-relative-url-streamed/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest, TEST_HOST } from '../../../../utils/fixtures'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('names spans for relative XHR requests after the page domain', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const spansPromise = waitForStreamedSpans( | ||
| page, | ||
| spans => spans.filter(s => getSpanOp(s) === 'http.client').length >= 3, | ||
| ); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const requestSpans = (await spansPromise) | ||
| .filter(s => getSpanOp(s) === 'http.client') | ||
| .sort((a, b) => | ||
| (a.attributes!['url.full']!.value as string).localeCompare(b.attributes!['url.full']!.value as string), | ||
| ); | ||
|
|
||
| expect(requestSpans).toHaveLength(3); | ||
|
|
||
| requestSpans.forEach((span, index) => | ||
| expect(span).toMatchObject({ | ||
| // A relative URL has no domain of its own, so it resolves against the page origin. | ||
| name: 'GET sentry-test.io', | ||
| attributes: expect.objectContaining({ | ||
| 'http.request.method': { type: 'string', value: 'GET' }, | ||
| 'url.full': { type: 'string', value: `${TEST_HOST}/test-req/${index}` }, | ||
| 'url.domain': { type: 'string', value: 'sentry-test.io' }, | ||
| 'server.address': { type: 'string', value: 'sentry-test.io' }, | ||
| type: { type: 'string', value: 'xhr' }, | ||
| }), | ||
| }), | ||
| ); | ||
| }); |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| import { HTTP_REQUEST_METHOD, SENTRY_OP, URL_FULL } from '@sentry/conventions/attributes'; | ||
| import { HTTP_REQUEST_METHOD, SENTRY_OP, URL_DOMAIN, URL_FULL } from '@sentry/conventions/attributes'; | ||
| import { HTTP_CLIENT_STREAM } from '@sentry/conventions/op'; | ||
| import type { IntegrationFn, Span } from '@sentry/core'; | ||
| import { | ||
| addFetchEndInstrumentationHandler, | ||
| addFetchInstrumentationHandler, | ||
| defineIntegration, | ||
| getSanitizedUrlStringFromUrlObject, | ||
| getUrlDomain, | ||
| hasSpanStreamingEnabled, | ||
| parseStringToURLObject, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| stripDataUrlContent, | ||
| filterCollectedUrl, | ||
| startInactiveSpan, | ||
| } from '@sentry/core/browser'; | ||
| import { WINDOW } from '../helpers'; | ||
|
|
||
| const responseToStreamSpan = new WeakMap<object, Span>(); | ||
| const responseToFallbackTimeout = new WeakMap<object, ReturnType<typeof setTimeout>>(); | ||
|
|
@@ -37,7 +40,7 @@ export const fetchStreamPerformanceIntegration = defineIntegration(() => { | |
| return { | ||
| name: 'FetchStreamPerformance' as const, | ||
|
|
||
| setup() { | ||
| setup(client) { | ||
| // End the stream span when the response body finishes resolving | ||
| addFetchEndInstrumentationHandler(handlerData => { | ||
| if (handlerData.response) { | ||
|
|
@@ -78,11 +81,15 @@ export const fetchStreamPerformanceIntegration = defineIntegration(() => { | |
| ? getSanitizedUrlStringFromUrlObject(parsedUrl) | ||
| : url; | ||
|
|
||
| // `http.client.stream` follows the same name rules as `http.client`. | ||
| const domain = getUrlDomain(url, WINDOW.location?.origin); | ||
| const streamedName = domain ? `${method} ${domain}` : method; | ||
| const streamSpan = startInactiveSpan({ | ||
| name: `${method} ${sanitizedUrl}`, | ||
| name: hasSpanStreamingEnabled(client) ? streamedName : `${method} ${sanitizedUrl}`, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: The Edit: seems like the PR description covers that part |
||
| startTime: handlerData.endTimestamp, | ||
| attributes: { | ||
| [URL_FULL]: filterCollectedUrl(stripDataUrlContent(url)), | ||
| [URL_DOMAIN]: domain, | ||
| [HTTP_REQUEST_METHOD]: method, | ||
| type: 'fetch', | ||
| [SENTRY_OP]: HTTP_CLIENT_STREAM, | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.