Skip to content

Commit 9d5156b

Browse files
committed
fix(node): Fix exports for openai instrumentation
1 parent b9849a2 commit 9d5156b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,21 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
8383
}
8484
}
8585

86-
const isESM = Object.prototype.toString.call(exports) === '[object Module]';
87-
if (isESM) {
86+
// Constructor replacement - handle read-only properties
87+
// The OpenAI property might have only a getter, so use defineProperty
88+
// Constructor replacement works the same for both ESM and CJS modules
89+
// We can directly assign to exports.OpenAI in both module systems
90+
try {
8891
exports.OpenAI = WrappedOpenAI;
89-
return exports;
92+
} catch (error) {
93+
// If direct assignment fails, override the property descriptor
94+
Object.defineProperty(exports, 'OpenAI', {
95+
value: WrappedOpenAI,
96+
writable: true,
97+
configurable: true,
98+
enumerable: true,
99+
});
90100
}
91-
92-
return { ...exports, OpenAI: WrappedOpenAI };
101+
return exports;
93102
}
94103
}

0 commit comments

Comments
 (0)