Skip to content

Commit cd323cd

Browse files
author
Luca Forstner
committed
stuff
1 parent 64144de commit cd323cd

File tree

7 files changed

+19
-124
lines changed

7 files changed

+19
-124
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as Sentry from '@sentry/browser';
2-
import { Integrations } from '@sentry/tracing';
32

43
window.Sentry = Sentry;
54

65
Sentry.init({
76
dsn: 'https://[email protected]/1337',
8-
integrations: [new Integrations.BrowserTracing()],
7+
integrations: [Sentry.browserTracingIntegration()],
98
tracesSampleRate: 1,
109
});

packages/remix/test/integration/app_v2/entry.client.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ Sentry.init({
77
dsn: 'https://[email protected]/1337',
88
tracesSampleRate: 1,
99
integrations: [
10-
new Sentry.BrowserTracing({
11-
routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches),
10+
Sentry.browserTracingIntegration({
11+
useEffect,
12+
useLocation,
13+
useMatches,
1214
}),
1315
],
1416
});

packages/sveltekit/src/client/sdk.ts

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { applySdkMetadata, hasTracingEnabled, setTag } from '@sentry/core';
2-
import type { BrowserOptions, browserTracingIntegration } from '@sentry/svelte';
2+
import type { BrowserOptions } from '@sentry/svelte';
33
import { getDefaultIntegrations as getDefaultSvelteIntegrations } from '@sentry/svelte';
44
import { WINDOW, init as initSvelteSdk } from '@sentry/svelte';
55
import type { Integration } from '@sentry/types';
66

7-
import {
8-
BrowserTracing,
9-
browserTracingIntegration as svelteKitBrowserTracingIntegration,
10-
} from './browserTracingIntegration';
7+
import { browserTracingIntegration as svelteKitBrowserTracingIntegration } from './browserTracingIntegration';
118

129
type WindowWithSentryFetchProxy = typeof WINDOW & {
1310
_sentryFetchProxy?: typeof fetch;
@@ -29,8 +26,6 @@ export function init(options: BrowserOptions): void {
2926

3027
applySdkMetadata(opts, 'sveltekit', ['sveltekit', 'svelte']);
3128

32-
fixBrowserTracingIntegration(opts);
33-
3429
// 1. Switch window.fetch to our fetch proxy we injected earlier
3530
const actualFetch = switchToFetchProxy();
3631

@@ -45,61 +40,6 @@ export function init(options: BrowserOptions): void {
4540
setTag('runtime', 'browser');
4641
}
4742

48-
// TODO v8: Remove this again
49-
// We need to handle BrowserTracing passed to `integrations` that comes from `@sentry/tracing`, not `@sentry/sveltekit` :(
50-
function fixBrowserTracingIntegration(options: BrowserOptions): void {
51-
const { integrations } = options;
52-
if (!integrations) {
53-
return;
54-
}
55-
56-
if (Array.isArray(integrations)) {
57-
options.integrations = maybeUpdateBrowserTracingIntegration(integrations);
58-
} else {
59-
options.integrations = defaultIntegrations => {
60-
const userFinalIntegrations = integrations(defaultIntegrations);
61-
62-
return maybeUpdateBrowserTracingIntegration(userFinalIntegrations);
63-
};
64-
}
65-
}
66-
67-
function isNewBrowserTracingIntegration(
68-
integration: Integration,
69-
): integration is Integration & { options?: Parameters<typeof browserTracingIntegration>[0] } {
70-
// eslint-disable-next-line deprecation/deprecation
71-
return !!integration.afterAllSetup && !!(integration as BrowserTracing).options;
72-
}
73-
74-
function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Integration[] {
75-
const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing');
76-
77-
if (!browserTracing) {
78-
return integrations;
79-
}
80-
81-
// If `browserTracingIntegration()` was added, we need to force-convert it to our custom one
82-
if (isNewBrowserTracingIntegration(browserTracing)) {
83-
const { options } = browserTracing;
84-
// eslint-disable-next-line deprecation/deprecation
85-
integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
86-
}
87-
88-
// If BrowserTracing was added, but it is not our forked version,
89-
// replace it with our forked version with the same options
90-
// eslint-disable-next-line deprecation/deprecation
91-
if (!(browserTracing instanceof BrowserTracing)) {
92-
// eslint-disable-next-line deprecation/deprecation
93-
const options: ConstructorParameters<typeof BrowserTracing>[0] = (browserTracing as BrowserTracing).options;
94-
// This option is overwritten by the custom integration
95-
delete options.routingInstrumentation;
96-
// eslint-disable-next-line deprecation/deprecation
97-
integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
98-
}
99-
100-
return integrations;
101-
}
102-
10343
function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefined {
10444
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
10545
// will get treeshaken away

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('Sentry client SDK', () => {
6161
['tracesSampleRate', { tracesSampleRate: 0 }],
6262
['tracesSampler', { tracesSampler: () => 1.0 }],
6363
['enableTracing', { enableTracing: true }],
64-
])('adds the BrowserTracing integration if tracing is enabled via %s', (_, tracingOptions) => {
64+
])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
6565
init({
6666
dsn: 'https://[email protected]/1337',
6767
...tracingOptions,
@@ -74,7 +74,7 @@ describe('Sentry client SDK', () => {
7474
it.each([
7575
['enableTracing', { enableTracing: false }],
7676
['no tracing option set', {}],
77-
])("doesn't add the BrowserTracing integration if tracing is disabled via %s", (_, tracingOptions) => {
77+
])("doesn't add a browserTracingIntegration integration if tracing is disabled via %s", (_, tracingOptions) => {
7878
init({
7979
dsn: 'https://[email protected]/1337',
8080
...tracingOptions,
@@ -84,7 +84,7 @@ describe('Sentry client SDK', () => {
8484
expect(browserTracing).toBeUndefined();
8585
});
8686

87-
it("doesn't add the BrowserTracing integration if `__SENTRY_TRACING__` is set to false", () => {
87+
it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
8888
// This is the closest we can get to unit-testing the `__SENTRY_TRACING__` tree-shaking guard
8989
// IRL, the code to add the integration would most likely be removed by the bundler.
9090

@@ -100,49 +100,6 @@ describe('Sentry client SDK', () => {
100100

101101
delete globalThis.__SENTRY_TRACING__;
102102
});
103-
104-
it('Merges a user-provided BrowserTracing integration with the automatically added one', () => {
105-
init({
106-
dsn: 'https://[email protected]/1337',
107-
// eslint-disable-next-line deprecation/deprecation
108-
integrations: [new BrowserTracing({ finalTimeout: 10 })],
109-
enableTracing: true,
110-
});
111-
112-
// eslint-disable-next-line deprecation/deprecation
113-
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
114-
const options = browserTracing.options;
115-
116-
expect(browserTracing).toBeDefined();
117-
118-
// This shows that the user-configured options are still here
119-
expect(options.finalTimeout).toEqual(10);
120-
121-
// But we force the routing instrumentation to be ours
122-
// eslint-disable-next-line deprecation/deprecation
123-
expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation);
124-
});
125-
126-
it('Merges a user-provided browserTracingIntegration with the automatically added one', () => {
127-
init({
128-
dsn: 'https://[email protected]/1337',
129-
integrations: [browserTracingIntegration({ finalTimeout: 10 })],
130-
enableTracing: true,
131-
});
132-
133-
// eslint-disable-next-line deprecation/deprecation
134-
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
135-
const options = browserTracing.options;
136-
137-
expect(browserTracing).toBeDefined();
138-
139-
// This shows that the user-configured options are still here
140-
expect(options.finalTimeout).toEqual(10);
141-
142-
// But we force the routing instrumentation to be ours
143-
// eslint-disable-next-line deprecation/deprecation
144-
expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation);
145-
});
146103
});
147104
});
148105
});

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
380380
enableHTTPTimings,
381381
});
382382
},
383-
// TODO v8: Remove this again
384-
// This is private API that we use to fix converted BrowserTracing integrations in Next.js & SvelteKit
385-
options,
386383
};
387384
}) satisfies IntegrationFn;
388385

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import {
33
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
44
TRACING_DEFAULTS,
55
getClient,
6-
getCurrentHub,
76
setCurrentClient,
87
spanToJSON,
98
} from '@sentry/core';
109
import * as hubExtensions from '@sentry/core';
1110
import type { BaseTransportOptions, ClientOptions, DsnComponents, HandlerDataHistory } from '@sentry/types';
1211
import { JSDOM } from 'jsdom';
1312

13+
import { BrowserClient } from '@sentry/browser';
1414
import { timestampInSeconds } from '@sentry/utils';
1515
import type { IdleTransaction } from '../../../tracing/src';
1616
import { getActiveTransaction } from '../../../tracing/src';
1717
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
18+
import { browserTracingIntegration } from '../../build/types';
1819
import type { BrowserTracingOptions } from '../../src/browser/browsertracing';
19-
import { BrowserTracing, getMetaContent } from '../../src/browser/browsertracing';
20+
import { getMetaContent } from '../../src/browser/browsertracing';
2021
import { defaultRequestInstrumentationOptions } from '../../src/browser/request';
2122
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
2223
import { WINDOW } from '../../src/browser/types';
@@ -82,11 +83,10 @@ describe('BrowserTracing', () => {
8283
}
8384
});
8485

85-
function createBrowserTracing(setup?: boolean, _options?: Partial<BrowserTracingOptions>): BrowserTracing {
86-
const instance = new BrowserTracing(_options);
86+
function createBrowserTracing(setup?: boolean, options?: Partial<BrowserTracingOptions>) {
87+
const instance = browserTracingIntegration(options);
8788
if (setup) {
88-
const processor = () => undefined;
89-
instance.setupOnce(processor, () => getCurrentHub() as hubExtensions.Hub);
89+
instance.afterAllSetup(new BrowserClient());
9090
}
9191

9292
return instance;

packages/tracing/test/hub.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { BrowserClient } from '@sentry/browser';
3+
import { BrowserClient, browserTracingIntegration } from '@sentry/browser';
44
import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, makeMain } from '@sentry/core';
55
import * as utilsModule from '@sentry/utils'; // for mocking
66
import { extractTraceparentData, logger } from '@sentry/utils';
@@ -457,7 +457,7 @@ The transaction will not be sampled. Please use the otel instrumentation to star
457457
const options = getDefaultBrowserClientOptions({
458458
dsn: 'https://[email protected]/1121',
459459
tracesSampleRate: 1,
460-
integrations: [new BrowserTracing()],
460+
integrations: [browserTracingIntegration()],
461461
});
462462
const hub = new Hub(new BrowserClient(options));
463463
makeMain(hub);
@@ -496,7 +496,7 @@ The transaction will not be sampled. Please use the otel instrumentation to star
496496
const options = getDefaultBrowserClientOptions({
497497
dsn: 'https://[email protected]/1121',
498498
tracesSampleRate: 1,
499-
integrations: [new BrowserTracing()],
499+
integrations: [browserTracingIntegration()],
500500
});
501501
const hub = new Hub(new BrowserClient(options));
502502
makeMain(hub);

0 commit comments

Comments
 (0)