Skip to content

feat: NextJS client and server sides #3277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
053e1ea
build: Install @sentry/browser, @sentry/node and @sentry/types
iker-barriocanal Feb 22, 2021
8357ff2
feat: Add `flush` and `close` functionality
iker-barriocanal Feb 22, 2021
56e6056
feat: Add NextJS options
iker-barriocanal Feb 22, 2021
a60448b
feat: Add init
iker-barriocanal Feb 22, 2021
9657701
feat: Add NextJS browser entry point and exports for @sentry/types an…
iker-barriocanal Feb 23, 2021
f62ecc7
feat: Add NextJS entry point
iker-barriocanal Feb 23, 2021
0a7e96b
ref: Extract dynamic module requiring
iker-barriocanal Feb 23, 2021
8931f67
build: Add dependencies and update `yarn.lock`
iker-barriocanal Feb 23, 2021
633a67a
feat: NextjsClient wrapper and interface
iker-barriocanal Feb 23, 2021
62ceb09
feat: Add browser client and backend
iker-barriocanal Feb 24, 2021
205c228
ref: Simplify approach with package.json
iker-barriocanal Feb 24, 2021
33f5a50
feat: Export @sentry/minimal
iker-barriocanal Feb 24, 2021
6273877
build: Remove @sentry/core and @sentry/utils from dependencies
iker-barriocanal Feb 24, 2021
57a7c94
docs: Add docs to browser and node inits
iker-barriocanal Feb 24, 2021
0d4c937
ref: Import only `init` from @sentry/browser and @sentry/node
iker-barriocanal Feb 24, 2021
949a5f4
build: Set exact versions for dependencies
iker-barriocanal Feb 24, 2021
0c75211
build: Update package version
iker-barriocanal Feb 24, 2021
8435adb
ref: Add MetadataBuilder and use it to build the metadata before SDKs…
iker-barriocanal Feb 24, 2021
241ee5a
fix: Include all used SDKs in the event payload
iker-barriocanal Feb 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/nextjs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ module.exports = {
],
rules: {
'max-lines': 'off',
'@sentry-internal/sdk/no-async-await': 'off',
'jsdoc/require-jsdoc': 0,
},
};
20 changes: 13 additions & 7 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/nextjs",
"version": "6.1.0",
"version": "6.2.0",
"description": "Official Sentry SDK for Next.js",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nextjs",
Expand All @@ -9,16 +9,22 @@
"engines": {
"node": ">=6"
},
"main": "dist/index.js",
"module": "esm/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.js",
"module": "./esm/node.js",
"browser": "./esm/browser.js",
"types": "./dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {},
"dependencies": {
"@sentry/browser": "6.2.0",
"@sentry/node": "6.2.0",
"@sentry/minimal": "6.2.0"
},
"devDependencies": {
"eslint": "^7.20.0",
"rimraf": "^3.0.2"
"@sentry/types": "6.2.0",
"eslint": "7.20.0",
"rimraf": "3.0.2"
},
"scripts": {
"build": "run-p build:es5 build:esm",
Expand Down
12 changes: 12 additions & 0 deletions packages/nextjs/src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { init as browserInit } from '@sentry/browser';

import { MetadataBuilder, NextjsOptions } from './options';

/** Inits the Sentry NextJS SDK on the browser. */
export function init(options: NextjsOptions): any {
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'browser']);
metadataBuilder.addSdkMetadata();
browserInit(options);
}

export * from '@sentry/minimal';
2 changes: 2 additions & 0 deletions packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { init } from './sdk';
export * from '@sentry/minimal';
12 changes: 12 additions & 0 deletions packages/nextjs/src/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { init as nodeInit } from '@sentry/node';

import { MetadataBuilder, NextjsOptions } from './options';

/** Inits the Sentry NextJS SDK on node. */
export function init(options: NextjsOptions): any {
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'node']);
metadataBuilder.addSdkMetadata();
nodeInit(options);
}

export * from '@sentry/minimal';
45 changes: 45 additions & 0 deletions packages/nextjs/src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BrowserOptions, SDK_VERSION } from '@sentry/browser';
import { NodeOptions } from '@sentry/node';
import { Options, Package, SdkInfo } from '@sentry/types';

const SDK_NAME = 'sentry.javascript.nextjs';
const PACKAGE_NAME_PREFIX = 'npm:@sentry/';

export interface NextjsOptions extends Options, BrowserOptions, NodeOptions {
// TODO: options for NextJS
}

/**
* A builder for the SDK metadata in the options for the SDK initialization.
*/
export class MetadataBuilder {
private _options: NextjsOptions;
private _packageNames: string[];

constructor(options: NextjsOptions, packages: string[]) {
this._options = options;
this._packageNames = packages;
}

public addSdkMetadata(): void {
this._options._metadata = this._options._metadata || {};
this._options._metadata.sdk = this._getSdkInfo();
}

private _getSdkInfo(): SdkInfo {
return {
name: SDK_NAME,
version: SDK_VERSION,
packages: this._getPackages(),
};
}

private _getPackages(): Package[] {
return this._packageNames.map((pkgName: string) => {
return {
name: PACKAGE_NAME_PREFIX + pkgName,
version: SDK_VERSION,
};
});
}
}
17 changes: 15 additions & 2 deletions packages/nextjs/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
// eslint-disable-next-line no-console
console.log('Sentaurs greet NextJS!');
import { init as browserInit } from '@sentry/browser';

import { MetadataBuilder, NextjsOptions } from './options';

/**
* The Sentry NextJS SDK Client.
*
* TODO: docs, examples...
*
*/
export function init(options: NextjsOptions): void {
const metadataBuilder = new MetadataBuilder(options, ['nextjs']);
metadataBuilder.addSdkMetadata();
browserInit(options);
}
78 changes: 78 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,84 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@sentry/browser@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.2.0.tgz#4113a92bc82f55e63f30cb16a94f717bd0b95817"
integrity sha512-4r3paHcHXLemj471BtNDhUs2kvJxk5XDRplz1dbC/LHXN5PWEXP4anhGILxOlxqi4y33r53PIZu3xXFjznaVZA==
dependencies:
"@sentry/core" "6.2.0"
"@sentry/types" "6.2.0"
"@sentry/utils" "6.2.0"
tslib "^1.9.3"

"@sentry/[email protected]":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.2.0.tgz#be1c33854fc94e1a4d867f7c2c311cf1cefb8ee9"
integrity sha512-oTr2b25l+0bv/+d6IgMamPuGleWV7OgJb0NFfd+WZhw6UDRgr7CdEJy2gW6tK8SerwXgPHdn4ervxsT3WIBiXw==
dependencies:
"@sentry/hub" "6.2.0"
"@sentry/minimal" "6.2.0"
"@sentry/types" "6.2.0"
"@sentry/utils" "6.2.0"
tslib "^1.9.3"

"@sentry/[email protected]":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.2.0.tgz#e7502652bc9608cf8fb63e43cd49df9019a28f29"
integrity sha512-BDTEFK8vlJydWXp/KMX0stvv73V7od224iLi+w3k7BcPwMKXBuURBXPU8d5XIC4G8nwg8X6cnDvwL+zBBlBbkg==
dependencies:
"@sentry/types" "6.2.0"
"@sentry/utils" "6.2.0"
tslib "^1.9.3"

"@sentry/[email protected]", "@sentry/minimal@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.2.0.tgz#718b70babb55912eeb38babaf7823d1bcdd77d1e"
integrity sha512-haxsx8/ZafhZUaGeeMtY7bJt9HbDlqeiaXrRMp1CxGtd0ZRQwHt60imEjl6IH1I73SEWxNfqScGsX2s3HzztMg==
dependencies:
"@sentry/hub" "6.2.0"
"@sentry/types" "6.2.0"
tslib "^1.9.3"

"@sentry/node@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.2.0.tgz#4c1860822a4a73d24242e5254124bd3bf9028d52"
integrity sha512-02lXk+56tPA3lWTvNLMGorp77wUVti8wOs+TlYARkJ+N+16dwqEBSBTy3hCDxlxriB+qHchSIS+ovPGi6WNiYA==
dependencies:
"@sentry/core" "6.2.0"
"@sentry/hub" "6.2.0"
"@sentry/tracing" "6.2.0"
"@sentry/types" "6.2.0"
"@sentry/utils" "6.2.0"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"

"@sentry/[email protected]":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.2.0.tgz#76c17e5dd3f1e61c8a4e3bd090f904a63d674765"
integrity sha512-pzgM1dePPJysVnzaFCMp+BKtjM5q46HZeyShiR+KcQYvneD3fmUPJigDkkcsB2DcrY3mFvDcswjoqxaTIW7ZBQ==
dependencies:
"@sentry/hub" "6.2.0"
"@sentry/minimal" "6.2.0"
"@sentry/types" "6.2.0"
"@sentry/utils" "6.2.0"
tslib "^1.9.3"

"@sentry/[email protected]", "@sentry/types@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.2.0.tgz#ca020ff42913c6b9f88a9d0c375b5ee3965a2590"
integrity sha512-vN4P/a+QqAuVfWFB9G3nQ7d6bgnM9jd/RLVi49owMuqvM24pv5mTQHUk2Hk4S3k7ConrHFl69E7xH6Dv5VpQnQ==

"@sentry/[email protected]":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.2.0.tgz#39c81ad5ba92cec54d690e3fa8ea4e777d8e9c2b"
integrity sha512-YToUC7xYf2E/pIluI7upYTlj8fKXOtdwoOBkcQZifHgX/dP+qDaHibbBFe5PyZwdmU2UiLnWFsBr0gjo0QFo1g==
dependencies:
"@sentry/types" "6.2.0"
tslib "^1.9.3"

"@simple-dom/interface@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@simple-dom/interface/-/interface-1.4.0.tgz#e8feea579232017f89b0138e2726facda6fbb71f"
Expand Down