Skip to content

Commit 9d07ad8

Browse files
RulaKhaledandreiborza
authored andcommitted
fix(v9/node): Assign default export of openai to the instrumented fn (#17320)
Both of: - import OpenAI from `openai` - import { OpenAI } from`openai` Should point to the instrumented wrapper function.
1 parent 9f29e0a commit 9d07ad8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/node/src/integrations/tracing/openai/instrumentation.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
9696
enumerable: true,
9797
});
9898
}
99+
100+
// Wrap the default export if it points to the original constructor
101+
// Constructor replacement - handle read-only properties
102+
// The OpenAI property might have only a getter, so use defineProperty
103+
if (exports.default === Original) {
104+
try {
105+
exports.default = WrappedOpenAI;
106+
} catch (error) {
107+
// If direct assignment fails, override the property descriptor
108+
Object.defineProperty(exports, 'default', {
109+
value: WrappedOpenAI,
110+
writable: true,
111+
configurable: true,
112+
enumerable: true,
113+
});
114+
}
115+
}
99116
return exports;
100117
}
101118
}

0 commit comments

Comments
 (0)