Open mydea opened 6 days ago
Looks good!
We could try and detect those who will see this as a breaking change and warn them to set this to false long before v9.
Looks good!
We could try and detect those who will see this as a breaking change and warn them to set this to false long before v9.
Is this possible? if so, let's do this I'd say?
Description
Today, by default we instrument all packages with import-in-the-middle in ESM.
For v9, we may flip the default of
onlyIncludeInstrumentedModules
fromfalse
totrue
, so that by default only the things you are adding instrumentation for in the--import
hook are wrapped. This will work for everybody using the SDK to handle OTEL for them; only for users with a custom OTEL setup this may have problems.To clarify, having this flag enabled can lead to issues in rare cases, e.g. if users run
node --import instrument.mjs app.mjs
with code like this:So we have a few possible permutations here, which are unfortunate:
onlyIncludeInstrumentedModules: true
will always work and makes senseregisterEsmLoaderHooks: false
: Users have to set up their own OTEL loader hook, in which case they have to configure things like whatonlyIncludeInstrumentedModules
themselves. āonlyIncludeInstrumentedModules
is ignored anyhow, so default does not matter.registerEsmLoaderHooks: true
(default) andskipOpenTelemetryInstrumentation: true
): This is the tricky scenario.There are a few possible ways we could go there:
skipOpenTelemetryInstrumentation
,registerEsmLoaderHooks
is automaticallyfalse
(so we never set up the loader for users that doskipOpenTelemetryInstrumentation
. While this kind of makes sense, it is definitely breaking for users of this setup (instrumentation will just stop). While setting this up yourself technically makes sense if you are shipping your own OTEL SDK, some users probably rely on us doing this for them right now.onlyIncludeInstrumentedModules
to true, and if users rely on a scenario where they register instrumentation after--import
, they need to flip this themselves. --> it's worth noting that I suspect even for custom otel setups this is a rather rare (but not impossible) scenario.onlyIncludeInstrumentedModules
depending on ifskipOpenTelemetryInstrumentation
is enabledI think I would tend to solution 2 š¤ this is breaking but unlikely to affect a lot of users - it would only affect
a) People using a custom otel setup b) ... who ALSO register instrumentation outside of
--import
And those people only have to flip the setting back to false to get stuff working again š¤