Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
_INTERNAL_shouldSkipAiProviderWrapping,
ANTHROPIC_AI_INTEGRATION_NAME,
instrumentAnthropicAiClient,
replaceExports,
SDK_VERSION,
} from '@sentry/core';

Expand Down Expand Up @@ -76,36 +77,8 @@ export class SentryAnthropicAiInstrumentation extends InstrumentationBase<Anthro
}
}

// Constructor replacement - handle read-only properties
// The Anthropic property might have only a getter, so use defineProperty
try {
exports.Anthropic = WrappedAnthropic;
} catch {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports, 'Anthropic', {
value: WrappedAnthropic,
writable: true,
configurable: true,
enumerable: true,
});
}

// Wrap the default export if it points to the original constructor
// Constructor replacement - handle read-only properties
// The Anthropic property might have only a getter, so use defineProperty
if (exports.default === Original) {
try {
exports.default = WrappedAnthropic;
} catch {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports, 'default', {
value: WrappedAnthropic,
writable: true,
configurable: true,
enumerable: true,
});
}
}
// Replace exports with the wrapped constructor
replaceExports(exports, 'Anthropic', WrappedAnthropic);
return exports;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SentryGoogleGenAiInstrumentation extends InstrumentationBase<Google
}
}

// Replace google genai exports with the wrapped constructor
// Replace exports with the wrapped constructor
replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);

return exports;
Expand Down
33 changes: 3 additions & 30 deletions packages/node/src/integrations/tracing/openai/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
_INTERNAL_shouldSkipAiProviderWrapping,
instrumentOpenAiClient,
OPENAI_INTEGRATION_NAME,
replaceExports,
SDK_VERSION,
} from '@sentry/core';

Expand Down Expand Up @@ -90,36 +91,8 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<OpenAiInstr
}
}

// Constructor replacement - handle read-only properties
// The OpenAI property might have only a getter, so use defineProperty
try {
exports[exportKey] = WrappedOpenAI;
} catch {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports, exportKey, {
value: WrappedOpenAI,
writable: true,
configurable: true,
enumerable: true,
});
}

// Wrap the default export if it points to the original constructor
// Constructor replacement - handle read-only properties
// The OpenAI property might have only a getter, so use defineProperty
if (exports.default === Original) {
try {
exports.default = WrappedOpenAI;
} catch {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports, 'default', {
value: WrappedOpenAI,
writable: true,
configurable: true,
enumerable: true,
});
}
}
// Replace exports with the wrapped constructor
replaceExports(exports, exportKey, WrappedOpenAI);
return exports;
}
}
Loading