[Node]: Support otel auto instrumentation when code is bundled
Problem Statement
OpenTelemetry auto instrumentation relies on import-in-the-middle and require-in-the-middle to hook loading of modules so they can be proxied and automatically instrumented. If the code is bundled, modules are not loaded so there is no auto instrumentation.
Solution Brainstorm
Using the Sentry bundler plugins, we can wrap the "loading" of modules and call the existing callbacks that hook up the instrumentation.
https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling
https://github.com/open-telemetry/opentelemetry-js/issues/4174 https://github.com/DataDog/dd-trace-js/blob/master/packages/datadog-esbuild/index.js
open-telemetry/opentelemetry-js#4174 DataDog/dd-trace-js@
master/packages/datadog-esbuild/index.js
I can imagine so many scenarios where this esbuild plugin will break.
For vis: I have this PR to add an esbuild plugin for this to OTel js contrib https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1856
@drewcorlin1 huh neat. Thanks for sharing. We'll definitely investigate also creating a plugin ourselves.
Hey guys! Is there any ETA for providing the plugin for webpack/esbuild? This is still blocking us from migrating to v8 :/
Hey, sadly not so far! I think for now using a plugin such as mentioned/proposed by @drewcorlin1 is the way to go!
Hey, sadly not so far! I think for now using a plugin such as mentioned/proposed by @drewcorlin1 is the way to go!
Unfortunately it's only for esbuild, while I need to support webpack as well.
It's in our backlog and I'll make sure we make it part of our planning!
@mydea Any news?
@Michsior14 you'll see it here! We haven't started working on anything.
Would it be possible to manually instrument the packages when using esbuild?
Hey @enko! You could go down the route of implementing something like https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1856 yourself – but we haven't looked into creating a plugin like this ourselves.
@enko Give opentelemetry-esbuild-plugin-node a try! I'm currently working on plugins for other bundlers too (just wrapped up webpack + about to publish it, rollup is next). I'd love any feedback on it or if other bundlers would be helpful