Skip to content

Commit 15a2aa2

Browse files
feat(nextjs): Automatic performance monitoring
1 parent 94c2a4b commit 15a2aa2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/nextjs/src/index.client.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { configureScope, init as reactInit } from '@sentry/react';
2+
import { Integrations } from '@sentry/tracing';
23

4+
import { nextRouterInstrumentation } from './performance/client';
35
import { MetadataBuilder } from './utils/metadataBuilder';
46
import { NextjsOptions } from './utils/nextjsOptions';
7+
import { addIntegration } from './utils/userIntegrations';
58

69
export * from '@sentry/react';
710
export { nextRouterInstrumentation } from './performance/client';
@@ -11,8 +14,21 @@ export function init(options: NextjsOptions): void {
1114
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'react']);
1215
metadataBuilder.addSdkMetadata();
1316
options.environment = options.environment || process.env.NODE_ENV;
17+
addClientIntegrations(options);
1418
reactInit(options);
1519
configureScope(scope => {
1620
scope.setTag('runtime', 'browser');
1721
});
1822
}
23+
24+
const defaultBrowserTracingIntegration = new Integrations.BrowserTracing({
25+
routingInstrumentation: nextRouterInstrumentation,
26+
});
27+
28+
function addClientIntegrations(options: NextjsOptions): void {
29+
if (options.integrations) {
30+
addIntegration(defaultBrowserTracingIntegration, options.integrations);
31+
} else {
32+
options.integrations = [defaultBrowserTracingIntegration];
33+
}
34+
}

0 commit comments

Comments
 (0)