-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Add diagnoseSdkConnectivity()
function to programmatically detect possible connectivity issues
#15821
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cec610c
feat(browser): Add `diagnoseSdk()` function to programmatically detec…
lforst 4f755ad
moar comment
lforst b1703a8
more comment
lforst 77b07ca
comment
lforst 30da2fa
simplify
lforst 5ba8e38
check for dsn
lforst 371e228
export
lforst efbc46a
different org
lforst fecaf0e
empty object
lforst 7881e06
different client
lforst 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getClient } from '@sentry/core'; | ||
|
||
/** | ||
* A function to diagnose why the SDK might not be successfully sending data. | ||
* | ||
* Possible return values wrapped in a Promise: | ||
* - `"no-client-active"` - There was no active client when the function was called. This possibly means that the SDK was not initialized yet. | ||
* - `"sentry-unreachable"` - The Sentry SaaS servers were not reachable. This likely means that there is an ad blocker active on the page or that there are other connection issues. | ||
* | ||
* If the function doesn't detect an issue it resolves to `undefined`. | ||
*/ | ||
export async function diagnoseSdkConnectivity(): Promise< | ||
'no-client-active' | 'sentry-unreachable' | 'no-dsn-configured' | void | ||
> { | ||
const client = getClient(); | ||
|
||
if (!client) { | ||
return 'no-client-active'; | ||
} | ||
|
||
if (!client.getDsn()) { | ||
return 'no-dsn-configured'; | ||
} | ||
|
||
try { | ||
// If fetch throws, there is likely an ad blocker active or there are other connective issues. | ||
await fetch( | ||
// We want this to be as close as possible to an actual ingest URL so that ad blockers will actually block the request | ||
// We are using the "sentry-sdks" org with id 447951 not to pollute any actual organizations. | ||
'https://o447951.ingest.sentry.io/api/1337/envelope/?sentry_version=7&sentry_key=1337&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
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.