Merged
Conversation
[Gitflow] Merge master into develop
Noticed we forgot to set this.
…12203) The action sets up node 18 currently anyway, this doesn't seem to have any effect.
Based on the great feedback in #12191, this does some small adjustments to ensure that you actually can use the Node SDK properly with a custom OTEL setup: ## 1. Ensure we do not run `validateOpenTelemetrySetup()` when `skipOpenTelemetrySetup` is configured. Today, this is impossible to fix because you need a client to create the sampler, and you need the sampler to satisfy the validation, but the validation runs in `init()`. So either you call init() before doing your manual setup, which means you get the warning, or you do the manual setup first, but then you can't actually add the sampler, and still get the warning. This change means that users that configure `skipOpenTelemetrySetup` can manually call `Sentry.validateOpenTelemetrySetup()` if they want to get the validation, else there will be no validation automtically. ## 2. Export `SentryContextManager` from `@sentry/node` This is easier to use than to use the primitive `wrapContextManagerClass` from `@sentry/opentelemetry`. ## 3. Ensure we always run `setupEventContextTrace`, not tied to `skipOpenTelemetrySetup` There is no reason to tie this together, this now just always runs in `init()` - it's just an event processor!
This allows to pass a custom scope to `Sentry.captureFeedback()`, like
this:
```js
Sentry.captureFeedback({message : 'test' }, {}, scope);
```
This should fix the use case from
#11072 (comment)
Add a new `Sentry.startNewTrace` function that allows users to start a trace in isolation of a potentially still active trace. When this function is called, a new trace will be started on a forked scope which remains valid throughout the callback lifetime.
This PR adds a new way to initialize `@sentry/node`, which allows to use
the SDK with performance instrumentation even if you cannot (for
whatever reason) call `Sentry.init()` at the very start of your app.
## CJS usage
In CommonJS mode, you can run the SDK like this:
```bash
node --require @sentry/node/preload ./app.js
```
```js
// app.js
const express = require('express');
const Sentry = require('@sentry/node');
const dsn = await getSentryDsn();
Sentry.init({ dsn });
// express is instrumented even though we initialized Sentry late
```
## ESM usage
in ESM mode, you can run the SDK like this:
```bash
node --import @sentry/node/preload ./app.mjs
```
```js
// app.mjs
import express from 'express';
import * as Sentry from '@sentry/node';
const dsn = await getSentryDsn();
Sentry.init({ dsn });
// express is instrumented even though we initialized Sentry late
```
## Configuration options
This script will by default preload all opentelemetry instrumentation.
You can choose to instrument only specific packages like this:
```bash
SENTRY_PRELOAD_INTEGRATIONS="Http,Express,Graphql" --import @sentry/node/preload ./app.mjs
```
You can also enable debug logging for the script via
`SENTRY_DEBUG=true`.
## Manually preloading
It is also possible to manually call `preloadOpenTelemetry()` to achieve
the same thing. For example, in a CJS app you could do the following
thing if you want to initialize late but don't want to use `--require`:
```js
// preload.js
const Sentry = require('@sentry/node');
Sentry.preloadOpenTelemetry();
// app.js
// call this first, before any other requires!
require('./preload.js');
// Then, other stuff
const express = require('express');
const Sentry = require('@sentry/node');
const dsn = await getSentryDsn();
Sentry.init({ dsn });
```
#11979) Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
We had no entry covering the bundle size of metrics so far.
…mbdas (#12133) Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
…bda layer bundle (#12232) FIx one of the two issues that currently cause our lambda layer to break. When we build the lambda layer bundle we applied minification via our terser plugin which mangles `_`-prefixed private variables - like `Module._resolveFilename`. This patch adds the method to the list of excluded `_`-prefixed symbols.
Closes #12223 I've added a test that uses `import-in-the-middle` to throw if `inspector` is imported without enabling the `LocalVariables` integration so this should not regress in the future. Note that we don't need to import asynchronously in the worker scripts since these are not evaluated if the features aren't used.
…ddle` (#12233) Our lambda layer relies on one bundled Sentry SDK, which caused problems raised in #12089 and #12009 (comment). Specifically, by bundling `import-in-the-middle` code into one file, it seems like the library's way of declaring its exports conflict, causing the "ImportInTheMiddle is not a constructor" error to be thrown. While this should ideally be fixed soon in `import-in-the-middle`, for now this patch adds a small Rollup plugin to transform `new ImportInTheMiddle(...)` calls to `new ImportInTheMiddle.default(...)` to our AWS Lambda Layer bundle config.
Make our check for when we abort and log an error due to `Sentry.init` being used in a browser extension a bit more fine-gained. In particular, we now do not abort the SDK initialization if we detect that the SDK is running in a browser-extension dedicated window (e.g. a URL starting with `chrome-extension://`).
Lms24
commented
May 27, 2024
CHANGELOG.md
Outdated
| ``` | ||
|
|
||
| For a detailed guide, head over to our | ||
| [Sentry Node SDK documentation](https://docs.sentry.io/platforms/javascript/guides/node/) |
Member
Author
There was a problem hiding this comment.
Docs aren't merged yet but we can edit the link in the GH release once they are merged
77d8f89 to
82728b0
Compare
Metrics are only included when performance is included, reducing the base bundle size. We always expose a shim so there is no API breakage, it just does nothing. I noticed this while working on #12226.
mydea
reviewed
May 27, 2024
| First, run the SDK like this: | ||
|
|
||
| ```bash | ||
| node --require @sentry/node/preload ./app.js |
Member
There was a problem hiding this comment.
Suggested change
| node --require @sentry/node/preload ./app.js | |
| node --import @sentry/node/preload ./app.mjs |
not 100% sure, should we use the cjs or esm example here? 🤔
Member
There was a problem hiding this comment.
I guess CJS is probably fine, thinking about this... so disregard this comment I guess!
Member
Author
There was a problem hiding this comment.
Yeah I asked myself the same thing 😅 I guess CJS is still used more frequently so... 🤷
Basically I wanted to add a small snippet to show the use case but not copy the entire PR description.
mydea
approved these changes
May 27, 2024
82728b0 to
5ff736c
Compare
5ff736c to
f32f88d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.