From 87f9816587365c481149dd0c015f3867b39342df Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 21 Mar 2024 13:54:08 -0400 Subject: [PATCH 1/2] nodejs doc: add clarification to node.js getting started One common approach to register de API is to set the environment variable `NODE_OPTIONS` with `--require @opentelemetry/auto-instrumentations-node/register`, but if we follow the `Getting Started` for `Node.js`, the step to use `--require ./instrumentation.ts` on command line can cause a conflict, resulting on an error message similar to: ``` Error: @opentelemetry/api: Attempted duplicate registration of API: trace at registerGlobal (/Users/maryliag/development/otel/opentelemetry-js/api/src/internal/global-utils.ts:47:17) at TraceAPI.setGlobalTracerProvider (/Users/maryliag/development/otel/opentelemetry-js/api/src/api/trace.ts:67:35) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts:153:11) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-node/src/NodeTracerProvider.ts:68:11) at NodeSDK.start (/Users/maryliag/development/otel/opentelemetry-js/experimental/packages/opentelemetry-sdk-node/src/sdk.ts:355:20) at Object. (/Users/maryliag/development/otel/nodejs-test/instrumentation.ts:17:5) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module.m._compile (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Object.require.extensions. [as .ts] (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1621:12) Error: @opentelemetry/api: Attempted duplicate registration of API: context at registerGlobal (/Users/maryliag/development/otel/opentelemetry-js/api/src/internal/global-utils.ts:47:17) at ContextAPI.setGlobalContextManager (/Users/maryliag/development/otel/opentelemetry-js/api/src/api/context.ts:53:26) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts:159:15) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-node/src/NodeTracerProvider.ts:68:11) at NodeSDK.start (/Users/maryliag/development/otel/opentelemetry-js/experimental/packages/opentelemetry-sdk-node/src/sdk.ts:355:20) at Object. (/Users/maryliag/development/otel/nodejs-test/instrumentation.ts:17:5) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module.m._compile (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Object.require.extensions. [as .ts] (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1621:12) Error: @opentelemetry/api: Attempted duplicate registration of API: propagation at registerGlobal (/Users/maryliag/development/otel/opentelemetry-js/api/src/internal/global-utils.ts:47:17) at PropagationAPI.setGlobalPropagator (/Users/maryliag/development/otel/opentelemetry-js/api/src/api/propagation.ts:67:26) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts:163:19) at NodeTracerProvider.register (/Users/maryliag/development/otel/opentelemetry-js/packages/opentelemetry-sdk-trace-node/src/NodeTracerProvider.ts:68:11) at NodeSDK.start (/Users/maryliag/development/otel/opentelemetry-js/experimental/packages/opentelemetry-sdk-node/src/sdk.ts:355:20) at Object. (/Users/maryliag/development/otel/nodejs-test/instrumentation.ts:17:5) at Module._compile (node:internal/modules/cjs/loader:1378:14) at Module.m._compile (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1437:10) at Object.require.extensions. [as .ts] (/Users/maryliag/development/otel/nodejs-test/node_modules/ts-node/src/index.ts:1621:12) ``` It can be hard to identify the problem from the error message. So this commit adds a small warning to make sure the requirements are not conflicting. --- content/en/docs/languages/js/getting-started/nodejs.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/en/docs/languages/js/getting-started/nodejs.md b/content/en/docs/languages/js/getting-started/nodejs.md index e9deba0c3421..6ebebdb1ac9f 100644 --- a/content/en/docs/languages/js/getting-started/nodejs.md +++ b/content/en/docs/languages/js/getting-started/nodejs.md @@ -227,6 +227,9 @@ sdk.start(); Now you can run your application as you normally would, but you can use the `--require` flag to load the instrumentation before the application code. +Make sure you don't have other conflicting `--require` flags such as +`--require @opentelemetry/auto-instrumentations-node/register` on your `NODE_OPTIONS` +environment variable. {{< tabpane text=true >}} {{% tab TypeScript %}} From e1edb265801ef0a23a97d801c606832b467ba0e2 Mon Sep 17 00:00:00 2001 From: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Date: Fri, 22 Mar 2024 06:46:41 +0000 Subject: [PATCH 2/2] Results from /fix:format --- content/en/docs/languages/js/getting-started/nodejs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/en/docs/languages/js/getting-started/nodejs.md b/content/en/docs/languages/js/getting-started/nodejs.md index 6ebebdb1ac9f..156ccd08373d 100644 --- a/content/en/docs/languages/js/getting-started/nodejs.md +++ b/content/en/docs/languages/js/getting-started/nodejs.md @@ -226,10 +226,10 @@ sdk.start(); ## Run the instrumented app Now you can run your application as you normally would, but you can use the -`--require` flag to load the instrumentation before the application code. -Make sure you don't have other conflicting `--require` flags such as -`--require @opentelemetry/auto-instrumentations-node/register` on your `NODE_OPTIONS` -environment variable. +`--require` flag to load the instrumentation before the application code. Make +sure you don't have other conflicting `--require` flags such as +`--require @opentelemetry/auto-instrumentations-node/register` on your +`NODE_OPTIONS` environment variable. {{< tabpane text=true >}} {{% tab TypeScript %}}