Skip to content

Revert "ref: Move node & node-experimental folders" #11318

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 1 commit 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",
"@sentry/node": "file:../../../node-experimental",
"@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) 2019 Sentry (https://sentry.io) and individual contributors. All rights reserved.
Copyright (c) 2023 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: 35 additions & 44 deletions packages/node-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,56 @@
</a>
</p>

# Legacy Sentry SDK for NodeJS
# Official Sentry SDK for 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)
[![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)

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
## Installation

## Status
```bash
npm install @sentry/node

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/).
# Or yarn
yarn add @sentry/node
```

## Usage

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';
```js
// CJS Syntax
const Sentry = require('@sentry/node');
// ESM Syntax
import * as Sentry from '@sentry/node';

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

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()`:
Note that it is necessary to initialize Sentry **before you import any package that may be instrumented by us**.

```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' });
[More information on how to set up Sentry for Node in v8.](./../../docs/v8-node.md)

// Add a breadcrumb for future events
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
// ...
});
### ESM Support

// Capture exceptions, messages or manual events
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
// ...
],
});
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"`):

```bash
node --experimental-loader=@opentelemetry/instrumentation/hook.mjs ./app.js
```

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: 29 additions & 22 deletions packages/node-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sentry/node-experimental",
"name": "@sentry/node",
"version": "8.0.0-alpha.5",
"description": "The old version of Sentry SDK for Node.js, without OpenTelemetry support.",
"description": "Sentry Node SDK using OpenTelemetry for performance instrumentation",
"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,22 +42,39 @@
"access": "public"
},
"dependencies": {
"@sentry-internal/tracing": "8.0.0-alpha.5",
"@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/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/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"
"@types/node": "^14.18.0"
},
"optionalDependencies": {
"opentelemetry-instrumentation-fetch-node": "1.1.2"
},
"scripts": {
"build": "run-s build:transpile build:types",
"build": "run-p 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 @@ -72,23 +89,13 @@
"clean": "rimraf build coverage sentry-node-experimental-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "run-s test:jest test:express test:webpack test:release-health",
"test:express": "node test/manual/express-scope-separation/start.js",
"test": "yarn test:jest",
"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: 26 additions & 29 deletions packages/node-experimental/rollup.anr-worker.config.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import { makeBaseBundleConfig } from '@sentry-internal/rollup-utils';

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,
},
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 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');
},
},
],
},
}),
getBase64Code() {
return base64Code;
},
});
};
}

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

const { workerRollupConfig, getBase64Code } = createAnrWorkerCode();

export default [
...makeNPMConfigVariants(makeBaseNPMConfig()),
// The ANR worker builds must come after the main build because they overwrite the worker-script.js file
...anrWorkerConfigs,
// 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(),
},
}),
],
},
}),
),
];
Loading