Skip to content
Merged
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
4 changes: 2 additions & 2 deletions content/observability/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The two can be installed in the same application, but both hook the database dri

#### Zero-code setup

> info **Hint** Much of OpenTelemetry's Node.js documentation assumes the compiled application runs as CommonJS. Applications generated by `nest new` on Nest 12 are ES modules, which need an extra loader flag. Both variants are shown below.
> info **Hint** Much of OpenTelemetry's Node.js documentation assumes the compiled application runs as CommonJS. Applications generated by `nest new` on Nest 12 are ES modules, which need an extra loader flag. Both variants are shown below. On Nest 12 a CommonJS build needs that flag too, because the `@nestjs/*` packages are ES modules and import Express themselves. Without it Express isn't instrumented and the HTTP span is named without its route.

The quickest way to get traces out of a Nest application is OpenTelemetry's zero-code instrumentation. Install the API and the auto-instrumentations bundle:

Expand Down Expand Up @@ -120,7 +120,7 @@ $ node --experimental-loader=@opentelemetry/instrumentation/hook.mjs \
--import ./dist/instrumentation.js dist/main.js
```

In a CommonJS build you can instead import the file on the very first line of `main.ts`, before `@nestjs/core` and your `AppModule`. In an ES module build that isn't enough, because the loader hook has to be registered on the command line.
In a CommonJS build you can instead import the file on the very first line of `main.ts`, before `@nestjs/core` and your `AppModule`. In an ES module build, and for Express on Nest 12, that isn't enough, because the loader hook has to be registered on the command line.

The SDK exports spans in batches. To send the last batch when the application stops, call `otelSdk.shutdown()` once Nest has finished shutting down, for example from an `onApplicationShutdown()` hook with [shutdown hooks](/fundamentals/lifecycle-events#application-shutdown) enabled.

Expand Down
Loading