Skip to content

Commit cbacaa9

Browse files
feat: NextJS client and server sides (#3277)
1 parent 8cd3228 commit cbacaa9

File tree

8 files changed

+179
-9
lines changed

8 files changed

+179
-9
lines changed

packages/nextjs/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ module.exports = {
2727
],
2828
rules: {
2929
'max-lines': 'off',
30+
'@sentry-internal/sdk/no-async-await': 'off',
31+
'jsdoc/require-jsdoc': 0,
3032
},
3133
};

packages/nextjs/package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/nextjs",
3-
"version": "6.1.0",
3+
"version": "6.2.0",
44
"description": "Official Sentry SDK for Next.js",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nextjs",
@@ -9,16 +9,22 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
12+
"main": "./dist/index.js",
13+
"module": "./esm/node.js",
14+
"browser": "./esm/browser.js",
15+
"types": "./dist/index.d.ts",
1516
"publishConfig": {
1617
"access": "public"
1718
},
18-
"dependencies": {},
19+
"dependencies": {
20+
"@sentry/browser": "6.2.0",
21+
"@sentry/node": "6.2.0",
22+
"@sentry/minimal": "6.2.0"
23+
},
1924
"devDependencies": {
20-
"eslint": "^7.20.0",
21-
"rimraf": "^3.0.2"
25+
"@sentry/types": "6.2.0",
26+
"eslint": "7.20.0",
27+
"rimraf": "3.0.2"
2228
},
2329
"scripts": {
2430
"build": "run-p build:es5 build:esm",

packages/nextjs/src/browser.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { init as browserInit } from '@sentry/browser';
2+
3+
import { MetadataBuilder, NextjsOptions } from './options';
4+
5+
/** Inits the Sentry NextJS SDK on the browser. */
6+
export function init(options: NextjsOptions): any {
7+
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'browser']);
8+
metadataBuilder.addSdkMetadata();
9+
browserInit(options);
10+
}
11+
12+
export * from '@sentry/minimal';

packages/nextjs/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { init } from './sdk';
2+
export * from '@sentry/minimal';

packages/nextjs/src/node.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { init as nodeInit } from '@sentry/node';
2+
3+
import { MetadataBuilder, NextjsOptions } from './options';
4+
5+
/** Inits the Sentry NextJS SDK on node. */
6+
export function init(options: NextjsOptions): any {
7+
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'node']);
8+
metadataBuilder.addSdkMetadata();
9+
nodeInit(options);
10+
}
11+
12+
export * from '@sentry/minimal';

packages/nextjs/src/options.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { BrowserOptions, SDK_VERSION } from '@sentry/browser';
2+
import { NodeOptions } from '@sentry/node';
3+
import { Options, Package, SdkInfo } from '@sentry/types';
4+
5+
const SDK_NAME = 'sentry.javascript.nextjs';
6+
const PACKAGE_NAME_PREFIX = 'npm:@sentry/';
7+
8+
export interface NextjsOptions extends Options, BrowserOptions, NodeOptions {
9+
// TODO: options for NextJS
10+
}
11+
12+
/**
13+
* A builder for the SDK metadata in the options for the SDK initialization.
14+
*/
15+
export class MetadataBuilder {
16+
private _options: NextjsOptions;
17+
private _packageNames: string[];
18+
19+
constructor(options: NextjsOptions, packages: string[]) {
20+
this._options = options;
21+
this._packageNames = packages;
22+
}
23+
24+
public addSdkMetadata(): void {
25+
this._options._metadata = this._options._metadata || {};
26+
this._options._metadata.sdk = this._getSdkInfo();
27+
}
28+
29+
private _getSdkInfo(): SdkInfo {
30+
return {
31+
name: SDK_NAME,
32+
version: SDK_VERSION,
33+
packages: this._getPackages(),
34+
};
35+
}
36+
37+
private _getPackages(): Package[] {
38+
return this._packageNames.map((pkgName: string) => {
39+
return {
40+
name: PACKAGE_NAME_PREFIX + pkgName,
41+
version: SDK_VERSION,
42+
};
43+
});
44+
}
45+
}

packages/nextjs/src/sdk.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
// eslint-disable-next-line no-console
2-
console.log('Sentaurs greet NextJS!');
1+
import { init as browserInit } from '@sentry/browser';
2+
3+
import { MetadataBuilder, NextjsOptions } from './options';
4+
5+
/**
6+
* The Sentry NextJS SDK Client.
7+
*
8+
* TODO: docs, examples...
9+
*
10+
*/
11+
export function init(options: NextjsOptions): void {
12+
const metadataBuilder = new MetadataBuilder(options, ['nextjs']);
13+
metadataBuilder.addSdkMetadata();
14+
browserInit(options);
15+
}

yarn.lock

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,84 @@
32763276
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
32773277
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
32783278

3279+
"@sentry/browser@^6.2.0":
3280+
version "6.2.0"
3281+
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.2.0.tgz#4113a92bc82f55e63f30cb16a94f717bd0b95817"
3282+
integrity sha512-4r3paHcHXLemj471BtNDhUs2kvJxk5XDRplz1dbC/LHXN5PWEXP4anhGILxOlxqi4y33r53PIZu3xXFjznaVZA==
3283+
dependencies:
3284+
"@sentry/core" "6.2.0"
3285+
"@sentry/types" "6.2.0"
3286+
"@sentry/utils" "6.2.0"
3287+
tslib "^1.9.3"
3288+
3289+
3290+
version "6.2.0"
3291+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.2.0.tgz#be1c33854fc94e1a4d867f7c2c311cf1cefb8ee9"
3292+
integrity sha512-oTr2b25l+0bv/+d6IgMamPuGleWV7OgJb0NFfd+WZhw6UDRgr7CdEJy2gW6tK8SerwXgPHdn4ervxsT3WIBiXw==
3293+
dependencies:
3294+
"@sentry/hub" "6.2.0"
3295+
"@sentry/minimal" "6.2.0"
3296+
"@sentry/types" "6.2.0"
3297+
"@sentry/utils" "6.2.0"
3298+
tslib "^1.9.3"
3299+
3300+
3301+
version "6.2.0"
3302+
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.2.0.tgz#e7502652bc9608cf8fb63e43cd49df9019a28f29"
3303+
integrity sha512-BDTEFK8vlJydWXp/KMX0stvv73V7od224iLi+w3k7BcPwMKXBuURBXPU8d5XIC4G8nwg8X6cnDvwL+zBBlBbkg==
3304+
dependencies:
3305+
"@sentry/types" "6.2.0"
3306+
"@sentry/utils" "6.2.0"
3307+
tslib "^1.9.3"
3308+
3309+
"@sentry/[email protected]", "@sentry/minimal@^6.2.0":
3310+
version "6.2.0"
3311+
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.2.0.tgz#718b70babb55912eeb38babaf7823d1bcdd77d1e"
3312+
integrity sha512-haxsx8/ZafhZUaGeeMtY7bJt9HbDlqeiaXrRMp1CxGtd0ZRQwHt60imEjl6IH1I73SEWxNfqScGsX2s3HzztMg==
3313+
dependencies:
3314+
"@sentry/hub" "6.2.0"
3315+
"@sentry/types" "6.2.0"
3316+
tslib "^1.9.3"
3317+
3318+
"@sentry/node@^6.2.0":
3319+
version "6.2.0"
3320+
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.2.0.tgz#4c1860822a4a73d24242e5254124bd3bf9028d52"
3321+
integrity sha512-02lXk+56tPA3lWTvNLMGorp77wUVti8wOs+TlYARkJ+N+16dwqEBSBTy3hCDxlxriB+qHchSIS+ovPGi6WNiYA==
3322+
dependencies:
3323+
"@sentry/core" "6.2.0"
3324+
"@sentry/hub" "6.2.0"
3325+
"@sentry/tracing" "6.2.0"
3326+
"@sentry/types" "6.2.0"
3327+
"@sentry/utils" "6.2.0"
3328+
cookie "^0.4.1"
3329+
https-proxy-agent "^5.0.0"
3330+
lru_map "^0.3.3"
3331+
tslib "^1.9.3"
3332+
3333+
3334+
version "6.2.0"
3335+
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.2.0.tgz#76c17e5dd3f1e61c8a4e3bd090f904a63d674765"
3336+
integrity sha512-pzgM1dePPJysVnzaFCMp+BKtjM5q46HZeyShiR+KcQYvneD3fmUPJigDkkcsB2DcrY3mFvDcswjoqxaTIW7ZBQ==
3337+
dependencies:
3338+
"@sentry/hub" "6.2.0"
3339+
"@sentry/minimal" "6.2.0"
3340+
"@sentry/types" "6.2.0"
3341+
"@sentry/utils" "6.2.0"
3342+
tslib "^1.9.3"
3343+
3344+
"@sentry/[email protected]", "@sentry/types@^6.2.0":
3345+
version "6.2.0"
3346+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.2.0.tgz#ca020ff42913c6b9f88a9d0c375b5ee3965a2590"
3347+
integrity sha512-vN4P/a+QqAuVfWFB9G3nQ7d6bgnM9jd/RLVi49owMuqvM24pv5mTQHUk2Hk4S3k7ConrHFl69E7xH6Dv5VpQnQ==
3348+
3349+
3350+
version "6.2.0"
3351+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.2.0.tgz#39c81ad5ba92cec54d690e3fa8ea4e777d8e9c2b"
3352+
integrity sha512-YToUC7xYf2E/pIluI7upYTlj8fKXOtdwoOBkcQZifHgX/dP+qDaHibbBFe5PyZwdmU2UiLnWFsBr0gjo0QFo1g==
3353+
dependencies:
3354+
"@sentry/types" "6.2.0"
3355+
tslib "^1.9.3"
3356+
32793357
"@simple-dom/interface@^1.4.0":
32803358
version "1.4.0"
32813359
resolved "https://registry.yarnpkg.com/@simple-dom/interface/-/interface-1.4.0.tgz#e8feea579232017f89b0138e2726facda6fbb71f"

0 commit comments

Comments
 (0)