-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
9.43.0
Framework Version
Node 22.16.0
Link to Sentry event
N/A - This is a build/import error
Reproduction Example/SDK Setup
https://github.com/mfazekas/sentry-openai-repro
Steps to Reproduce
- Clone the reproduction repository: https://github.com/mfazekas/sentry-openai-repro
- Run
npm install - Run
npm test
The minimal reproduction consists of two files:
sentry.ts:
import * as Sentry from '@sentry/node'
Sentry.init({
dsn: 'https://example@sentry.io/123456',
environment: 'test',
sampleRate: 1.0,
tracesSampler: () => {
return 1.0
},
})
export default Sentryindex.ts:
// Import Sentry first
import './sentry'
// Then import OpenAI
import OpenAI from 'openai'
// This will fail with: TypeError: import_openai.default is not a constructor
const client = new OpenAI({ apiKey: 'dummy-key' })
console.log('✓ OpenAI client created successfully!')Expected Result
The OpenAI client should be created successfully without errors.
Actual Result
TypeError: import_openai.default is not a constructor
at OpenAI (/Users/boga/Work/Zabit/zabit-mono/.local/sentry-openai-repro/index.ts:8:16)
at Object.<anonymous> (/Users/boga/Work/Zabit/zabit-mono/.local/sentry-openai-repro/index.ts:9:52)
at Module._compile (node:internal/modules/cjs/loader:1730:14)
at Object.transformer (/Users/boga/Work/Zabit/zabit-mono/.local/sentry-openai-repro/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:1186)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at cjsLoader (node:internal/modules/esm/translators:266:5)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:200:7)
Additional Context
Version-specific findings:
- ✅ Works: @sentry/node v8.38.0
- ✅ Works: @sentry/node v9.0.0
- ✅ Works: @sentry/node v9.20.0
- ✅ Works: @sentry/node v9.39.0
- ❌ Fails: @sentry/node v9.40.0
- ❌ Fails: @sentry/node v9.43.0
The issue was introduced in v9.40.0.
Key findings:
- The issue ONLY occurs when
tracesSampleris configured - The issue ONLY occurs when Sentry is initialized in a separate file that is imported
- Setting
registerEsmLoaderHooks: falsedoes NOT fix the issue - The issue does NOT occur when both Sentry and OpenAI are imported in the same file
Workarounds:
- Remove
tracesSamplerconfiguration - Use
tracesSampleRateinstead oftracesSampler - Import OpenAI before initializing Sentry
- Downgrade to @sentry/node v9.39.0 or earlier
- Initialize Sentry and import OpenAI in the same file
This appears to be related to how Sentry instruments modules when tracesSampler is enabled. The issue is similar to #12414 but manifests differently (v8 shows "API.Completions is not a constructor" while v9.40+ shows "import_openai.default is not a constructor").
Environment
- Node.js: v22.16.0
- @sentry/node: 9.43.0
- openai: ^4.93.0
- typescript: ~5.8.3
- tsx: 4.19.3
logartis and betamax
Metadata
Metadata
Assignees
Projects
Status
No status