You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, we use import-in-the-middle and require-in-the-middle based instrumentation for Node libraries in our Node SDK, e.g. for express, mysql, etc.
This has some downsides:
For ESM, to have import-in-the-middle work reliably it should be configured via --import in the Node CLI
import-in-the-middle is flawed in a couple of ways that means it can't be used to wrap all libraries
Neither import-in-the-middle or require-in-the-middle work with bundled code (as it instruments import/require, basically)
To "fix" this, we want to migrate to using diagnostics_channel for the packages we instrument. With this, both of these downsides disappear.
In order to achieve this, we need to actually PR the libraries themselves (e.g. express, mysql, ...) and make them emit diagnostics_channel (or a tracing channel). Then, the OTEL instrumentation can be updated to use this instead of using import-in-the-middle.
This will be a gradual approach, we can update libraries as we go, starting with more important ones.
The goal is for Express to eventually support publishing events to
`diagnostics_channel` (#15107) so that Open Telemetry can instrument it
without monkey-patching internal code. However, this might take a while
and it would be great to support Express v5 now. This PR is a stop-gap
solution until that work is complete and published.
This PR vendors the code added in my otel PR:
- open-telemetry/opentelemetry-js-contrib#2437
- Adds a new instrumentation specifically for hooking express v5
- Copies the Express v4 integration tests to test v5
- The only changes in the tests is the removal of a couple of complex
regex tests where the regexes are no longer supported by Express.
- Modifies the NestJs v11 tests which now support full Express spans
Description
Today, we use
import-in-the-middle
andrequire-in-the-middle
based instrumentation for Node libraries in our Node SDK, e.g. for express, mysql, etc.This has some downsides:
import-in-the-middle
work reliably it should be configured via--import
in the Node CLIimport-in-the-middle
is flawed in a couple of ways that means it can't be used to wrap all librariesimport-in-the-middle
orrequire-in-the-middle
work with bundled code (as it instrumentsimport
/require
, basically)To "fix" this, we want to migrate to using
diagnostics_channel
for the packages we instrument. With this, both of these downsides disappear.In order to achieve this, we need to actually PR the libraries themselves (e.g. express, mysql, ...) and make them emit
diagnostics_channel
(or a tracing channel). Then, the OTEL instrumentation can be updated to use this instead of using import-in-the-middle.This will be a gradual approach, we can update libraries as we go, starting with more important ones.
The text was updated successfully, but these errors were encountered: