Skip to content

Commit 8ed15bb

Browse files
authored
fix(node): Fix exports for openai instrumentation (#17238)
Fixed an issue where default exports in CommonJS were failing. Returning a new exports object was overriding some default export functionality. I removed some redundant code as well.
1 parent 8caf794 commit 8ed15bb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@ 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+
try {
8889
exports.OpenAI = WrappedOpenAI;
89-
return exports;
90+
} catch (error) {
91+
// If direct assignment fails, override the property descriptor
92+
Object.defineProperty(exports, 'OpenAI', {
93+
value: WrappedOpenAI,
94+
writable: true,
95+
configurable: true,
96+
enumerable: true,
97+
});
9098
}
91-
92-
return { ...exports, OpenAI: WrappedOpenAI };
99+
return exports;
93100
}
94101
}

0 commit comments

Comments
 (0)