UNPKG

openlit

Version:

OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects

43 lines 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const instrumentation_1 = require("@opentelemetry/instrumentation"); const constant_1 = require("../../constant"); const wrapper_1 = __importDefault(require("./wrapper")); class OpenlitAnthropicInstrumentation extends instrumentation_1.InstrumentationBase { constructor(config = {}) { super(`${constant_1.INSTRUMENTATION_PREFIX}/instrumentation-anthropic`, '1.0.0', config); } init() { const module = new instrumentation_1.InstrumentationNodeModuleDefinition('@anthropic-ai/sdk', ['>= 0.21.0'], (moduleExports) => { this._patch(moduleExports); return moduleExports; }, (moduleExports) => { if (moduleExports !== undefined) { this._unpatch(moduleExports); } }); return [module]; } manualPatch(anthropic) { this._patch(anthropic); } _patch(moduleExports) { try { if ((0, instrumentation_1.isWrapped)(moduleExports.Anthropic.Messages.prototype.create)) { this._unwrap(moduleExports.Anthropic.Messages.prototype, 'create'); } this._wrap(moduleExports.Anthropic.Messages.prototype, 'create', wrapper_1.default._patchMessageCreate(this.tracer)); } catch (e) { console.error('Error in _patch method:', e); } } _unpatch(moduleExports) { this._unwrap(moduleExports.Anthropic.Messages.prototype, 'create'); } } exports.default = OpenlitAnthropicInstrumentation; //# sourceMappingURL=index.js.map