8000 ref: Move RewriteFrames from the plugin to the SDK · szechyjs/sentry-javascript@15e4baa · GitHub
[go: up one dir, main page]

Skip to content

Commit 15e4baa

Browse files
ref: Move RewriteFrames from the plugin to the SDK
Besides, remove unncessary files
1 parent f71c3c9 commit 15e4baa

File tree

5 files changed

+27
-58
lines changed

5 files changed

+27
-58
lines changed

packages/next-plugin-sentry/config.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/next-plugin-sentry/index.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import { init } from '@sentry/nextjs';
2-
import getConfig from 'next/config';
3-
4-
import { getDsn, getRelease } from '../env';
5-
import { clientConfig } from '../config';
1+
import '../../../../sentry.client.config.js';
62

73
export default async function initClient() {
8-
const { publicRuntimeConfig = {} } = getConfig() || {};
9-
const runtimeConfig = publicRuntimeConfig.sentry || {};
10-
11-
init({
12-
dsn: getDsn(),
13-
...(getRelease() && { release: getRelease() }),
14-
...runtimeConfig,
15-
...clientConfig,
16-
});
4+
// TODO: remove this console.log
5+
console.log('on-init-client');
176
}
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,6 @@
1-
import { init } from '@sentry/nextjs';
2-
import { RewriteFrames } from '@sentry/integrations';
3-
import getConfig 10000 from 'next/config';
4-
5-
import { getDsn, getRelease } from '../env';
6-
import { serverConfig } from '../config';
1+
import '../../../../sentry.server.config.js';
72

83
export default async function initServer() {
9-
const { serverRuntimeConfig = {}, publicRuntimeConfig = {} } = getConfig() || {};
10-
const runtimeConfig = serverRuntimeConfig.sentry || publicRuntimeConfig.sentry || {};
11-
12-
init({
13-
dsn: getDsn(),
14-
frameContextLines: 0,
15-
...(getRelease() && { release: getRelease() }),
16-
...runtimeConfig,
17-
...serverConfig,
18-
integrations: [
19-
new RewriteFrames({
20-
iteratee: frame => {
21-
try {
22-
const [_, path] = frame.filename.split('.next/');
23-
if (path) {
24-
frame.filename = `app:///_next/${path}`;
25-
}
26-
} catch {}
27-
return frame;
28-
},
29-
}),
30-
...(runtimeConfig.integrations || []),
31-
...(serverConfig.integrations || []),
32-
],
33-
});
4+
// TODO: remove this console.log
5+
console.log('on-init-server');
346
}

packages/nextjs/src/index.server.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RewriteFrames } from '@sentry/integrations';
12
import { configureScope, init as nodeInit } from '@sentry/node';
23

34
import { InitDecider } from './utils/initDecider';
@@ -10,13 +11,32 @@ export * from '@sentry/node';
1011
// because or SSR of next.js we can only use this.
1112
export { ErrorBoundary, withErrorBoundary } from '@sentry/react';
1213

14+
const SOURCEMAP_FILENAME_REGEX = /^.*\/.next\//;
15+
1316
/** Inits the Sentry NextJS SDK on node. */
1417
export function init(options: NextjsOptions): void {
1518
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'node']);
1619
metadataBuilder.addSdkMetadata();
1720
const initDecider = new InitDecider(options);
1821
if (initDecider.shouldInitSentry()) {
19-
nodeInit(options);
22+
nodeInit({
23+
...options,
24+
// TODO: handle use cases when users provide integrations
25+
integrations: [
26+
new RewriteFrames({
27+
iteratee: frame => {
28+
try {
29+
if (frame.filename) {
30+
frame.filename = frame.filename.replace(SOURCEMAP_FILENAME_REGEX, 'app:///_next/');
31+
}
32+
} catch {
33+
//
34+
}
35+
return frame;
36+
},
37+
}),
38+
],
39+
});
2040
configureScope(scope => {
2141
scope.setTag('runtime', 'node');
2242
});

0 commit comments

Comments
 (0)
0