Skip to content

ref: Move node & node-experimental folders #11309

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 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion packages/nextjs/test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"resolutions": {
"@sentry/browser": "file:../../../browser",
"@sentry/core": "file:../../../core",
"@sentry/node": "file:../../../node-experimental",
"@sentry/node": "file:../../../node",
"@sentry/opentelemetry": "file:../../../opentelemetry",
"@sentry/react": "file:../../../react",
"@sentry-internal/replay": "file:../../../replay-internal",
Expand Down
2 changes: 1 addition & 1 deletion packages/node-experimental/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 Sentry (https://sentry.io) and individual contributors. All rights reserved.
Copyright (c) 2019 Sentry (https://sentry.io) and individual contributors. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down
79 changes: 44 additions & 35 deletions packages/node-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,65 @@
</a>
</p>

# Official Sentry SDK for Node
# Legacy Sentry SDK for NodeJS

[![npm version](https://img.shields.io/npm/v/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
[![npm dm](https://img.shields.io/npm/dm/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
[![npm dt](https://img.shields.io/npm/dt/@sentry/node.svg)](https://www.npmjs.com/package/@sentry/node)
[![npm version](https://img.shields.io/npm/v/@sentry/node-experimental.svg)](https://www.npmjs.com/package/@sentry/node-experimental)
[![npm dm](https://img.shields.io/npm/dm/@sentry/node-experimental.svg)](https://www.npmjs.com/package/@sentry/node-experimental)
[![npm dt](https://img.shields.io/npm/dt/@sentry/node-experimental.svg)](https://www.npmjs.com/package/@sentry/node-experimental)

## Installation
## Links

```bash
npm install @sentry/node
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)

# Or yarn
yarn add @sentry/node
```
## Status

Since v8, this is the _legacy_ SDK, and it will most likely be completely removed before v8 is fully stable. It only
exists so that Meta-SDKs like `@sentry/nextjs` or `@sentry/sveltekit` can be migrated to the new `@sentry/node`
step-by-step.

You should instead use [@sentry/node](./../node-experimental/).

## Usage

```js
// CJS Syntax
const Sentry = require('@sentry/node');
// ESM Syntax
import * as Sentry from '@sentry/node';
To use this SDK, call `init(options)` as early as possible in the main entry module. This will initialize the SDK and
hook into the environment. Note that you can turn off almost all side effects using the respective options. Minimum
supported Node version is Node 14.

```javascript
// CJS syntax
const Sentry = require('@sentry/node-experimental');
// ESM syntax
import * as Sentry from '@sentry/node-experimental';

Sentry.init({
dsn: '__DSN__',
// ...
});
```

Note that it is necessary to initialize Sentry **before you import any package that may be instrumented by us**.

[More information on how to set up Sentry for Node in v8.](./../../docs/v8-node.md)
To set context information or send manual events, use the exported functions of `@sentry/node-experimental`. Note that
these functions will not perform any action before you have called `init()`:

### ESM Support
```javascript
// Set user information, as well as tags and further extras
Sentry.setExtra('battery', 0.7);
Sentry.setTag('user_mode', 'admin');
Sentry.setUser({ id: '4711' });

Due to the way OpenTelemetry handles instrumentation, this only works out of the box for CommonJS (`require`)
applications.

There is experimental support for running OpenTelemetry with ESM (`"type": "module"`):
// Add a breadcrumb for future events
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
// ...
});

```bash
node --experimental-loader=@opentelemetry/instrumentation/hook.mjs ./app.js
// Capture exceptions, messages or manual events
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
// ...
],
});
```

You'll need to install `@opentelemetry/instrumentation` in your app to ensure this works.

See
[OpenTelemetry Instrumentation Docs](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation#instrumentation-for-es-modules-in-nodejs-experimental)
for details on this - but note that this is a) experimental, and b) does not work with all integrations.

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
51 changes: 22 additions & 29 deletions packages/node-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sentry/node",
"name": "@sentry/node-experimental",
"version": "8.0.0-alpha.5",
"description": "Sentry Node SDK using OpenTelemetry for performance instrumentation",
"description": "The old version of Sentry SDK for Node.js, without OpenTelemetry support.",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/node-experimental",
"author": "Sentry",
Expand Down Expand Up @@ -42,39 +42,22 @@
"access": "public"
},
"dependencies": {
"@opentelemetry/api": "1.7.0",
"@opentelemetry/context-async-hooks": "1.21.0",
"@opentelemetry/core": "1.21.0",
"@opentelemetry/instrumentation": "0.48.0",
"@opentelemetry/instrumentation-express": "0.35.0",
"@opentelemetry/instrumentation-fastify": "0.33.0",
"@opentelemetry/instrumentation-graphql": "0.37.0",
"@opentelemetry/instrumentation-hapi": "0.34.0",
"@opentelemetry/instrumentation-http": "0.48.0",
"@opentelemetry/instrumentation-koa": "0.37.0",
"@opentelemetry/instrumentation-mongodb": "0.39.0",
"@opentelemetry/instrumentation-mongoose": "0.35.0",
"@opentelemetry/instrumentation-mysql": "0.35.0",
"@opentelemetry/instrumentation-mysql2": "0.35.0",
"@opentelemetry/instrumentation-nestjs-core": "0.34.0",
"@opentelemetry/instrumentation-pg": "0.38.0",
"@opentelemetry/resources": "1.21.0",
"@opentelemetry/sdk-trace-base": "1.21.0",
"@opentelemetry/semantic-conventions": "1.21.0",
"@prisma/instrumentation": "5.9.0",
"@sentry-internal/tracing": "8.0.0-alpha.5",
"@sentry/core": "8.0.0-alpha.5",
"@sentry/opentelemetry": "8.0.0-alpha.5",
"@sentry/types": "8.0.0-alpha.5",
"@sentry/utils": "8.0.0-alpha.5"
},
"devDependencies": {
"@types/node": "^14.18.0"
},
"optionalDependencies": {
"opentelemetry-instrumentation-fetch-node": "1.1.2"
"@types/cookie": "0.5.2",
"@types/express": "^4.17.14",
"@types/lru-cache": "^5.1.0",
"@types/node": "14.18.63",
"express": "^4.17.1",
"nock": "^13.0.5",
"undici": "^5.21.0"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build": "run-s build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core build:types:downlevel",
Expand All @@ -89,13 +72,23 @@
"clean": "rimraf build coverage sentry-node-experimental-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "yarn test:jest",
"test": "run-s test:jest test:express test:webpack test:release-health",
"test:express": "node test/manual/express-scope-separation/start.js",
"test:jest": "jest",
"test:release-health": "node test/manual/release-health/runner.js",
"test:webpack": "cd test/manual/webpack-async-context/ && yarn --silent --ignore-engines && node npm-build.js",
"test:watch": "jest --watch",
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"madge": {
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
},
"sideEffects": false
}
55 changes: 29 additions & 26 deletions packages/node-experimental/rollup.anr-worker.config.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { makeBaseBundleConfig } from '@sentry-internal/rollup-utils';

export function createAnrWorkerCode() {
let base64Code;

return {
workerRollupConfig: makeBaseBundleConfig({
bundleType: 'node-worker',
entrypoints: ['src/integrations/anr/worker.ts'],
licenseTitle: '@sentry/node',
outputFileBase: () => 'worker-script.js',
packageSpecificConfig: {
output: {
dir: 'build/esm/integrations/anr',
sourcemap: false,
},
plugins: [
{
name: 'output-base64-worker-script',
renderChunk(code) {
base64Code = Buffer.from(code).toString('base64');
},
},
],
function createAnrWorkerConfig(destDir, esm) {
return makeBaseBundleConfig({
bundleType: 'node-worker',
entrypoints: ['src/integrations/anr/worker.ts'],
licenseTitle: '@sentry/node',
outputFileBase: () => 'worker-script.js',
packageSpecificConfig: {
output: {
dir: destDir,
sourcemap: false,
},
}),
getBase64Code() {
return base64Code;
plugins: [
{
name: 'output-base64-worker-script',
renderChunk(code) {
const base64Code = Buffer.from(code).toString('base64');
if (esm) {
return `export const base64WorkerScript = '${base64Code}';`;
} else {
return `exports.base64WorkerScript = '${base64Code}';`;
}
},
},
],
},
};
});
}

export const anrWorkerConfigs = [
createAnrWorkerConfig('build/esm/integrations/anr', true),
createAnrWorkerConfig('build/cjs/integrations/anr', false),
];
32 changes: 4 additions & 28 deletions packages/node-experimental/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
import replace from '@rollup/plugin-replace';
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
import { createAnrWorkerCode } from './rollup.anr-worker.config.mjs';

const { workerRollupConfig, getBase64Code } = createAnrWorkerCode();
import { anrWorkerConfigs } from './rollup.anr-worker.config.mjs';

export default [
// The worker needs to be built first since it's output is used in the main bundle.
workerRollupConfig,
...makeNPMConfigVariants(
makeBaseNPMConfig({
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
exports: 'named',
// set preserveModules to false because we want to bundle everything into one file.
preserveModules: false,
},
plugins: [
replace({
delimiters: ['###', '###'],
// removes some webpack warnings
preventAssignment: true,
values: {
base64WorkerScript: () => getBase64Code(),
},
}),
],
},
}),
),
...makeNPMConfigVariants(makeBaseNPMConfig()),
// The ANR worker builds must come after the main build because they overwrite the worker-script.js file
...anrWorkerConfigs,
];
File renamed without changes.
Loading