MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / diagnoseSdkConnectivity

Function diagnoseSdkConnectivity

packages/browser/src/diagnose-sdk.ts:12–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10 * If the function doesn't detect an issue it resolves to `undefined`.
11 */
12export async function diagnoseSdkConnectivity(): Promise<
13 'no-client-active' | 'sentry-unreachable' | 'no-dsn-configured' | void
14> {
15 const client = getClient();
16
17 if (!client) {
18 return 'no-client-active';
19 }
20
21 if (!client.getDsn()) {
22 return 'no-dsn-configured';
23 }
24
25 // Check if a tunnel is configured and use it if available
26 const tunnel = client.getOptions().tunnel;
27
28 // We are using the
29 // - "sentry-sdks" org with id 447951 not to pollute any actual organizations.
30 // - "diagnose-sdk-connectivity" project with id 4509632503087104
31 // - the public key of said org/project, which is disabled in the project settings
32 // => this DSN: https://c1dfb07d783ad5325c245c1fd3725390@o447951.ingest.us.sentry.io/4509632503087104 (i.e. disabled)
33 const defaultUrl =
34 'https://o447951.ingest.sentry.io/api/4509632503087104/envelope/?sentry_version=7&sentry_key=c1dfb07d783ad5325c245c1fd3725390&sentry_client=sentry.javascript.browser%2F1.33.7';
35
36 const url = tunnel || defaultUrl;
37
38 try {
39 await suppressTracing(() =>
40 // If fetch throws, there is likely an ad blocker active or there are other connective issues.
41 fetch(url, {
42 body: '{}',
43 method: 'POST',
44 mode: 'cors',
45 credentials: 'omit',
46 }),
47 );
48 } catch {
49 return 'sentry-unreachable';
50 }
51}

Callers 1

Calls 4

getClientFunction · 0.90
getOptionsMethod · 0.65
suppressTracingFunction · 0.50
fetchFunction · 0.50

Tested by

no test coverage detected