-
Notifications
You must be signed in to change notification settings - Fork 305
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
Error with ESM support when using the openai
package
#4277
Comments
This may be similar to getsentry/sentry-javascript#12414 and thus openai/openai-node#1010 and openai/openai-node#903. If that is the case, this problem would likely now surface like this:
and the workaround is to do this: // loader.mjs
import { register } from "node:module";
register("import-in-the-middle/hook.mjs", import.meta.url, {
parentURL: import.meta.url,
data: { include: ["openai"]}, // this is the important bit here
}); which I believe may need to be done on the Datadog side. |
According to @guidev, this bug (or perhaps another one?) makes Datadog unusable in any node projects that use the @sabrenner, worth a look? |
FYI the loader.mjs workaround prevented the error in my project, but also stopped traces from being sent. The way I was able to fix this was by importing the openai web shims using the Start node like this:
When initializing the openai client: import 'http'
import OpenAI from 'openai'
const openai = new OpenAI({
httpAgent: new http.Agent()
}) And it all works! Same steps apply if you're using Anthropic btw. |
Thanks for the ping @rattrayalex! I'm wondering if folks here have tried @adam-on-tailwind's solution, and how it worked for them. In any case, I try out including the |
Awesome, thanks Sam! Let me know if there's anything I can do to help. |
When running a Node.js (v20) server with ESM modules using
dd-trace
andopenai
packages, the process crashes with the following error:Expected Behavior
Running
node --import dd-trace/register.js index.js
should start the server without crashing.Steps to Reproduce
Using Node.js
v20.11.0
:npm init -y
npm i [email protected] [email protected]
package.json
file:dd-trace
andopenai
in theindex.js
file:node --import dd-trace/register.js index.js
Your Environment
dd-trace
: 5.12.0openai
: 4.40.0The text was updated successfully, but these errors were encountered: