-
Notifications
You must be signed in to change notification settings - Fork 530
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
Autoinstrumentation not working #1109
Comments
Could you explain what is not working? Above description just tells that manual creation of spans works as expected. Also your sample code doesn't use express or similar. Therefore it's hard to understand the problem. |
Without your code it's hard to tell. I recommend to post working and non working code to allow comparison. do you ensure that OTel is fully initalised before you require express/nest-js/http? |
unfortunatelly cannot share application and the code i shared above is called in app.ts in first lines. i can also see in logs
but the autoinstrumentation still does not work. the code did not change, i am pretty sure about it. the libraries was version 1.4.0 but now its 1.5.0. anyway, it stopped working with 1.4.0 already.
how to ensure that? |
It's about the sequence of require. It's important that instrumentations are loaded/initialized before the corresponding module is loaded. const express =require("express"); // wont be instrumented
// register instrumentations
const nestjs = require("nestjs"); // should be instrumented You use Side note: While writing this I notice that this is actually quite a bad choice in NodeSDK as the first thing You could easily workaround this by remving const { registerInstrumentations } = require('@opentelemetry/instrumentation');
registerInstrumentations({
instrumentations: getNodeAutoInstrumentations()
}); at the very beginning of your main/tracesetup script, e.g. even before require/initializing Another potential problem is module duplication because of non matching ranges.
|
So.
result: the same - manual span creation works, autoinstrumentation does not work 2nd attempt: remove
logs:
but autoinstrumentation still does not work. attempt 3:
into very first lines of my app.ts code and it started to work!
not sure why it worked this t ime... will try few more refactorings to get more understanding. thanks a lot! --- edit the code:
MUST BE before:
otherwise it will not work. would be good to mention somewhere in docs, if you use NestJS you should initialize before NestFactory |
That is what I said, do not import/require anything before the instrumenations are in place. |
It's documented e.g. here or here. But I agree that it might be better to mention this more visible. I will close this issue as it seems your problem is solved. Feel free to reopen. |
@Flarna this was super helpful! I'd spent days trying to figure out why the trace context wasn't getting inserted into the outbound request, and this simple suggestion fixed it! Thank you very much! 🙏🏼 P.S. we should update the documentation here: https://opentelemetry.io/docs/languages/js/getting-started/nodejs/ |
Help required 🙏
What version of OpenTelemetry are you using?
What version of Node are you using?
Hi,
I have implemented and tested locally the tracing, using ⬆️ libraries.
It was working properly - i saw spans reported, they were autoinstrumented on libraries like
express
or networking.After that, I cannot fully recall, but I went through some nodeJS courses (possibly invoking
tsc
in my project). After 2 days i wanted to run example again, and since then its not working anymore.I was trying to play around and revert all modules (i refactored to modules), then reimplemented from scratch, and again, autoinstrumentation does not work.
What works is the manual test:
I tried all of https://opentelemetry.io/blog/2022/troubleshooting-nodejs/ and without result.
i added debug logger and can see in logs:
which indicates that it is still autoregistering some components.
my full code added to app:
what else can i try?
The text was updated successfully, but these errors were encountered: