-
Notifications
You must be signed in to change notification settings - Fork 825
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
Worker thread not instrumented using workerData #3486
Comments
Does your worker have its own OTel setup code or do you rely on the main setup for this? We don't do anything particular to support worker threads so I have to assume your worker has its own setup? If that's the case, you may want to try doing a manual setup using trace-base directly. There is a known issue where the SDK setup is asynchronous so you would miss any spans started before the resource detection completes. |
It relies on the main setup. Strange thing is that the main setup is inside a javascript used with the --require. I don't want to manually setup the worker thread tracing, isn't there any way to 'wait' for the required javascript to be fully loaded ? |
Maybe I could try to wait the sdk start ? |
The worker environment and the main context environment are two distinct JavaScript execution environments. We can not share direct JavaScript object access between them. The SDK must be properly set up in both environments if you would like to instrument in the worker environment too. |
When I call the WorkerThread the --require switch is used/forwarded just like for the main thread.
The first log line is about sdk being initialized, the other two are about the computations done by the worker threads. I also tried using the await in the tracing.js setup, and this still doesn't work. Using sendMessage the instrumentation makes the instrumentation work (and I can see my axios traces), so, again, my guess is that workerData is too straightforward and instrumentation isn't completed when axios calls are done by the worker threads. Is there any wait to wait for the instrumentation to be completed using the --require switch with node ? |
This is because of the async nature of NodeSDK in case resource detection is done (which is the default). see here It also happens on main thread. You can avoid it by using the e.g. in your tracing.js const { ConsoleSpanExporter, SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-base")
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node")
const traceExporter = new ConsoleSpanExporter();
const spanProcessor = new SimpleSpanProcessor(traceExporter);
const provider = new NodeTracerProvider();
provider.addSpanProcessor(spanProcessor);
provider.register(); Or you disable autodetection of Resource in
It is vital to delay loading modules to instrument not only the actual operations. If you require the modules to instrument to early they are no instrumented. This could be improved (see #3146) |
I think I'll wait for the resolution of #3502 Thank you |
@amoscatelli does the latest version fix your issue? 🙂 |
I changed my workplace, so I'll try to engage one of my ex coworker to have this tested. Thank you for your work ! |
@amoscatelli @pichlermarc We will be able to try this within the next two weeks. I'll let you know as soon as I will have some useful feedback |
Any update? |
@dyladan We apologize for the delay wrt the expected return time. |
What happened?
Steps to Reproduce
Instrumenting Worker Thread doesn't work when using workerData api.
Using postMessage and message handlers are correctly instrumented.
So for example this works :
Instrumenting doesn't work using workerData instead:
Expected Result
Node.js should be correctly instrumented in a worker thread using workerData, just like when using postMessage.
Actual Result
Node.js is not correctly instrumented, for example http api calls are not traced.
Additional Details
Probably this is a timing issue.
Using postMessage, the Worker Thread message handler, that is the lambda from the code above, has more time to be instrumented.
When using workerData, code is executed earlier, because it is executed straight away without register any handler.
Also I double checked that the issue is present both propagating and not propagating the --require tracing.js and other opentelemetry configuration to the worker thread via argv, env and execArgv as you can see in the code above.
OpenTelemetry Setup Code
package.json
Relevant log output
The text was updated successfully, but these errors were encountered: