-
Notifications
You must be signed in to change notification settings - Fork 472
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
Add Node.js support for --import
flag
#3416
base: main
Are you sure you want to change the base?
Changes from 8 commits
6bb45bf
30c7f36
f4e5a79
3b65d65
4421cc0
993d67f
555ddcb
a8e0a47
d6747dd
da2827e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: auto-instrumentation | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add Node.js support for `--import` flag | ||
|
||
# One or more tracking issues related to the change | ||
issues: [3414] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
The new UseImport option overrides the default injected --require flag with an --import flag. | ||
When using the provided container image, this enables instrumentation of ESM code. | ||
This behavior may be different for other images, and the option may even be either required or unsupported. | ||
Node.js ^18.19.0 || ^20.6.0 || >=22 is required for the flag to be supported. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import "./autoinstrumentation.js"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @raphael-theriault-swi how does the Related ticket: #3465 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trentm could you please take a look here? cc) @JamieDanielson There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pavolloffay Are you asking if However, whether to move the operator to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also add that the The contents of the file could be replaced by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue is that, if we keep adding new features here it will be harder to migrate them to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like I mentioned above switching to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pavolloffay Are there any changes you would like to see with regards to the switch |
||
import module from "node:module"; | ||
|
||
if (typeof module.register === "function") { | ||
module.register("@opentelemetry/instrumentation/hooks.mjs"); | ||
} else { | ||
console.warn( | ||
`OpenTelemetry Operator auto-instrumentation could not instrument ESM code: Node.js ${process.version} does not support 'module.register()'` | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5666,6 +5666,16 @@ If the former var had been defined, then the other vars would be ignored.<br/> | |
Resources describes the compute resource requirements.<br/> | ||
</td> | ||
<td>false</td> | ||
</tr><tr> | ||
<td><b>useImport</b></td> | ||
<td>boolean</td> | ||
<td> | ||
UseImport overrides the default injected --require flag with an --import flag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this documentation should be expanded a bit. It is relevant that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's documented in the Dockerfile which is where the related info about |
||
When using the provided container image, this enables instrumentation of ESM code. | ||
This behavior may be different for other images, and the option may even be either required or unsupported. | ||
Node.js ^18.19.0 || ^20.6.0 || >=22 is required for the flag to be supported.<br/> | ||
</td> | ||
<td>false</td> | ||
</tr><tr> | ||
<td><b><a href="#instrumentationspecnodejsvolumeclaimtemplate">volumeClaimTemplate</a></b></td> | ||
<td>object</td> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One subtlety that might impact the choice of the config var name.
The feature for the user is whether a module import hook is added (via
module.register()
) to support instrumentating ESM code.That is actually independent of whether
--import something.mjs
or--require something.js
is used to run the OTel setup when Node.js is starting up. It is definitely possible to callmodule.register("@opentelemetry/instrumentation/hooks.mjs");
from the CommonJSautoinstrumentation.js
(loaded via--require
).So I wonder if a config name something like
instrumentEsm
or something like that would be clearer.There are a few subtleties discussed at open-telemetry/opentelemetry-js#4933, but I don't think you need to read and grok all that. Eventually we'd like it so that there is just the one obvious way to setup OTel -- and that would be via
--import some-esm-file-that-calls-module.register.mjs
. However, for now we need to make the ESM support opt-in because:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
instrumentEsm
here would be a bit of a misnomer, given that functionality could be added without an import flag, and a custom image could also require the use of an import flag for top level await support (which is actually our usecase for this addition) without providing ESM instrumentationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I misunderstood the use case then. Using
import
in the var name makes sense then. The docs for this feature should mention the two things then: (1)--import ...
is used to load "autoinstrumentation.mjs" (so custom versions can use ESM and top-level await), (2) the default "autoinstrumentation.mjs" differs from "autoinstrumentation.js" in that it registers the hook for ESM instrumentation.