From 5ba24a029cd3b7d71496f1b232e77b480842e959 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Mon, 14 Sep 2026 13:08:15 +0200 Subject: [PATCH] docs(nestjs): Fix the verify snippet that exits the app and the start command Two snippets a new user hits between install and the first event. The tracing verify snippet threw inside `setTimeout(..., 99)`, so the route answered 200 and sent the span, and the throw then fired outside the Nest pipeline. It was captured as `auto.node.onuncaughtexception` and the process exited, leaving the app dead after a single request. Throw synchronously inside the span callback instead, and return it, so Nest handles the error and the span stays part of the request's trace. The snippet showed no controller and no `Sentry` import either, so it now shows both. Rename the span to "My First Test Span", since a span inside the request trace is what arrives. The ESM start command was a package.json fragment that runs nowhere: `"start": "--import ./instrument.mjs nest start"` names no `node` binary and fails with `sh: --: invalid option`. Lead with `NODE_OPTIONS`, which reaches the process that ends up running the app, so `nest start` keeps working. Replace the `npm run start` variant below it with the direct `node --import ./instrument.mjs dist/main.js`, for running the build output. Refs SDK-1499 Co-Authored-By: Claude Opus 5 --- .../javascript/guides/nestjs/install/esm.mdx | 8 ++--- .../javascript.nestjs.mdx | 32 +++++++++++-------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/platforms/javascript/guides/nestjs/install/esm.mdx b/docs/platforms/javascript/guides/nestjs/install/esm.mdx index 9ba9ba454e9a06..7a8297bd044044 100644 --- a/docs/platforms/javascript/guides/nestjs/install/esm.mdx +++ b/docs/platforms/javascript/guides/nestjs/install/esm.mdx @@ -28,17 +28,17 @@ Sentry.init({ }); ``` -**Step 2:** Adjust your application's start command to use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter: +**Step 2:** Load `instrument.mjs` with the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter when your application starts. Set it through `NODE_OPTIONS`, which applies to the Node.js process that runs your app: ```bash # Note: This is only available for Node v18.19.0 onwards. -"start": "--import ./instrument.mjs nest start" +NODE_OPTIONS="--import ./instrument.mjs" nest start ``` -If you can't pass the `--import` flag to the Node.js binary, you can alternatively use the `NODE_OPTIONS` environment variable as follows: +If you run your build output directly, pass the flag to `node` instead: ```bash -NODE_OPTIONS="--import ./instrument.mjs" npm run start +node --import ./instrument.mjs dist/main.js ``` We do not support ESM in Node versions before 18.19.0. diff --git a/platform-includes/getting-started-verify/javascript.nestjs.mdx b/platform-includes/getting-started-verify/javascript.nestjs.mdx index a8e42429fd124f..0bfc2204712701 100644 --- a/platform-includes/getting-started-verify/javascript.nestjs.mdx +++ b/platform-includes/getting-started-verify/javascript.nestjs.mdx @@ -27,25 +27,29 @@ First, let's verify that Sentry captures errors and creates issues in your Sentr -To test your tracing configuration, update the previous code snippet by starting a performance trace to measure the time it takes for the execution of your code. +To test your tracing configuration, update the previous code snippet to start a span around the error. The span is recorded as part of the request's trace. -```javascript -@Get("/debug-sentry") +```javascript {filename:app.controller.ts} +import { Controller, Get } from "@nestjs/common"; +import * as Sentry from "@sentry/nestjs"; + +@Controller() +export class AppController { + @Get("/debug-sentry") getError() { - Sentry.startSpan( - { - op: "test", - name: "My First Test Transaction", - }, - () => { - setTimeout(() => { - throw new Error("My first Sentry error!"); - }, 99); - }, - ); + return Sentry.startSpan( + { + op: "test", + name: "My First Test Span", + }, + () => { + throw new Error("My first Sentry error!"); + } + ); + } } ```