Skip to content

Commit f2718a1

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

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-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+
const integrations = getDefaultSolidIntegrations(options);
29+
30+
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false",
31+
// in which case everything inside will get tree-shaken away
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

+45
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,47 @@ 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
46+
?.getOptions()
47+
.integrations.find(integration => integration.name === 'BrowserTracing');
48+
expect(browserTracingIntegration).toBeDefined();
49+
expect(browserTracingIntegration!.isDefaultInstance).toEqual(true);
50+
});
51+
52+
it("doesn't add the `browserTracingIntegration` if `__SENTRY_TRACING__` is false", () => {
53+
// @ts-expect-error Test setup for build-time flag
54+
globalThis.__SENTRY_TRACING__ = false;
55+
56+
const client = solidStartInit({
57+
dsn: 'https://[email protected]/1337',
58+
});
59+
60+
const browserTracingIntegration = client
61+
?.getOptions()
62+
.integrations.find(integration => integration.name === 'BrowserTracing');
63+
expect(browserTracingIntegration).toBeUndefined();
64+
65+
// @ts-expect-error Test setup for build-time flag
66+
delete globalThis.__SENTRY_TRACING__;
67+
});
68+
69+
it("doesn't add the default `browserTracingIntegration` if `solidBrowserTracingIntegration` was already passed in", () => {
70+
const client = solidStartInit({
71+
integrations: [solidRouterBrowserTracingIntegration()],
72+
dsn: 'https://[email protected]/1337',
73+
});
74+
75+
const browserTracingIntegration = client
76+
?.getOptions()
77+
.integrations.find(integration => integration.name === 'BrowserTracing');
78+
expect(browserTracingIntegration).toBeDefined();
79+
expect(browserTracingIntegration!.isDefaultInstance).toBeUndefined();
80+
});
81+
});

0 commit comments

Comments
 (0)