Skip to content

Commit 5448d22

Browse files
JamieDanielsonotelbot[bot]vitorvasc
authored
Add clarification for otel-js apps written in CJS and ESM (open-telemetry#8666)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Vitor Vasconcellos <vitor.vasconcellos@mercadolivre.com> Co-authored-by: Vitor Vasconcellos <vvasconcellos1@gmail.com>
1 parent 1e4e400 commit 5448d22

8 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
---
3+
4+
> [!NOTE]
5+
>
6+
> The OpenTelemetry documentation assumes that the compiled application is run
7+
> as [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules).
8+
> If the application runs as ESM, add the loader hook as specified in the
9+
> [ESM Support Doc](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md).

content/en/docs/languages/js/getting-started/nodejs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ Listening for requests on http://localhost:8080
245245

246246
{{% /tab %}} {{< /tabpane >}}
247247

248+
(Note: If your application is written in JavaScript as ECMAScript Modules (ESM),
249+
or compiled to ESM from TypeScript, then a loader hook is required to properly
250+
support instrumentation. Use
251+
`node --experimental-loader=@opentelemetry/instrumentation/hook.mjs --require ./instrumentation.js app.js`.
252+
See
253+
[ESM support docs](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md)
254+
for details on ESM support in OpenTelemetry.)
255+
248256
Open <http://localhost:8080/rolldice> in your web browser and reload the page a
249257
few times. After a while you should see the spans printed in the console by the
250258
`ConsoleSpanExporter`.
@@ -553,5 +561,7 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
553561

554562
{{% /tab %}} {{< /tabpane >}}
555563

564+
{{% include esm-support-note.md %}}
565+
556566
[traces]: /docs/concepts/signals/traces/
557567
[metrics]: /docs/concepts/signals/metrics/

content/en/docs/languages/js/instrumentation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ about manual instrumentation.
3131
You don't have to use the example app: if you want to instrument your own app or
3232
library, follow the instructions here to adapt the process to your own code.
3333

34+
{{% include esm-support-note.md %}}
35+
3436
### Dependencies {#example-app-dependencies}
3537

3638
Create an empty NPM `package.json` file in a new directory:

content/en/docs/languages/js/libraries.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ For example,
1919
will automatically create [spans](/docs/concepts/signals/traces/#spans) based on
2020
the inbound HTTP requests.
2121

22+
{{% include esm-support-note.md %}}
23+
2224
### Setup
2325

2426
Each instrumentation library is an NPM package. For example, here’s how you can

content/en/docs/languages/js/propagation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ cSpell:ignore: rolldice
77

88
{{% docs/languages/propagation %}}
99

10+
{{% include esm-support-note.md %}}
11+
1012
## Automatic context propagation
1113

1214
[Instrumentation libraries](../libraries/) like

content/en/docs/languages/js/resources.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Follow the instructions in the [Getting Started - Node.js][], so that you have
1616
the files `package.json`, `app.js` (or `app.ts`) and `instrumentation.mjs` (or
1717
`instrumentation.ts`).
1818

19+
{{% include esm-support-note.md %}}
20+
1921
## Process & Environment Resource Detection
2022

2123
Out of the box, the Node.js SDK detects [process and process runtime

content/en/docs/languages/js/serverless.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ cSpell:ignore: otelwrapper
88
This guide shows how to get started with tracing serverless functions using
99
OpenTelemetry instrumentation libraries.
1010

11+
> [!NOTE]
12+
>
13+
> The OpenTelemetry documentation assume that the compiled application is run as
14+
> [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules).
15+
1116
## AWS Lambda
1217

1318
> [!NOTE]

static/refcache.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12627,6 +12627,10 @@
1262712627
"StatusCode": 206,
1262812628
"LastSeen": "2026-03-02T09:52:36.24661858Z"
1262912629
},
12630+
"https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md": {
12631+
"StatusCode": 206,
12632+
"LastSeen": "2026-03-17T09:57:57.21652344Z"
12633+
},
1263012634
"https://github.com/open-telemetry/opentelemetry-js/discussions": {
1263112635
"StatusCode": 206,
1263212636
"LastSeen": "2026-02-28T09:44:10.519724831Z"
@@ -18823,6 +18827,10 @@
1882318827
"StatusCode": 206,
1882418828
"LastSeen": "2026-03-02T09:58:08.183553018Z"
1882518829
},
18830+
"https://nodejs.org/api/modules.html#modules-commonjs-modules": {
18831+
"StatusCode": 206,
18832+
"LastSeen": "2025-12-18T11:01:15.225540416Z"
18833+
},
1882618834
"https://nodejs.org/api/perf_hooks.html": {
1882718835
"StatusCode": 206,
1882818836
"LastSeen": "2026-03-02T09:58:30.616931835Z"

0 commit comments

Comments
 (0)