sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

[Node]: Support otel auto instrumentation when code is bundled

Open timfish opened this issue 1 year ago • 14 comments

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.

timfish avatar Mar 06 '24 00:03 timfish

https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#bundling

AbhiPrasad avatar Mar 07 '24 14:03 AbhiPrasad

https://github.com/open-telemetry/opentelemetry-js/issues/4174 https://github.com/DataDog/dd-trace-js/blob/master/packages/datadog-esbuild/index.js

timfish avatar Mar 14 '24 16:03 timfish

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.

lforst avatar Mar 15 '24 08:03 lforst

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 avatar May 08 '24 03:05 drewcorlin1

@drewcorlin1 huh neat. Thanks for sharing. We'll definitely investigate also creating a plugin ourselves.

lforst avatar May 08 '24 07:05 lforst

Hey guys! Is there any ETA for providing the plugin for webpack/esbuild? This is still blocking us from migrating to v8 :/

Michsior14 avatar Jun 13 '24 08:06 Michsior14

Hey, sadly not so far! I think for now using a plugin such as mentioned/proposed by @drewcorlin1 is the way to go!

mydea avatar Jun 13 '24 11:06 mydea

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.

Michsior14 avatar Jun 13 '24 11:06 Michsior14

It's in our backlog and I'll make sure we make it part of our planning!

mydea avatar Jun 13 '24 11:06 mydea

@mydea Any news?

Michsior14 avatar Aug 19 '24 08:08 Michsior14

@Michsior14 you'll see it here! We haven't started working on anything.

lforst avatar Aug 26 '24 07:08 lforst

Would it be possible to manually instrument the packages when using esbuild?

enko avatar May 19 '25 12:05 enko

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.

chargome avatar May 19 '25 12:05 chargome

@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

drewcorlin1 avatar May 19 '25 21:05 drewcorlin1