-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Ensure request from diagnoseSdkConnectivity
doesn't create span
#17280
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
Merged
Lms24
merged 4 commits into
develop
from
lms/fix-browser-diagnose-sdk-connectivity-no-span
Aug 1, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/public-api/diagnoseSdkConnectivity/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,9 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [Sentry.browserTracingIntegration({ idleTimeout: 3000, childSpanTimeout: 3000 })], | ||
tracesSampleRate: 1, | ||
}); |
1 change: 1 addition & 0 deletions
1
dev-packages/browser-integration-tests/suites/public-api/diagnoseSdkConnectivity/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 @@ | ||
Sentry.diagnoseSdkConnectivity().then(res => console.log('SDK connectivity:', res)); |
47 changes: 47 additions & 0 deletions
47
dev-packages/browser-integration-tests/suites/public-api/diagnoseSdkConnectivity/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,47 @@ | ||
import { expect } from '@playwright/test'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest('makes a call to sentry.io to diagnose SDK connectivity', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const pageloadRequestPromise = waitForTransactionRequest(page, e => e.contexts?.trace?.op === 'pageload'); | ||
|
||
// mock sdk connectivity url to avoid making actual request to sentry.io | ||
page.route('**/api/4509632503087104/envelope/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
body: '{}', | ||
}); | ||
}); | ||
|
||
const diagnoseMessagePromise = new Promise<string>(resolve => { | ||
page.on('console', msg => { | ||
if (msg.text().includes('SDK connectivity:')) { | ||
resolve(msg.text()); | ||
} | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const pageLoadEvent = envelopeRequestParser(await pageloadRequestPromise); | ||
|
||
// udnefined is expected and means the request was successful | ||
expect(await diagnoseMessagePromise).toEqual('SDK connectivity: undefined'); | ||
|
||
// the request to sentry.io should not be traced, hence no http.client span should be sent. | ||
const httpClientSpans = pageLoadEvent.spans?.filter(s => s.op === 'http.client'); | ||
expect(httpClientSpans).toHaveLength(0); | ||
|
||
// no fetch breadcrumb should be sent (only breadcrumb for the console log) | ||
expect(pageLoadEvent.breadcrumbs).toEqual([ | ||
expect.objectContaining({ | ||
category: 'console', | ||
message: 'SDK connectivity: undefined', | ||
}), | ||
]); | ||
}); |
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,4 +1,4 @@ | ||
import { getClient } from '@sentry/core'; | ||
import { getClient, suppressTracing } from '@sentry/core'; | ||
|
||
/** | ||
* A function to diagnose why the SDK might not be successfully sending data. | ||
|
@@ -23,20 +23,22 @@ export async function diagnoseSdkConnectivity(): Promise< | |
} | ||
|
||
try { | ||
// If fetch throws, there is likely an ad blocker active or there are other connective issues. | ||
await fetch( | ||
// We are using the | ||
// - "sentry-sdks" org with id 447951 not to pollute any actual organizations. | ||
// - "diagnose-sdk-connectivity" project with id 4509632503087104 | ||
// - the public key of said org/project, which is disabled in the project settings | ||
// => this DSN: https://[email protected]/4509632503087104 (i.e. disabled) | ||
'https://o447951.ingest.sentry.io/api/4509632503087104/envelope/?sentry_version=7&sentry_key=c1dfb07d783ad5325c245c1fd3725390&sentry_client=sentry.javascript.browser%2F1.33.7', | ||
{ | ||
body: '{}', | ||
method: 'POST', | ||
mode: 'cors', | ||
credentials: 'omit', | ||
}, | ||
await suppressTracing(() => | ||
// If fetch throws, there is likely an ad blocker active or there are other connective issues. | ||
fetch( | ||
// We are using the | ||
// - "sentry-sdks" org with id 447951 not to pollute any actual organizations. | ||
// - "diagnose-sdk-connectivity" project with id 4509632503087104 | ||
// - the public key of said org/project, which is disabled in the project settings | ||
// => this DSN: https://[email protected]/4509632503087104 (i.e. disabled) | ||
'https://o447951.ingest.sentry.io/api/4509632503087104/envelope/?sentry_version=7&sentry_key=c1dfb07d783ad5325c245c1fd3725390&sentry_client=sentry.javascript.browser%2F1.33.7', | ||
{ | ||
body: '{}', | ||
method: 'POST', | ||
mode: 'cors', | ||
credentials: 'omit', | ||
}, | ||
), | ||
); | ||
} catch { | ||
return 'sentry-unreachable'; | ||
|
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 |
---|---|---|
|
@@ -162,4 +162,18 @@ describe('diagnoseSdkConnectivity', () => { | |
credentials: 'omit', | ||
}); | ||
}); | ||
|
||
it('calls suppressTracing to avoid tracing the fetch call to sentry', async () => { | ||
const suppressTracingSpy = vi.spyOn(sentryCore, 'suppressTracing'); | ||
|
||
const mockClient: Partial<Client> = { | ||
getDsn: vi.fn().mockReturnValue('https://[email protected]/123'), | ||
}; | ||
mockGetClient.mockReturnValue(mockClient); | ||
mockFetch.mockResolvedValue(new Response('{}', { status: 200 })); | ||
|
||
await diagnoseSdkConnectivity(); | ||
|
||
expect(suppressTracingSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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.