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

update nodejs autoinstrumetation, fixes #2626 #3570

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ElfoLiNk
Copy link

Description:

Update nodejs autoinstrumentation like register.ts from auto-instrumentations-node metapackage

Link to tracking Issue(s):

Testing:

Not tested yet

Documentation:

@ElfoLiNk ElfoLiNk requested a review from a team as a code owner December 22, 2024 10:39
@swiatekm
Copy link
Contributor

@open-telemetry/javascript-approvers could you have a look? 🙏

@ElfoLiNk ElfoLiNk force-pushed the fix/update-nodejs-autoinstrumentation branch from 0b6b81c to cf4ab32 Compare December 30, 2024 17:20
@pavolloffay pavolloffay added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jan 7, 2025
@ElfoLiNk ElfoLiNk force-pushed the fix/update-nodejs-autoinstrumentation branch from a1389c9 to 04677de Compare January 7, 2025 09:19
@ElfoLiNk
Copy link
Author

ElfoLiNk commented Jan 7, 2025

Thank you @pavolloffay i fixed the build since getResourceDetectorsFromEnv is exported as getResourceDetectors

@pichlermarc
Copy link
Member

Actually, I think since metrics auto-configuration is now implemented, you may not even need the autoconfigure.ts file anymore. It just duplicates what's happening in @opentelemetry/auto-instrumentations-node/register now (the only difference being that the implementation from the upstream package does not throw when a non-existing exporter is selected)

@ElfoLiNk
Copy link
Author

ElfoLiNk commented Jan 7, 2025

Hi @pichlermarc, are you suggesting to remove autoinstrumentation.ts here and update the code in nodejs.go to something like:

nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"

Would this approach work when referenced like this? I haven’t tested it yet.

Thank you

PS @swiatekm, what’s your opinion on this?

@iblancasa
Copy link
Contributor

Hi @pichlermarc, are you suggesting to remove autoinstrumentation.ts here and update the code in nodejs.go to something like:

nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"

Would this approach work when referenced like this? I haven’t tested it yet.

Thank you

PS @swiatekm, what’s your opinion on this?
It makes sense to me

@pichlermarc
Copy link
Member

Hi @pichlermarc, are you suggesting to remove autoinstrumentation.ts here and update the code in nodejs.go to something like:

nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"

Something along these lines yes. I don't think you necessarily need to reference the full path - you may be able to just ref the entrypoint:

nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/register"

@ElfoLiNk ElfoLiNk force-pushed the fix/update-nodejs-autoinstrumentation branch from 710e87c to 8726e9e Compare January 14, 2025 17:12
@ElfoLiNk ElfoLiNk force-pushed the fix/update-nodejs-autoinstrumentation branch from 605e371 to c6ed877 Compare January 15, 2025 11:03
@swiatekm swiatekm requested a review from pavolloffay January 17, 2025 12:29
@swiatekm
Copy link
Contributor

@pavolloffay @pichlermarc could you re-review this (I assume) final state of the change?

@ElfoLiNk have you tested this with a real Node application? Our tests only check if the instrumented application starts, but not if it's actually emitting the right telemetry, so this should be verified manually with this kind of substantial change.

@swiatekm swiatekm requested a review from pichlermarc January 17, 2025 12:31
@@ -22,7 +22,7 @@ import (

const (
envNodeOptions = "NODE_OPTIONS"
nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js"
nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work? That's the entrypoint we provide for these kinds of things.

Suggested change
nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"
nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/register"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but i got

Error: Cannot find module '/otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/register'

@ElfoLiNk
Copy link
Author

ElfoLiNk commented Jan 18, 2025

@pavolloffay @pichlermarc could you re-review this (I assume) final state of the change?

@ElfoLiNk have you tested this with a real Node application? Our tests only check if the instrumented application starts, but not if it's actually emitting the right telemetry, so this should be verified manually with this kind of substantial change.

I tested today, and everything seems to be working:

OTEL_LOGS_EXPORTER is empty. Using default otlp exporter.
Unsupported OTLP metrics protocol: "undefined". Using http/protobuf.
OpenTelemetry automatic instrumentation started successfully

I was testing it with this configuration:

- name: OTEL_TRACES_EXPORTER
  value: "otlp"
- name: OTEL_METRICS_EXPORTER
   value: "otlp"
- name: OTEL_NODE_RESOURCE_DETECTORS
   value: "env,os,process,container"

The exporter endpoint was set to port 4317.

The only issue I encountered was with the metrics exporter:

Error: PeriodicExportingMetricReader: metrics export failed (error Error: Parse Error: Expected HTTP/)

To resolve this, I explicitly added OTEL_EXPORTER_OTLP_PROTOCOL to the instrumentation configuration, which resolved the issue.

Additionally, both the operator and instrumentation Docker images need to be updated simultaneously. If you update only the instrumentation, you encounter the following error:

Error: Cannot find module '/otel-auto-instrumentation-nodejs/autoinstrumentation.js'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node.js resource detectors can't be disabled with OTEL_NODE_RESOURCE_DETECTORS
5 participants