Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs doc: add clarification to node.js getting started #4191

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

maryliag
Copy link
Contributor

@maryliag maryliag commented Mar 21, 2024

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.<anonymous> (/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.<computed> [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.<anonymous> (/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.<computed> [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.<anonymous> (/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.<computed> [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.

Run the instrumented app after the change:
Screenshot 2024-03-21 at 1 53 30 PM

@maryliag maryliag requested review from a team March 21, 2024 18:01
@maryliag maryliag changed the title nodejs doc: add clarifycation to node.js getting started nodejs doc: add clarification to node.js getting started Mar 21, 2024
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.<anonymous> (/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.<computed> [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.<anonymous> (/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.<computed> [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.<anonymous> (/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.<computed> [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.
@cartermp
Copy link
Contributor

/fix:format

Copy link
Contributor

@cartermp cartermp merged commit 9ed7b43 into open-telemetry:main Mar 22, 2024
5 checks passed
@maryliag maryliag deleted the node-doc branch March 22, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants