Skip to content

Commit f867cc0

Browse files
authored
feat(nuxt): Automatically add BrowserTracing (#13005)
Add `BrowserTracing` when `tracesSampleRate` is set.
1 parent 5a709df commit f867cc0

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

dev-packages/e2e-tests/test-applications/nuxt-3/sentry.client.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
tunnel: `http://localhost:3031/`, // proxy server
77
tracesSampleRate: 1.0,
8-
integrations: [Sentry.browserTracingIntegration()],
98
});

packages/nuxt/src/client/sdk.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { init as initBrowser } from '@sentry/browser';
1+
import {
2+
browserTracingIntegration,
3+
getDefaultIntegrations as getBrowserDefaultIntegrations,
4+
init as initBrowser,
5+
} from '@sentry/browser';
26
import { applySdkMetadata } from '@sentry/core';
37
import type { Client } from '@sentry/types';
48
import type { SentryNuxtOptions } from '../common/types';
@@ -10,6 +14,7 @@ import type { SentryNuxtOptions } from '../common/types';
1014
*/
1115
export function init(options: SentryNuxtOptions): Client | undefined {
1216
const sentryOptions = {
17+
defaultIntegrations: [...getBrowserDefaultIntegrations(options), browserTracingIntegration()],
1318
...options,
1419
};
1520

packages/nuxt/test/client/sdk.test.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as SentryBrowser from '@sentry/browser';
2-
import { SDK_VERSION } from '@sentry/vue';
2+
import { type BrowserClient, SDK_VERSION, getClient } from '@sentry/vue';
33
import { beforeEach, describe, expect, it, vi } from 'vitest';
44
import { init } from '../../src/client';
55

6-
const vueInit = vi.spyOn(SentryBrowser, 'init');
6+
const browserInit = vi.spyOn(SentryBrowser, 'init');
77

88
describe('Nuxt Client SDK', () => {
99
describe('init', () => {
@@ -12,7 +12,7 @@ describe('Nuxt Client SDK', () => {
1212
});
1313

1414
it('Adds Nuxt metadata to the SDK options', () => {
15-
expect(vueInit).not.toHaveBeenCalled();
15+
expect(browserInit).not.toHaveBeenCalled();
1616

1717
init({
1818
dsn: 'https://[email protected]/1337',
@@ -31,8 +31,25 @@ describe('Nuxt Client SDK', () => {
3131
},
3232
};
3333

34-
expect(vueInit).toHaveBeenCalledTimes(1);
35-
expect(vueInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
34+
expect(browserInit).toHaveBeenCalledTimes(1);
35+
expect(browserInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
36+
});
37+
38+
describe('Automatically adds BrowserTracing integration', () => {
39+
it.each([
40+
['tracesSampleRate', { tracesSampleRate: 0 }],
41+
['tracesSampler', { tracesSampler: () => 1.0 }],
42+
['enableTracing', { enableTracing: true }],
43+
['no tracing option set', {}] /* enable "tracing without performance" by default */,
44+
])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
45+
init({
46+
dsn: 'https://[email protected]/1337',
47+
...tracingOptions,
48+
});
49+
50+
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
51+
expect(browserTracing).toBeDefined();
52+
});
3653
});
3754

3855
it('returns client from init', () => {

0 commit comments

Comments
 (0)