Skip to content

Commit

Permalink
feat(node-experimental): Add @sentry/node-experimental package as M…
Browse files Browse the repository at this point in the history
…VP for POTEL (#8609)

This introduces a new package `@sentry/node-experimental`, which is an
MVP implementation for Performance powered by OTEL (POTEL).

This package provides a wrapper over `@sentry/node` (also using
`@sentry/opentelemetry-node`) which uses opentelemetry for performance
instrumentation under the hood.

This is all abstracted away from the user, they only need to do:

```js
import * as Sentry from '@sentry/node-experimental';

Sentry.init({
  dsn: 'my-dsn',
  tracesSampleRate: 0.1
});
```

And it will set up all the necessary integrations etc. for the user,
including the default integrations + any applying performance
integrations.

For this, I added all performance integrations that exist for node,
minus undici (which will take some more work to get going), plus some
new stuff: mysql, fastify, nest. Also, mongoose is it's own integration
now, not handled via mongo anymore.

Note that I've only manually tested express & http so far. All others
still need to be verified etc. But this is really a POC, which may go
somewhere or not - by publishing this, it becomes super easy to try this
in various scenarios.

I have tweaked the Http integration to create more or less the same
output as we're used to for Sentry. I also made small tweaks to
`@sentry/opentelemetry-node` to allow us to communicate with this a bit
better. There are two main use cases I've identified there:

* Tell the span processor to drop a span (=not send it to Sentry). For
this, I added dedicated hooks.
* Add some specific data/context/tags/metadata to an otel span, that
should be added to the resulting sentry span. For this, I added utils
which keep a map of data to be added in `spanEnd`.

---------

Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
  • Loading branch information
mydea and Lms24 committed Jul 31, 2023
1 parent 540adac commit a858a07
Show file tree
Hide file tree
Showing 47 changed files with 1,729 additions and 107 deletions.
59 changes: 32 additions & 27 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,102 +6,107 @@ targets:
## 1. Base Packages, node or browser SDKs depend on
## 1.1 Types
- name: npm
id: "@sentry/types"
id: '@sentry/types'
includeNames: /^sentry-types-\d.*\.tgz$/
## 1.2 Utils
- name: npm
id: "@sentry/utils"
id: '@sentry/utils'
includeNames: /^sentry-utils-\d.*\.tgz$/
## 1.3 Core SDK
- name: npm
id: "@sentry/core"
id: '@sentry/core'
includeNames: /^sentry-core-\d.*\.tgz$/
## 1.4 Tracing package
- name: npm
id: "@sentry-internal/tracing"
id: '@sentry-internal/tracing'
includeNames: /^sentry-internal-tracing-\d.*\.tgz$/
## 1.5 Replay package (browser only)
- name: npm
id: "@sentry/replay"
id: '@sentry/replay'
includeNames: /^sentry-replay-\d.*\.tgz$/

## 2. Browser & Node SDKs
- name: npm
id: "@sentry/browser"
id: '@sentry/browser'
includeNames: /^sentry-browser-\d.*\.tgz$/
- name: npm
id: "@sentry/node"
id: '@sentry/node'
includeNames: /^sentry-node-\d.*\.tgz$/

## 3 Browser-based Packages
- name: npm
id: "@sentry/angular-ivy"
id: '@sentry/angular-ivy'
includeNames: /^sentry-angular-ivy-\d.*\.tgz$/
- name: npm
id: "@sentry/angular"
id: '@sentry/angular'
includeNames: /^sentry-angular-\d.*\.tgz$/
- name: npm
id: "@sentry/ember"
id: '@sentry/ember'
includeNames: /^sentry-ember-\d.*\.tgz$/
- name: npm
id: "@sentry/react"
id: '@sentry/react'
includeNames: /^sentry-react-\d.*\.tgz$/
- name: npm
id: "@sentry/svelte"
id: '@sentry/svelte'
includeNames: /^sentry-svelte-\d.*\.tgz$/
- name: npm
id: "@sentry/vue"
id: '@sentry/vue'
includeNames: /^sentry-vue-\d.*\.tgz$/
- name: npm
id: "@sentry/wasm"
id: '@sentry/wasm'
includeNames: /^sentry-wasm-\d.*\.tgz$/
- name: npm
id: "@sentry/integrations"
id: '@sentry/integrations'
includeNames: /^sentry-integrations-\d.*\.tgz$/

## 4. Node-based Packages
- name: npm
id: "@sentry/serverless"
id: '@sentry/serverless'
includeNames: /^sentry-serverless-\d.*\.tgz$/
- name: npm
id: "@sentry/opentelemetry-node"
id: '@sentry/opentelemetry-node'
includeNames: /^sentry-opentelemetry-node-\d.*\.tgz$/

## 5. Fullstack/Meta Frameworks (depending on Node and Browser or Framework SDKs)
- name: npm
id: "@sentry/nextjs"
id: '@sentry/nextjs'
includeNames: /^sentry-nextjs-\d.*\.tgz$/
- name: npm
id: "@sentry/remix"
id: '@sentry/remix'
includeNames: /^sentry-remix-\d.*\.tgz$/
- name: npm
id: "@sentry/sveltekit"
id: '@sentry/sveltekit'
includeNames: /^sentry-sveltekit-\d.*\.tgz$/
- name: npm
id: "@sentry/gatsby"
id: '@sentry/gatsby'
includeNames: /^sentry-gatsby-\d.*\.tgz$/

## 6. Other Packages
## 6.1
- name: npm
id: "@sentry-internal/typescript"
id: '@sentry-internal/typescript'
includeNames: /^sentry-internal-typescript-\d.*\.tgz$/
- name: npm
id: "@sentry-internal/eslint-plugin-sdk"
id: '@sentry-internal/eslint-plugin-sdk'
includeNames: /^sentry-internal-eslint-plugin-sdk-\d.*\.tgz$/
## 6.2
- name: npm
id: "@sentry-internal/eslint-config-sdk"
id: '@sentry-internal/eslint-config-sdk'
includeNames: /^sentry-internal-eslint-config-sdk-\d.*\.tgz$/

## 7. Deprecated packages we still release (but no packages depend on them anymore)
- name: npm
id: "@sentry/hub"
id: '@sentry/hub'
includeNames: /^sentry-hub-\d.*\.tgz$/
- name: npm
id: "@sentry/tracing"
id: '@sentry/tracing'
includeNames: /^sentry-tracing-\d.*\.tgz$/

## 8. Experimental packages
- name: npm
id: '@sentry/node-experimental'
includeNames: /^sentry-node-experimental-\d.*\.tgz$/

# AWS Lambda Layer target
- name: aws-lambda-layer
includeNames: /^sentry-node-serverless-\d+.\d+.\d+(-(beta|alpha)\.\d+)?\.zip$/
Expand All @@ -118,7 +123,7 @@ targets:

# CDN Bundle Target
- name: gcs
id: "browser-cdn-bundles"
id: 'browser-cdn-bundles'
includeNames: /.*\.js.*$/
bucket: sentry-js-sdk
paths:
Expand Down
2 changes: 1 addition & 1 deletion docs/new-sdk-release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ When you’re ready to make the first release, there are a couple of steps that
- [ ] 3) Add an `npm` target in `craft.yml` for the new package. Make sure to insert it in the right place, after all the Sentry dependencies of your package but before packages that depend on your new package (if applicable).
```yml
- name: npm
id: npm:@sentry/[yourPackage]
id: '@sentry/[yourPackage]'
includeNames: /^sentry-[yourPackage]-\d.*\.tgz$/
```
- [ ] 4) Cut a new release (as usual, see [Publishing Release](https://github.com/getsentry/sentry-javascript/blob/develop/docs/publishing-a-release.md))
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"postpublish": "lerna run --stream --concurrency 1 postpublish",
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test",
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit",
"test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
"test-ci-browser": "lerna run test --ignore \"@sentry/{node,node-experimental,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
"test:update-snapshots": "lerna run test:update-snapshots",
"yalc:publish": "lerna run yalc:publish"
Expand All @@ -54,6 +54,7 @@
"packages/nextjs",
"packages/node",
"packages/node-integration-tests",
"packages/node-experimental",
"packages/opentelemetry-node",
"packages/react",
"packages/remix",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
/** @inheritdoc */
public on(hook: 'createDsc', callback: (dsc: DynamicSamplingContext) => void): void;

/** @inheritdoc */
public on(hook: 'otelSpanEnd', callback: (otelSpan: unknown, mutableOptions: { drop: boolean }) => void): void;

/** @inheritdoc */
public on(hook: string, callback: unknown): void {
if (!this._hooks[hook]) {
Expand All @@ -413,6 +416,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
/** @inheritdoc */
public emit(hook: 'createDsc', dsc: DynamicSamplingContext): void;

/** @inheritdoc */
public emit(hook: 'otelSpanEnd', otelSpan: unknown, mutableOptions: { drop: boolean }): void;

/** @inheritdoc */
public emit(hook: string, ...rest: unknown[]): void {
if (this._hooks[hook]) {
Expand Down
6 changes: 6 additions & 0 deletions packages/e2e-tests/verdaccio-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ packages:
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/node-experimental':
access: $all
publish: $all
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/opentelemetry-node':
access: $all
publish: $all
Expand Down
9 changes: 9 additions & 0 deletions packages/node-experimental/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
node: true,
},
extends: ['../../.eslintrc.js'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
},
};
14 changes: 14 additions & 0 deletions packages/node-experimental/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66 changes: 66 additions & 0 deletions packages/node-experimental/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Official Sentry SDK for Node (EXPERIMENTAL)

[![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)

This is a WIP, proof of concept implementation of a Node SDK that uses OpenTelemetry for performance instrumentation under the hood.

THIS MAY/WILL BREAK IN MANY UNEXPECTED WAYS. We may remove, add, change any of the integrations, add/remove any exports, etc.
This package is **NOT READY TO USE IN ANY FORM OF PRODUCTION ENVIRONMENT**!

This SDK is **considered experimental and in an alpha state**. It may experience breaking changes, and may be discontinued at any time. Please reach out on
[GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback/concerns.

## Installation

```bash
npm install @sentry/node-experimental

# Or yarn
yarn add @sentry/node-experimental
```

## Usage

```js
// ES5 Syntax
const Sentry = require('@sentry/node-experimental');
// ES6 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**.

## Available (Performance) Integrations

* Http
* Express
* Fastify
* Nest
* Mysql
* Mysql2
* GraphQL
* Mongo
* Mongoose
* Postgres
* Prisma

All of these are auto-discovered, you don't need to configure anything for performance.
You still need to register middlewares etc. for error capturing.
Other, non-performance integrations from `@sentry/node` are also available (except for Undici).

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
1 change: 1 addition & 0 deletions packages/node-experimental/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest/jest.config.js');
76 changes: 76 additions & 0 deletions packages/node-experimental/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@sentry/node-experimental",
"version": "7.60.0",
"description": "Experimental version of a 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",
"license": "MIT",
"engines": {
"node": ">=14"
},
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"typesVersions": {
"<4.9": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@opentelemetry/api": "~1.4.1",
"@opentelemetry/instrumentation": "~0.41.0",
"@opentelemetry/instrumentation-fastify": "~0.32.0",
"@opentelemetry/instrumentation-http": "~0.41.0",
"@opentelemetry/instrumentation-express": "~0.33.0",
"@opentelemetry/instrumentation-graphql": "~0.35.0",
"@opentelemetry/instrumentation-mongodb": "~0.36.0",
"@opentelemetry/instrumentation-mongoose": "~0.33.0",
"@opentelemetry/instrumentation-mysql": "~0.34.0",
"@opentelemetry/instrumentation-mysql2": "~0.34.0",
"@opentelemetry/instrumentation-pg": "~0.36.0",
"@opentelemetry/instrumentation-nestjs-core": "~0.33.0",
"@opentelemetry/semantic-conventions": "~1.15.0",
"@opentelemetry/sdk-trace-node": "~1.15.0",
"@prisma/instrumentation": "~5.0.0",
"@sentry/core": "7.60.0",
"@sentry/node": "7.60.0",
"@sentry/opentelemetry-node": "7.60.0",
"@sentry/types": "7.60.0",
"@sentry/utils": "7.60.0"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.js",
"build:types": "run-s build:types:core build:types:downlevel",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-node-experimental-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --format stylish",
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
"test": "yarn test:jest",
"test:jest": "jest",
"test:watch": "jest --watch",
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
3 changes: 3 additions & 0 deletions packages/node-experimental/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';

export default makeNPMConfigVariants(makeBaseNPMConfig());
13 changes: 13 additions & 0 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Integrations as CoreIntegrations } from '@sentry/core';

import * as NodeExperimentalIntegrations from './integrations';

const INTEGRATIONS = {
...CoreIntegrations,
...NodeExperimentalIntegrations,
};

export { init } from './sdk/init';
export { INTEGRATIONS as Integrations };
export { getAutoPerformanceIntegrations } from './integrations/getAutoPerformanceIntegrations';
export * as Handlers from './sdk/handlers';

0 comments on commit a858a07

Please sign in to comment.