Files
klz-cables.com/.pnpm-store/v10/files/8a/23fe03b6b1f4110c2771d9a747c8c9170c97a7ba69d7e6f6a2c05c6b096e35f4c0b0e46084f382444dbe3e362a8d78d714e3c4fb36c3a06f93a345a90c5d9a
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

102 lines
3.3 KiB
Plaintext

import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { SDK_VERSION, _INTERNAL_shouldSkipAiProviderWrapping, ANTHROPIC_AI_INTEGRATION_NAME, getClient, instrumentAnthropicAiClient } from '@sentry/core';
const supportedVersions = ['>=0.19.2 <1.0.0'];
/**
* Sentry Anthropic AI instrumentation using OpenTelemetry.
*/
class SentryAnthropicAiInstrumentation extends InstrumentationBase {
constructor(config = {}) {
super('@sentry/instrumentation-anthropic-ai', SDK_VERSION, config);
}
/**
* Initializes the instrumentation by defining the modules to be patched.
*/
init() {
const module = new InstrumentationNodeModuleDefinition(
'@anthropic-ai/sdk',
supportedVersions,
this._patch.bind(this),
);
return module;
}
/**
* Core patch logic applying instrumentation to the Anthropic AI client constructor.
*/
_patch(exports$1) {
const Original = exports$1.Anthropic;
const config = this.getConfig();
const WrappedAnthropic = function ( ...args) {
// Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)
if (_INTERNAL_shouldSkipAiProviderWrapping(ANTHROPIC_AI_INTEGRATION_NAME)) {
return Reflect.construct(Original, args) ;
}
const instance = Reflect.construct(Original, args);
const client = getClient();
const defaultPii = Boolean(client?.getOptions().sendDefaultPii);
const recordInputs = config.recordInputs ?? defaultPii;
const recordOutputs = config.recordOutputs ?? defaultPii;
return instrumentAnthropicAiClient(instance , {
recordInputs,
recordOutputs,
});
} ;
// Preserve static and prototype chains
Object.setPrototypeOf(WrappedAnthropic, Original);
Object.setPrototypeOf(WrappedAnthropic.prototype, Original.prototype);
for (const key of Object.getOwnPropertyNames(Original)) {
if (!['length', 'name', 'prototype'].includes(key)) {
const descriptor = Object.getOwnPropertyDescriptor(Original, key);
if (descriptor) {
Object.defineProperty(WrappedAnthropic, key, descriptor);
}
}
}
// Constructor replacement - handle read-only properties
// The Anthropic property might have only a getter, so use defineProperty
try {
exports$1.Anthropic = WrappedAnthropic;
} catch (error) {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports$1, '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$1.default === Original) {
try {
exports$1.default = WrappedAnthropic;
} catch (error) {
// If direct assignment fails, override the property descriptor
Object.defineProperty(exports$1, 'default', {
value: WrappedAnthropic,
writable: true,
configurable: true,
enumerable: true,
});
}
}
return exports$1;
}
}
export { SentryAnthropicAiInstrumentation };
//# sourceMappingURL=instrumentation.js.map