From 0f110f6d1d6b64fa6d38c63cbe2b56ed8c6cf7f8 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Tue, 28 Jul 2026 12:14:08 +0200 Subject: [PATCH] ref(node): Remove vendored Anthropic AI instrumentation This instrumentation is dead code: the Anthropic AI integration is provided by the channel-based implementation in `@sentry/server-utils` (default since #22501), and the vendored OpenTelemetry instrumentation here is no longer wired up. Ref: #22346 Co-Authored-By: Claude Opus 4.8 --- .../tracing/anthropic-ai/index.ts | 9 -- .../tracing/anthropic-ai/instrumentation.ts | 111 ------------------ 2 files changed, 120 deletions(-) delete mode 100644 packages/node/src/integrations/tracing/anthropic-ai/index.ts delete mode 100644 packages/node/src/integrations/tracing/anthropic-ai/instrumentation.ts diff --git a/packages/node/src/integrations/tracing/anthropic-ai/index.ts b/packages/node/src/integrations/tracing/anthropic-ai/index.ts deleted file mode 100644 index ed86f6e83d9c..000000000000 --- a/packages/node/src/integrations/tracing/anthropic-ai/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { AnthropicAiOptions } from '@sentry/core'; -import { ANTHROPIC_AI_INTEGRATION_NAME } from '@sentry/core'; -import { generateInstrumentOnce } from '../../../otel/instrument'; -import { SentryAnthropicAiInstrumentation } from './instrumentation'; - -export const instrumentAnthropicAi = generateInstrumentOnce( - ANTHROPIC_AI_INTEGRATION_NAME, - options => new SentryAnthropicAiInstrumentation(options), -); diff --git a/packages/node/src/integrations/tracing/anthropic-ai/instrumentation.ts b/packages/node/src/integrations/tracing/anthropic-ai/instrumentation.ts deleted file mode 100644 index b01b34f2f8ad..000000000000 --- a/packages/node/src/integrations/tracing/anthropic-ai/instrumentation.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { - InstrumentationBase, - type InstrumentationConfig, - type InstrumentationModuleDefinition, - InstrumentationNodeModuleDefinition, -} from '@opentelemetry/instrumentation'; -import type { AnthropicAiClient, AnthropicAiOptions } from '@sentry/core'; -import { - _INTERNAL_shouldSkipAiProviderWrapping, - ANTHROPIC_AI_INTEGRATION_NAME, - instrumentAnthropicAiClient, - SDK_VERSION, -} from '@sentry/core'; - -const supportedVersions = ['>=0.19.2 <1.0.0']; - -type AnthropicAiInstrumentationOptions = InstrumentationConfig & AnthropicAiOptions; - -/** - * Represents the patched shape of the Anthropic AI module export. - */ -interface PatchedModuleExports { - [key: string]: unknown; - Anthropic: abstract new (...args: unknown[]) => AnthropicAiClient; -} - -/** - * Sentry Anthropic AI instrumentation using OpenTelemetry. - */ -export class SentryAnthropicAiInstrumentation extends InstrumentationBase { - public constructor(config: AnthropicAiInstrumentationOptions = {}) { - super('@sentry/instrumentation-anthropic-ai', SDK_VERSION, config); - } - - /** - * Initializes the instrumentation by defining the modules to be patched. - */ - public init(): InstrumentationModuleDefinition { - 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. - */ - private _patch(exports: PatchedModuleExports): PatchedModuleExports | void { - const Original = exports.Anthropic; - - const config = this.getConfig(); - - const WrappedAnthropic = function (this: unknown, ...args: unknown[]) { - // 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) as AnthropicAiClient; - } - - const instance = Reflect.construct(Original, args); - - return instrumentAnthropicAiClient(instance as AnthropicAiClient, config); - } as unknown as abstract new (...args: unknown[]) => AnthropicAiClient; - - // 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.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, - }); - } - } - return exports; - } -}