Open ericallam opened 5 months ago
Seems like other people are running into this issue in the wild, as seen in this issue here: https://github.com/openai/openai-node/issues/903
I'm looking into this! Thanks for the test case.
@ericallam do you happen to have the openai code that causes TypeError: getDefaultAgent is not a function
?
@timfish full reproduction with OpenAI SDK here: https://github.com/ericallam/iitm-openai
This is the bit of code I copied from them in the test case: https://github.com/openai/openai-node/blob/master/src/_shims/index.mjs
Any update? this makes Datadog unusable in any node project that uses the openai sdk...
The issue with openai
highlights a fundamental flaw in import-in-the-middle
(#38) that probably can't be solved with the current Node loaders API.
I have no idea how DataDog initialises import-in-the-middle
but this PR adds the ability to programatically skip wrapping of incompatible modules to work around this issue for now.
Using iitm 1.8.1 in an ESM project that imports the
openai
package leads to the following exception:getDefaultAgent
is part of the openai shims system, which automatically sets certain platform/runtime specific values using module side-effects. I've recreated a simplified version of this issue in a test file (I may have put the test file in the wrong place, please advise and I can move it if needed). You can see the test pass with the following:And fail with the loader added:
I'm not exactly sure what the issue is, but it does look like possibly the second import of
registry.mjs
in the shims file maybe just uses a module cache, instead of re-importing the module: