Skip to content

Commit 70f327c

Browse files
committed
feat(solidstart): Add browserTracingIntegration by default
1 parent f452423 commit 70f327c

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

packages/solidstart/src/client/sdk.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
import { applySdkMetadata } from '@sentry/core';
22
import type { BrowserOptions } from '@sentry/solid';
3-
import { init as initSolidSDK } from '@sentry/solid';
4-
import type { Client } from '@sentry/types';
3+
import {
4+
browserTracingIntegration,
5+
getDefaultIntegrations as getDefaultSolidIntegrations,
6+
init as initSolidSDK,
7+
} from '@sentry/solid';
8+
import type { Client, Integration } from '@sentry/types';
9+
10+
// Treeshakable guard to remove all code related to tracing
11+
declare const __SENTRY_TRACING__: boolean;
512

613
/**
714
* Initializes the client side of the Solid Start SDK.
815
*/
916
export function init(options: BrowserOptions): Client | undefined {
1017
const opts = {
18+
defaultIntegrations: getDefaultIntegrations(options),
1119
...options,
1220
};
1321

1422
applySdkMetadata(opts, 'solidstart', ['solidstart', 'solid']);
1523

1624
return initSolidSDK(opts);
1725
}
26+
27+
function getDefaultIntegrations(options: BrowserOptions): Integration[] {
28+
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false",
29+
// in which case everything inside will get tree-shaken away
30+
const integrations = getDefaultSolidIntegrations(options);
31+
32+
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
33+
// We add the default BrowserTracingIntegration here always.
34+
// We can do this, even if `solidRouterBrowserTracingIntegration` is
35+
// supplied as integration in `init` by users because it will win
36+
// over the default integration by virtue of having the same
37+
// `BrowserTracing` integration name and being added later.
38+
integrations.push(browserTracingIntegration());
39+
}
40+
41+
return integrations;
42+
}

packages/solidstart/test/client/sdk.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as SentrySolid from '@sentry/solid';
33

44
import { vi } from 'vitest';
55
import { init as solidStartInit } from '../../src/client';
6+
import { solidRouterBrowserTracingIntegration } from '../../src/client/solidrouter';
67

78
const browserInit = vi.spyOn(SentrySolid, 'init');
89

@@ -34,3 +35,43 @@ describe('Initialize Solid Start SDK', () => {
3435
expect(browserInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
3536
});
3637
});
38+
39+
describe('browserTracingIntegration', () => {
40+
it('adds the `browserTracingIntegration` when `__SENTRY_TRACING__` is not set', () => {
41+
const client = solidStartInit({
42+
dsn: 'https://[email protected]/1337',
43+
});
44+
45+
const browserTracingIntegration = client?.getOptions().integrations.find(integration => integration.name === 'BrowserTracing');
46+
expect(browserTracingIntegration).toBeDefined();
47+
expect(browserTracingIntegration!.isDefaultInstance).toEqual(true);
48+
});
49+
50+
it("doesn't add the `browserTracingIntegration` if `__SENTRY_TRACING__` is false", () => {
51+
// @ts-expect-error Test setup for build-time flag
52+
globalThis.__SENTRY_TRACING__ = false;
53+
54+
const client = solidStartInit({
55+
dsn: 'https://[email protected]/1337',
56+
});
57+
58+
const browserTracingIntegration = client?.getOptions().integrations.find(integration => integration.name === 'BrowserTracing');
59+
expect(browserTracingIntegration).toBeUndefined();
60+
61+
// @ts-expect-error Test setup for build-time flag
62+
delete globalThis.__SENTRY_TRACING__;
63+
});
64+
65+
it("doesn't add the default `browserTracingIntegration` if `solidBrowserTracingIntegration` was already passed in", () => {
66+
const client = solidStartInit({
67+
integrations: [
68+
solidRouterBrowserTracingIntegration(),
69+
],
70+
dsn: 'https://[email protected]/1337',
71+
});
72+
73+
const browserTracingIntegration = client?.getOptions().integrations.find(integration => integration.name === 'BrowserTracing');
74+
expect(browserTracingIntegration).toBeDefined();
75+
expect(browserTracingIntegration!.isDefaultInstance).toBeUndefined();
76+
})
77+
});

0 commit comments

Comments
 (0)