@traceloop/instrumentation-anthropic 0.22.0 → 0.22.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ var tslib = require('tslib');
4
4
  var api = require('@opentelemetry/api');
5
5
  var instrumentation = require('@opentelemetry/instrumentation');
6
6
  var aiSemanticConventions = require('@traceloop/ai-semantic-conventions');
7
+ var incubating = require('@opentelemetry/semantic-conventions/incubating');
7
8
 
8
- var version = "0.22.0";
9
+ var version = "0.22.5";
9
10
 
10
11
  class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
11
12
  constructor(config = {}) {
@@ -81,13 +82,13 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
81
82
  startSpan({ type, params, }) {
82
83
  var _a, _b;
83
84
  const attributes = {
84
- [aiSemanticConventions.SpanAttributes.LLM_SYSTEM]: "Anthropic",
85
+ [incubating.ATTR_GEN_AI_SYSTEM]: "Anthropic",
85
86
  [aiSemanticConventions.SpanAttributes.LLM_REQUEST_TYPE]: type,
86
87
  };
87
88
  try {
88
- attributes[aiSemanticConventions.SpanAttributes.LLM_REQUEST_MODEL] = params.model;
89
- attributes[aiSemanticConventions.SpanAttributes.LLM_REQUEST_TEMPERATURE] = params.temperature;
90
- attributes[aiSemanticConventions.SpanAttributes.LLM_REQUEST_TOP_P] = params.top_p;
89
+ attributes[incubating.ATTR_GEN_AI_REQUEST_MODEL] = params.model;
90
+ attributes[incubating.ATTR_GEN_AI_REQUEST_TEMPERATURE] = params.temperature;
91
+ attributes[incubating.ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;
91
92
  attributes[aiSemanticConventions.SpanAttributes.LLM_TOP_K] = params.top_k;
92
93
  // Handle thinking parameters (for beta messages)
93
94
  const betaParams = params;
@@ -97,11 +98,11 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
97
98
  betaParams.thinking.budget_tokens;
98
99
  }
99
100
  if (type === "completion") {
100
- attributes[aiSemanticConventions.SpanAttributes.LLM_REQUEST_MAX_TOKENS] =
101
+ attributes[incubating.ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
101
102
  params.max_tokens_to_sample;
102
103
  }
103
104
  else {
104
- attributes[aiSemanticConventions.SpanAttributes.LLM_REQUEST_MAX_TOKENS] = params.max_tokens;
105
+ attributes[incubating.ATTR_GEN_AI_REQUEST_MAX_TOKENS] = params.max_tokens;
105
106
  }
106
107
  if (params.extraAttributes !== undefined &&
107
108
  typeof params.extraAttributes === "object") {
@@ -114,8 +115,8 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
114
115
  let promptIndex = 0;
115
116
  // If a system prompt is provided, it should always be first
116
117
  if ("system" in params && params.system !== undefined) {
117
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.0.role`] = "system";
118
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.0.content`] =
118
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.0.role`] = "system";
119
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.0.content`] =
119
120
  typeof params.system === "string"
120
121
  ? params.system
121
122
  : JSON.stringify(params.system);
@@ -123,19 +124,21 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
123
124
  }
124
125
  params.messages.forEach((message, index) => {
125
126
  const currentIndex = index + promptIndex;
126
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.${currentIndex}.role`] =
127
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.${currentIndex}.role`] =
127
128
  message.role;
128
129
  if (typeof message.content === "string") {
129
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`] = message.content || "";
130
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
131
+ message.content || "";
130
132
  }
131
133
  else {
132
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`] = JSON.stringify(message.content);
134
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
135
+ JSON.stringify(message.content);
133
136
  }
134
137
  });
135
138
  }
136
139
  else {
137
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.0.role`] = "user";
138
- attributes[`${aiSemanticConventions.SpanAttributes.LLM_PROMPTS}.0.content`] = params.prompt;
140
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.0.role`] = "user";
141
+ attributes[`${incubating.ATTR_GEN_AI_PROMPT}.0.content`] = params.prompt;
139
142
  }
140
143
  }
141
144
  }
@@ -165,8 +168,9 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
165
168
  usage: {
166
169
  input_tokens: 0,
167
170
  output_tokens: 0,
168
- cache_creation_input_tokens: 0,
169
- cache_read_input_tokens: 0,
171
+ cache_creation: null,
172
+ cache_creation_input_tokens: null,
173
+ cache_read_input_tokens: null,
170
174
  server_tool_use: null,
171
175
  service_tier: null,
172
176
  },
@@ -317,23 +321,23 @@ class AnthropicInstrumentation extends instrumentation.InstrumentationBase {
317
321
  _endSpan({ span, type, result, }) {
318
322
  var _a, _b, _c, _d, _e, _f;
319
323
  try {
320
- span.setAttribute(aiSemanticConventions.SpanAttributes.LLM_RESPONSE_MODEL, result.model);
324
+ span.setAttribute(incubating.ATTR_GEN_AI_RESPONSE_MODEL, result.model);
321
325
  if (type === "chat" && result.usage) {
322
326
  span.setAttribute(aiSemanticConventions.SpanAttributes.LLM_USAGE_TOTAL_TOKENS, ((_a = result.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) + ((_b = result.usage) === null || _b === void 0 ? void 0 : _b.output_tokens));
323
- span.setAttribute(aiSemanticConventions.SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, (_c = result.usage) === null || _c === void 0 ? void 0 : _c.output_tokens);
324
- span.setAttribute(aiSemanticConventions.SpanAttributes.LLM_USAGE_PROMPT_TOKENS, (_d = result.usage) === null || _d === void 0 ? void 0 : _d.input_tokens);
327
+ span.setAttribute(incubating.ATTR_GEN_AI_USAGE_COMPLETION_TOKENS, (_c = result.usage) === null || _c === void 0 ? void 0 : _c.output_tokens);
328
+ span.setAttribute(incubating.ATTR_GEN_AI_USAGE_PROMPT_TOKENS, (_d = result.usage) === null || _d === void 0 ? void 0 : _d.input_tokens);
325
329
  }
326
330
  if (result.stop_reason) {
327
- span.setAttribute(`${aiSemanticConventions.SpanAttributes.LLM_COMPLETIONS}.0.finish_reason`, result.stop_reason);
331
+ span.setAttribute(`${incubating.ATTR_GEN_AI_COMPLETION}.0.finish_reason`, result.stop_reason);
328
332
  }
329
333
  if (this._shouldSendPrompts()) {
330
334
  if (type === "chat") {
331
- span.setAttribute(`${aiSemanticConventions.SpanAttributes.LLM_COMPLETIONS}.0.role`, "assistant");
332
- span.setAttribute(`${aiSemanticConventions.SpanAttributes.LLM_COMPLETIONS}.0.content`, JSON.stringify(result.content));
335
+ span.setAttribute(`${incubating.ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
336
+ span.setAttribute(`${incubating.ATTR_GEN_AI_COMPLETION}.0.content`, JSON.stringify(result.content));
333
337
  }
334
338
  else {
335
- span.setAttribute(`${aiSemanticConventions.SpanAttributes.LLM_COMPLETIONS}.0.role`, "assistant");
336
- span.setAttribute(`${aiSemanticConventions.SpanAttributes.LLM_COMPLETIONS}.0.content`, result.completion);
339
+ span.setAttribute(`${incubating.ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
340
+ span.setAttribute(`${incubating.ATTR_GEN_AI_COMPLETION}.0.content`, result.completion);
337
341
  }
338
342
  }
339
343
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/instrumentation.ts"],"sourcesContent":["/*\n * Copyright Traceloop\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n context,\n trace,\n Span,\n Attributes,\n SpanKind,\n SpanStatusCode,\n} from \"@opentelemetry/api\";\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from \"@opentelemetry/instrumentation\";\nimport {\n CONTEXT_KEY_ALLOW_TRACE_CONTENT,\n SpanAttributes,\n} from \"@traceloop/ai-semantic-conventions\";\nimport { AnthropicInstrumentationConfig } from \"./types\";\nimport { version } from \"../package.json\";\nimport type * as anthropic from \"@anthropic-ai/sdk\";\nimport type {\n CompletionCreateParamsNonStreaming,\n CompletionCreateParamsStreaming,\n Completion,\n} from \"@anthropic-ai/sdk/resources/completions\";\nimport type {\n MessageCreateParamsNonStreaming,\n MessageCreateParamsStreaming,\n Message,\n MessageStreamEvent,\n} from \"@anthropic-ai/sdk/resources/messages\";\nimport type { MessageCreateParamsNonStreaming as BetaMessageCreateParamsNonStreaming } from \"@anthropic-ai/sdk/resources/beta/messages\";\nimport type { Stream } from \"@anthropic-ai/sdk/streaming\";\nimport type { APIPromise, BaseAnthropic } from \"@anthropic-ai/sdk\";\n\nexport class AnthropicInstrumentation extends InstrumentationBase {\n declare protected _config: AnthropicInstrumentationConfig;\n\n constructor(config: AnthropicInstrumentationConfig = {}) {\n super(\"@traceloop/instrumentation-anthropic\", version, config);\n }\n\n public override setConfig(config: AnthropicInstrumentationConfig = {}) {\n super.setConfig(config);\n }\n\n public manuallyInstrument(module: typeof anthropic) {\n this._diag.debug(`Patching @anthropic-ai/sdk manually`);\n\n this._wrap(\n module.Anthropic.Completions.prototype,\n \"create\",\n this.patchAnthropic(\"completion\", module),\n );\n this._wrap(\n module.Anthropic.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", module),\n );\n this._wrap(\n module.Anthropic.Beta.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", module),\n );\n }\n\n protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n \"@anthropic-ai/sdk\",\n [\">=0.9.1\"],\n this.patch.bind(this),\n this.unpatch.bind(this),\n );\n return module;\n }\n\n private patch(moduleExports: typeof anthropic, moduleVersion?: string) {\n this._diag.debug(`Patching @anthropic-ai/sdk@${moduleVersion}`);\n\n this._wrap(\n moduleExports.Anthropic.Completions.prototype,\n \"create\",\n this.patchAnthropic(\"completion\", moduleExports),\n );\n this._wrap(\n moduleExports.Anthropic.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", moduleExports),\n );\n this._wrap(\n moduleExports.Anthropic.Beta.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", moduleExports),\n );\n return moduleExports;\n }\n\n private unpatch(\n moduleExports: typeof anthropic,\n moduleVersion?: string,\n ): void {\n this._diag.debug(`Unpatching @anthropic-ai/sdk@${moduleVersion}`);\n\n this._unwrap(moduleExports.Anthropic.Completions.prototype, \"create\");\n this._unwrap(moduleExports.Anthropic.Messages.prototype, \"create\");\n this._unwrap(moduleExports.Anthropic.Beta.Messages.prototype, \"create\");\n }\n\n private patchAnthropic(\n type: \"chat\" | \"completion\",\n moduleExports: typeof anthropic,\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const plugin = this;\n // eslint-disable-next-line\n return (original: Function) => {\n return function method(this: any, ...args: unknown[]) {\n const span =\n type === \"chat\"\n ? plugin.startSpan({\n type,\n params: args[0] as MessageCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n },\n })\n : plugin.startSpan({\n type,\n params: args[0] as CompletionCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n },\n });\n\n const execContext = trace.setSpan(context.active(), span);\n const execPromise = safeExecuteInTheMiddle(\n () => {\n return context.with(execContext, () => {\n if ((args?.[0] as any)?.extraAttributes) {\n delete (args[0] as any).extraAttributes;\n }\n return original.apply(this, args);\n });\n },\n (e) => {\n if (e) {\n plugin._diag.error(\"Error in Anthropic instrumentation\", e);\n }\n },\n );\n\n if (\n (\n args[0] as\n | MessageCreateParamsStreaming\n | CompletionCreateParamsStreaming\n ).stream\n ) {\n return context.bind(\n execContext,\n plugin._streamingWrapPromise(this._client, moduleExports, {\n span,\n type,\n promise: execPromise,\n }),\n );\n }\n\n const wrappedPromise = plugin._wrapPromise(type, span, execPromise);\n\n return context.bind(execContext, wrappedPromise as any);\n };\n };\n }\n\n private startSpan({\n type,\n params,\n }:\n | {\n type: \"chat\";\n params: MessageCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n };\n }\n | {\n type: \"completion\";\n params: CompletionCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n };\n }): Span {\n const attributes: Attributes = {\n [SpanAttributes.LLM_SYSTEM]: \"Anthropic\",\n [SpanAttributes.LLM_REQUEST_TYPE]: type,\n };\n\n try {\n attributes[SpanAttributes.LLM_REQUEST_MODEL] = params.model;\n attributes[SpanAttributes.LLM_REQUEST_TEMPERATURE] = params.temperature;\n attributes[SpanAttributes.LLM_REQUEST_TOP_P] = params.top_p;\n attributes[SpanAttributes.LLM_TOP_K] = params.top_k;\n\n // Handle thinking parameters (for beta messages)\n const betaParams = params as BetaMessageCreateParamsNonStreaming;\n if (betaParams.thinking && betaParams.thinking.type === \"enabled\") {\n attributes[\"llm.request.thinking.type\"] = betaParams.thinking.type;\n attributes[\"llm.request.thinking.budget_tokens\"] =\n betaParams.thinking.budget_tokens;\n }\n\n if (type === \"completion\") {\n attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] =\n params.max_tokens_to_sample;\n } else {\n attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] = params.max_tokens;\n }\n\n if (\n params.extraAttributes !== undefined &&\n typeof params.extraAttributes === \"object\"\n ) {\n Object.keys(params.extraAttributes).forEach((key: string) => {\n attributes[key] = params.extraAttributes![key];\n });\n }\n\n if (this._shouldSendPrompts()) {\n if (type === \"chat\") {\n let promptIndex = 0;\n\n // If a system prompt is provided, it should always be first\n if (\"system\" in params && params.system !== undefined) {\n attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = \"system\";\n attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] =\n typeof params.system === \"string\"\n ? params.system\n : JSON.stringify(params.system);\n promptIndex += 1;\n }\n\n params.messages.forEach((message, index) => {\n const currentIndex = index + promptIndex;\n attributes[`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.role`] =\n message.role;\n if (typeof message.content === \"string\") {\n attributes[\n `${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`\n ] = (message.content as string) || \"\";\n } else {\n attributes[\n `${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`\n ] = JSON.stringify(message.content);\n }\n });\n } else {\n attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = \"user\";\n attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] = params.prompt;\n }\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n\n return this.tracer.startSpan(`anthropic.${type}`, {\n kind: SpanKind.CLIENT,\n attributes,\n });\n }\n\n private _streamingWrapPromise(\n client: BaseAnthropic,\n moduleExports: typeof anthropic,\n {\n span,\n type,\n promise,\n }:\n | {\n span: Span;\n type: \"chat\";\n promise: APIPromise<Stream<MessageStreamEvent>>;\n }\n | {\n span: Span;\n type: \"completion\";\n promise: APIPromise<Stream<Completion>>;\n },\n ) {\n async function* iterateStream(\n this: AnthropicInstrumentation,\n stream: Stream<MessageStreamEvent> | Stream<Completion>,\n ) {\n try {\n if (type === \"chat\") {\n const result: Message = {\n id: \"0\",\n type: \"message\",\n model: \"\",\n role: \"assistant\",\n stop_reason: null,\n stop_sequence: null,\n usage: {\n input_tokens: 0,\n output_tokens: 0,\n cache_creation_input_tokens: 0,\n cache_read_input_tokens: 0,\n server_tool_use: null,\n service_tier: null,\n },\n content: [],\n };\n\n for await (const chunk of stream) {\n yield chunk;\n\n try {\n switch (chunk.type) {\n case \"message_start\":\n result.id = chunk.message.id;\n result.model = chunk.message.model;\n Object.assign(result.usage, chunk.message.usage);\n break;\n case \"message_delta\":\n if (chunk.usage) {\n Object.assign(result.usage, chunk.usage);\n }\n break;\n case \"content_block_start\":\n if (result.content.length <= chunk.index) {\n result.content.push({ ...chunk.content_block });\n }\n break;\n\n case \"content_block_delta\":\n if (chunk.index < result.content.length) {\n const current = result.content[chunk.index];\n if (\n current.type === \"text\" &&\n chunk.delta.type === \"text_delta\"\n ) {\n result.content[chunk.index] = {\n type: \"text\",\n text: current.text + chunk.delta.text,\n citations: current.citations,\n };\n }\n }\n break;\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n }\n\n this._endSpan({ span, type, result });\n } else {\n const result: Completion = {\n id: \"0\",\n type: \"completion\",\n model: \"\",\n completion: \"\",\n stop_reason: null,\n };\n for await (const chunk of stream as Stream<Completion>) {\n yield chunk;\n\n try {\n result.id = chunk.id;\n result.model = chunk.model;\n\n if (chunk.stop_reason) {\n result.stop_reason = chunk.stop_reason;\n }\n if (chunk.model) {\n result.model = chunk.model;\n }\n if (chunk.completion) {\n result.completion += chunk.completion;\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n }\n\n this._endSpan({ span, type, result });\n }\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n throw error;\n }\n }\n\n return new moduleExports.APIPromise(\n client,\n (promise as any).responsePromise,\n async (client, props) => {\n const realStream = await (promise as any).parseResponse(client, props);\n\n // take the incoming stream, iterate it using our instrumented function, and wrap it in a new stream to keep the rich object type the same\n return new realStream.constructor(\n () => iterateStream.call(this, realStream),\n realStream.controller,\n );\n },\n ) as\n | APIPromise<Stream<MessageStreamEvent>>\n | APIPromise<Stream<Completion>>;\n }\n\n private _wrapPromise<T>(\n type: \"chat\" | \"completion\",\n span: Span,\n promise: Promise<T>,\n ): Promise<T> {\n return promise\n .then((result) => {\n if (type === \"chat\") {\n this._endSpan({\n type,\n span,\n result: result as Message,\n });\n } else {\n this._endSpan({\n type,\n span,\n result: result as Completion,\n });\n }\n\n return result;\n })\n .catch((error: Error) => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n\n throw error;\n });\n }\n\n private _endSpan({\n span,\n type,\n result,\n }:\n | { span: Span; type: \"chat\"; result: Message }\n | {\n span: Span;\n type: \"completion\";\n result: Completion;\n }) {\n try {\n span.setAttribute(SpanAttributes.LLM_RESPONSE_MODEL, result.model);\n if (type === \"chat\" && result.usage) {\n span.setAttribute(\n SpanAttributes.LLM_USAGE_TOTAL_TOKENS,\n result.usage?.input_tokens + result.usage?.output_tokens,\n );\n span.setAttribute(\n SpanAttributes.LLM_USAGE_COMPLETION_TOKENS,\n result.usage?.output_tokens,\n );\n span.setAttribute(\n SpanAttributes.LLM_USAGE_PROMPT_TOKENS,\n result.usage?.input_tokens,\n );\n }\n\n if (result.stop_reason) {\n span.setAttribute(\n `${SpanAttributes.LLM_COMPLETIONS}.0.finish_reason`,\n result.stop_reason,\n );\n }\n\n if (this._shouldSendPrompts()) {\n if (type === \"chat\") {\n span.setAttribute(\n `${SpanAttributes.LLM_COMPLETIONS}.0.role`,\n \"assistant\",\n );\n span.setAttribute(\n `${SpanAttributes.LLM_COMPLETIONS}.0.content`,\n JSON.stringify(result.content),\n );\n } else {\n span.setAttribute(\n `${SpanAttributes.LLM_COMPLETIONS}.0.role`,\n \"assistant\",\n );\n span.setAttribute(\n `${SpanAttributes.LLM_COMPLETIONS}.0.content`,\n result.completion,\n );\n }\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n\n span.end();\n }\n\n private _shouldSendPrompts() {\n const contextShouldSendPrompts = context\n .active()\n .getValue(CONTEXT_KEY_ALLOW_TRACE_CONTENT);\n\n if (contextShouldSendPrompts !== undefined) {\n return contextShouldSendPrompts;\n }\n\n return this._config.traceContent !== undefined\n ? this._config.traceContent\n : true;\n }\n}\n"],"names":["InstrumentationBase","InstrumentationNodeModuleDefinition","trace","context","safeExecuteInTheMiddle","SpanAttributes","SpanKind","__asyncValues","__await","SpanStatusCode","__awaiter","CONTEXT_KEY_ALLOW_TRACE_CONTENT"],"mappings":";;;;;;;;;AAmDM,MAAO,wBAAyB,SAAQA,mCAAmB,CAAA;AAG/D,IAAA,WAAA,CAAY,SAAyC,EAAE,EAAA;AACrD,QAAA,KAAK,CAAC,sCAAsC,EAAE,OAAO,EAAE,MAAM,CAAC;IAChE;IAEgB,SAAS,CAAC,SAAyC,EAAE,EAAA;AACnE,QAAA,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;IACzB;AAEO,IAAA,kBAAkB,CAAC,MAAwB,EAAA;AAChD,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA,mCAAA,CAAqC,CAAC;QAEvD,IAAI,CAAC,KAAK,CACR,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,SAAS,EACtC,QAAQ,EACR,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,CAC1C;QACD,IAAI,CAAC,KAAK,CACR,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EACnC,QAAQ,EACR,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CACpC;QACD,IAAI,CAAC,KAAK,CACR,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EACxC,QAAQ,EACR,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CACpC;IACH;IAEU,IAAI,GAAA;AACZ,QAAA,MAAM,MAAM,GAAG,IAAIC,mDAAmC,CACpD,mBAAmB,EACnB,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAA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S,EAC1C,WAAW,CACZ;AACD,oBAAA,IAAI,CAAC,YAAY,CACf,GAAGA,oCAAc,CAAC,eAAe,CAAA,UAAA,CAAY,EAC7C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAC/B;gBACH;qBAAO;oBACL,IAAI,CAAC,YAAY,CACf,CAAA,EAAGA,oCAAc,CAAC,eAAe,CAAA,OAAA,CAAS,EAC1C,WAAW,CACZ;AACD,oBAAA,IAAI,CAAC,YAAY,CACf,CAAA,EAAGA,oCAAc,CAAC,eAAe,CAAA,UAAA,CAAY,EAC7C,MAAM,CAAC,UAAU,CAClB;gBACH;YACF;QACF;QAAE,OAAO,CAAC,EAAE;AACV,YAAA,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YACnB,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,IAAI,CAAC,OAAO,EAAC,eAAe,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA,CAAA,EAAA,EAAG,CAAC,CAAC;QACnC;QAEA,IAAI,CAAC,GAAG,EAAE;IACZ;IAEQ,kBAAkB,GAAA;QACxB,MAAM,wBAAwB,GAAGF;AAC9B,aAAA,MAAM;aACN,QAAQ,CAACQ,qDAA+B,CAAC;AAE5C,QAAA,IAAI,wBAAwB,KAAK,SAAS,EAAE;AAC1C,YAAA,OAAO,wBAAwB;QACjC;AAEA,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK;AACnC,cAAE,IAAI,CAAC,OAAO,CAAC;cACb,IAAI;IACV;AACD;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/instrumentation.ts"],"sourcesContent":["/*\n * Copyright Traceloop\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n context,\n trace,\n Span,\n Attributes,\n SpanKind,\n SpanStatusCode,\n} from \"@opentelemetry/api\";\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from \"@opentelemetry/instrumentation\";\nimport {\n CONTEXT_KEY_ALLOW_TRACE_CONTENT,\n SpanAttributes,\n} from \"@traceloop/ai-semantic-conventions\";\nimport {\n ATTR_GEN_AI_COMPLETION,\n ATTR_GEN_AI_PROMPT,\n ATTR_GEN_AI_REQUEST_MAX_TOKENS,\n ATTR_GEN_AI_REQUEST_MODEL,\n ATTR_GEN_AI_REQUEST_TEMPERATURE,\n ATTR_GEN_AI_REQUEST_TOP_P,\n ATTR_GEN_AI_RESPONSE_MODEL,\n ATTR_GEN_AI_SYSTEM,\n ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,\n ATTR_GEN_AI_USAGE_PROMPT_TOKENS,\n} from \"@opentelemetry/semantic-conventions/incubating\";\nimport { AnthropicInstrumentationConfig } from \"./types\";\nimport { version } from \"../package.json\";\nimport type * as anthropic from \"@anthropic-ai/sdk\";\nimport type {\n CompletionCreateParamsNonStreaming,\n CompletionCreateParamsStreaming,\n Completion,\n} from \"@anthropic-ai/sdk/resources/completions\";\nimport type {\n MessageCreateParamsNonStreaming,\n MessageCreateParamsStreaming,\n Message,\n MessageStreamEvent,\n} from \"@anthropic-ai/sdk/resources/messages\";\nimport type { MessageCreateParamsNonStreaming as BetaMessageCreateParamsNonStreaming } from \"@anthropic-ai/sdk/resources/beta/messages\";\nimport type { Stream } from \"@anthropic-ai/sdk/streaming\";\nimport type { APIPromise, BaseAnthropic } from \"@anthropic-ai/sdk\";\n\nexport class AnthropicInstrumentation extends InstrumentationBase {\n declare protected _config: AnthropicInstrumentationConfig;\n\n constructor(config: AnthropicInstrumentationConfig = {}) {\n super(\"@traceloop/instrumentation-anthropic\", version, config);\n }\n\n public override setConfig(config: AnthropicInstrumentationConfig = {}) {\n super.setConfig(config);\n }\n\n public manuallyInstrument(module: typeof anthropic) {\n this._diag.debug(`Patching @anthropic-ai/sdk manually`);\n\n this._wrap(\n module.Anthropic.Completions.prototype,\n \"create\",\n this.patchAnthropic(\"completion\", module),\n );\n this._wrap(\n module.Anthropic.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", module),\n );\n this._wrap(\n module.Anthropic.Beta.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", module),\n );\n }\n\n protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n \"@anthropic-ai/sdk\",\n [\">=0.9.1\"],\n this.patch.bind(this),\n this.unpatch.bind(this),\n );\n return module;\n }\n\n private patch(moduleExports: typeof anthropic, moduleVersion?: string) {\n this._diag.debug(`Patching @anthropic-ai/sdk@${moduleVersion}`);\n\n this._wrap(\n moduleExports.Anthropic.Completions.prototype,\n \"create\",\n this.patchAnthropic(\"completion\", moduleExports),\n );\n this._wrap(\n moduleExports.Anthropic.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", moduleExports),\n );\n this._wrap(\n moduleExports.Anthropic.Beta.Messages.prototype,\n \"create\",\n this.patchAnthropic(\"chat\", moduleExports),\n );\n return moduleExports;\n }\n\n private unpatch(\n moduleExports: typeof anthropic,\n moduleVersion?: string,\n ): void {\n this._diag.debug(`Unpatching @anthropic-ai/sdk@${moduleVersion}`);\n\n this._unwrap(moduleExports.Anthropic.Completions.prototype, \"create\");\n this._unwrap(moduleExports.Anthropic.Messages.prototype, \"create\");\n this._unwrap(moduleExports.Anthropic.Beta.Messages.prototype, \"create\");\n }\n\n private patchAnthropic(\n type: \"chat\" | \"completion\",\n moduleExports: typeof anthropic,\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const plugin = this;\n // eslint-disable-next-line\n return (original: Function) => {\n return function method(this: any, ...args: unknown[]) {\n const span =\n type === \"chat\"\n ? plugin.startSpan({\n type,\n params: args[0] as MessageCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n },\n })\n : plugin.startSpan({\n type,\n params: args[0] as CompletionCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n },\n });\n\n const execContext = trace.setSpan(context.active(), span);\n const execPromise = safeExecuteInTheMiddle(\n () => {\n return context.with(execContext, () => {\n if ((args?.[0] as any)?.extraAttributes) {\n delete (args[0] as any).extraAttributes;\n }\n return original.apply(this, args);\n });\n },\n (e) => {\n if (e) {\n plugin._diag.error(\"Error in Anthropic instrumentation\", e);\n }\n },\n );\n\n if (\n (\n args[0] as\n | MessageCreateParamsStreaming\n | CompletionCreateParamsStreaming\n ).stream\n ) {\n return context.bind(\n execContext,\n plugin._streamingWrapPromise(this._client, moduleExports, {\n span,\n type,\n promise: execPromise,\n }),\n );\n }\n\n const wrappedPromise = plugin._wrapPromise(type, span, execPromise);\n\n return context.bind(execContext, wrappedPromise as any);\n };\n };\n }\n\n private startSpan({\n type,\n params,\n }:\n | {\n type: \"chat\";\n params: MessageCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n };\n }\n | {\n type: \"completion\";\n params: CompletionCreateParamsNonStreaming & {\n extraAttributes?: Record<string, any>;\n };\n }): Span {\n const attributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: \"Anthropic\",\n [SpanAttributes.LLM_REQUEST_TYPE]: type,\n };\n\n try {\n attributes[ATTR_GEN_AI_REQUEST_MODEL] = params.model;\n attributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = params.temperature;\n attributes[ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;\n attributes[SpanAttributes.LLM_TOP_K] = params.top_k;\n\n // Handle thinking parameters (for beta messages)\n const betaParams = params as BetaMessageCreateParamsNonStreaming;\n if (betaParams.thinking && betaParams.thinking.type === \"enabled\") {\n attributes[\"llm.request.thinking.type\"] = betaParams.thinking.type;\n attributes[\"llm.request.thinking.budget_tokens\"] =\n betaParams.thinking.budget_tokens;\n }\n\n if (type === \"completion\") {\n attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n params.max_tokens_to_sample;\n } else {\n attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = params.max_tokens;\n }\n\n if (\n params.extraAttributes !== undefined &&\n typeof params.extraAttributes === \"object\"\n ) {\n Object.keys(params.extraAttributes).forEach((key: string) => {\n attributes[key] = params.extraAttributes![key];\n });\n }\n\n if (this._shouldSendPrompts()) {\n if (type === \"chat\") {\n let promptIndex = 0;\n\n // If a system prompt is provided, it should always be first\n if (\"system\" in params && params.system !== undefined) {\n attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = \"system\";\n attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] =\n typeof params.system === \"string\"\n ? params.system\n : JSON.stringify(params.system);\n promptIndex += 1;\n }\n\n params.messages.forEach((message, index) => {\n const currentIndex = index + promptIndex;\n attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.role`] =\n message.role;\n if (typeof message.content === \"string\") {\n attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =\n (message.content as string) || \"\";\n } else {\n attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =\n JSON.stringify(message.content);\n }\n });\n } else {\n attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = \"user\";\n attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] = params.prompt;\n }\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n\n return this.tracer.startSpan(`anthropic.${type}`, {\n kind: SpanKind.CLIENT,\n attributes,\n });\n }\n\n private _streamingWrapPromise(\n client: BaseAnthropic,\n moduleExports: typeof anthropic,\n {\n span,\n type,\n promise,\n }:\n | {\n span: Span;\n type: \"chat\";\n promise: APIPromise<Stream<MessageStreamEvent>>;\n }\n | {\n span: Span;\n type: \"completion\";\n promise: APIPromise<Stream<Completion>>;\n },\n ) {\n async function* iterateStream(\n this: AnthropicInstrumentation,\n stream: Stream<MessageStreamEvent> | Stream<Completion>,\n ) {\n try {\n if (type === \"chat\") {\n const result: Message = {\n id: \"0\",\n type: \"message\",\n model: \"\",\n role: \"assistant\",\n stop_reason: null,\n stop_sequence: null,\n usage: {\n input_tokens: 0,\n output_tokens: 0,\n cache_creation: null,\n cache_creation_input_tokens: null,\n cache_read_input_tokens: null,\n server_tool_use: null,\n service_tier: null,\n },\n content: [],\n };\n\n for await (const chunk of stream) {\n yield chunk;\n\n try {\n switch (chunk.type) {\n case \"message_start\":\n result.id = chunk.message.id;\n result.model = chunk.message.model;\n Object.assign(result.usage, chunk.message.usage);\n break;\n case \"message_delta\":\n if (chunk.usage) {\n Object.assign(result.usage, chunk.usage);\n }\n break;\n case \"content_block_start\":\n if (result.content.length <= chunk.index) {\n result.content.push({ ...chunk.content_block });\n }\n break;\n\n case \"content_block_delta\":\n if (chunk.index < result.content.length) {\n const current = result.content[chunk.index];\n if (\n current.type === \"text\" &&\n chunk.delta.type === \"text_delta\"\n ) {\n result.content[chunk.index] = {\n type: \"text\",\n text: current.text + chunk.delta.text,\n citations: current.citations,\n };\n }\n }\n break;\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n }\n\n this._endSpan({ span, type, result });\n } else {\n const result: Completion = {\n id: \"0\",\n type: \"completion\",\n model: \"\",\n completion: \"\",\n stop_reason: null,\n };\n for await (const chunk of stream as Stream<Completion>) {\n yield chunk;\n\n try {\n result.id = chunk.id;\n result.model = chunk.model;\n\n if (chunk.stop_reason) {\n result.stop_reason = chunk.stop_reason;\n }\n if (chunk.model) {\n result.model = chunk.model;\n }\n if (chunk.completion) {\n result.completion += chunk.completion;\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n }\n\n this._endSpan({ span, type, result });\n }\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n throw error;\n }\n }\n\n return new moduleExports.APIPromise(\n client,\n (promise as any).responsePromise,\n async (client, props) => {\n const realStream = await (promise as any).parseResponse(client, props);\n\n // take the incoming stream, iterate it using our instrumented function, and wrap it in a new stream to keep the rich object type the same\n return new realStream.constructor(\n () => iterateStream.call(this, realStream),\n realStream.controller,\n );\n },\n ) as\n | APIPromise<Stream<MessageStreamEvent>>\n | APIPromise<Stream<Completion>>;\n }\n\n private _wrapPromise<T>(\n type: \"chat\" | \"completion\",\n span: Span,\n promise: Promise<T>,\n ): Promise<T> {\n return promise\n .then((result) => {\n if (type === \"chat\") {\n this._endSpan({\n type,\n span,\n result: result as Message,\n });\n } else {\n this._endSpan({\n type,\n span,\n result: result as Completion,\n });\n }\n\n return result;\n })\n .catch((error: Error) => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n\n throw error;\n });\n }\n\n private _endSpan({\n span,\n type,\n result,\n }:\n | { span: Span; type: \"chat\"; result: Message }\n | {\n span: Span;\n type: \"completion\";\n result: Completion;\n }) {\n try {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_MODEL, result.model);\n if (type === \"chat\" && result.usage) {\n span.setAttribute(\n SpanAttributes.LLM_USAGE_TOTAL_TOKENS,\n result.usage?.input_tokens + result.usage?.output_tokens,\n );\n span.setAttribute(\n ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,\n result.usage?.output_tokens,\n );\n span.setAttribute(\n ATTR_GEN_AI_USAGE_PROMPT_TOKENS,\n result.usage?.input_tokens,\n );\n }\n\n if (result.stop_reason) {\n span.setAttribute(\n `${ATTR_GEN_AI_COMPLETION}.0.finish_reason`,\n result.stop_reason,\n );\n }\n\n if (this._shouldSendPrompts()) {\n if (type === \"chat\") {\n span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, \"assistant\");\n span.setAttribute(\n `${ATTR_GEN_AI_COMPLETION}.0.content`,\n JSON.stringify(result.content),\n );\n } else {\n span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, \"assistant\");\n span.setAttribute(\n `${ATTR_GEN_AI_COMPLETION}.0.content`,\n result.completion,\n );\n }\n }\n } catch (e) {\n this._diag.debug(e);\n this._config.exceptionLogger?.(e);\n }\n\n span.end();\n }\n\n private _shouldSendPrompts() {\n const contextShouldSendPrompts = context\n .active()\n .getValue(CONTEXT_KEY_ALLOW_TRACE_CONTENT);\n\n if (contextShouldSendPrompts !== undefined) {\n return contextShouldSendPrompts;\n }\n\n return this._config.traceContent !== undefined\n ? this._config.traceContent\n : true;\n }\n}\n"],"names":["InstrumentationBase","InstrumentationNodeModuleDefinition","trace","context","safeExecuteInTheMiddle","ATTR_GEN_AI_SYSTEM","SpanAttributes","ATTR_GEN_AI_REQUEST_MODEL","ATTR_GEN_AI_REQUEST_TEMPERATURE","ATTR_GEN_AI_REQUEST_TOP_P","ATTR_GEN_AI_REQUEST_MAX_TOKENS","ATTR_GEN_AI_PROMPT","SpanKind","__asyncValues","__await","SpanStatusCode","__awaiter","ATTR_GEN_AI_RESPONSE_MODEL","ATTR_GEN_AI_USAGE_COMPLETION_TOKENS","ATTR_GEN_AI_USAGE_PROMPT_TOKENS","ATTR_GEN_AI_COMPLETION","CONTEXT_KEY_ALLOW_TRACE_CONTENT"],"mappings":";;;;;;;;;;AA+DM,MAAO,wBAAyB,SAAQA,mCAAmB,CAAA;AAG/D,IAAA,WAAA,CAAY,SAAyC,EAAE,EAAA;AACrD,QAAA,KAAK,CAAC,sCAAsC,EAAE,OAAO,EAAE,MAAM,CAAC;IAChE;IAEgB,SAAS,CAAC,SAAyC,EAAE,EAAA;AACnE,QAAA,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;IACzB;AAEO,IAAA,kBAAkB,CAAC,MAAwB,EAAA;AAChD,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA,mCAAA,CAAqC,CAAC;QAEvD,IAAI,C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AA,OAAO,wBAAwB;QACjC;AAEA,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK;AACnC,cAAE,IAAI,CAAC,OAAO,CAAC;cACb,IAAI;IACV;AACD;;;;"}
package/dist/index.mjs CHANGED
@@ -2,8 +2,9 @@ import { __awaiter, __asyncGenerator, __asyncValues, __await } from 'tslib';
2
2
  import { trace, context, SpanKind, SpanStatusCode } from '@opentelemetry/api';
3
3
  import { InstrumentationBase, InstrumentationNodeModuleDefinition, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
4
4
  import { SpanAttributes, CONTEXT_KEY_ALLOW_TRACE_CONTENT } from '@traceloop/ai-semantic-conventions';
5
+ import { ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_REQUEST_TEMPERATURE, ATTR_GEN_AI_REQUEST_TOP_P, ATTR_GEN_AI_REQUEST_MAX_TOKENS, ATTR_GEN_AI_PROMPT, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_USAGE_COMPLETION_TOKENS, ATTR_GEN_AI_USAGE_PROMPT_TOKENS, ATTR_GEN_AI_COMPLETION, ATTR_GEN_AI_SYSTEM } from '@opentelemetry/semantic-conventions/incubating';
5
6
 
6
- var version = "0.22.0";
7
+ var version = "0.22.5";
7
8
 
8
9
  class AnthropicInstrumentation extends InstrumentationBase {
9
10
  constructor(config = {}) {
@@ -79,13 +80,13 @@ class AnthropicInstrumentation extends InstrumentationBase {
79
80
  startSpan({ type, params, }) {
80
81
  var _a, _b;
81
82
  const attributes = {
82
- [SpanAttributes.LLM_SYSTEM]: "Anthropic",
83
+ [ATTR_GEN_AI_SYSTEM]: "Anthropic",
83
84
  [SpanAttributes.LLM_REQUEST_TYPE]: type,
84
85
  };
85
86
  try {
86
- attributes[SpanAttributes.LLM_REQUEST_MODEL] = params.model;
87
- attributes[SpanAttributes.LLM_REQUEST_TEMPERATURE] = params.temperature;
88
- attributes[SpanAttributes.LLM_REQUEST_TOP_P] = params.top_p;
87
+ attributes[ATTR_GEN_AI_REQUEST_MODEL] = params.model;
88
+ attributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = params.temperature;
89
+ attributes[ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;
89
90
  attributes[SpanAttributes.LLM_TOP_K] = params.top_k;
90
91
  // Handle thinking parameters (for beta messages)
91
92
  const betaParams = params;
@@ -95,11 +96,11 @@ class AnthropicInstrumentation extends InstrumentationBase {
95
96
  betaParams.thinking.budget_tokens;
96
97
  }
97
98
  if (type === "completion") {
98
- attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] =
99
+ attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
99
100
  params.max_tokens_to_sample;
100
101
  }
101
102
  else {
102
- attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] = params.max_tokens;
103
+ attributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = params.max_tokens;
103
104
  }
104
105
  if (params.extraAttributes !== undefined &&
105
106
  typeof params.extraAttributes === "object") {
@@ -112,8 +113,8 @@ class AnthropicInstrumentation extends InstrumentationBase {
112
113
  let promptIndex = 0;
113
114
  // If a system prompt is provided, it should always be first
114
115
  if ("system" in params && params.system !== undefined) {
115
- attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "system";
116
- attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] =
116
+ attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = "system";
117
+ attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] =
117
118
  typeof params.system === "string"
118
119
  ? params.system
119
120
  : JSON.stringify(params.system);
@@ -121,19 +122,21 @@ class AnthropicInstrumentation extends InstrumentationBase {
121
122
  }
122
123
  params.messages.forEach((message, index) => {
123
124
  const currentIndex = index + promptIndex;
124
- attributes[`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.role`] =
125
+ attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.role`] =
125
126
  message.role;
126
127
  if (typeof message.content === "string") {
127
- attributes[`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`] = message.content || "";
128
+ attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
129
+ message.content || "";
128
130
  }
129
131
  else {
130
- attributes[`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`] = JSON.stringify(message.content);
132
+ attributes[`${ATTR_GEN_AI_PROMPT}.${currentIndex}.content`] =
133
+ JSON.stringify(message.content);
131
134
  }
132
135
  });
133
136
  }
134
137
  else {
135
- attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "user";
136
- attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] = params.prompt;
138
+ attributes[`${ATTR_GEN_AI_PROMPT}.0.role`] = "user";
139
+ attributes[`${ATTR_GEN_AI_PROMPT}.0.content`] = params.prompt;
137
140
  }
138
141
  }
139
142
  }
@@ -163,8 +166,9 @@ class AnthropicInstrumentation extends InstrumentationBase {
163
166
  usage: {
164
167
  input_tokens: 0,
165
168
  output_tokens: 0,
166
- cache_creation_input_tokens: 0,
167
- cache_read_input_tokens: 0,
169
+ cache_creation: null,
170
+ cache_creation_input_tokens: null,
171
+ cache_read_input_tokens: null,
168
172
  server_tool_use: null,
169
173
  service_tier: null,
170
174
  },
@@ -315,23 +319,23 @@ class AnthropicInstrumentation extends InstrumentationBase {
315
319
  _endSpan({ span, type, result, }) {
316
320
  var _a, _b, _c, _d, _e, _f;
317
321
  try {
318
- span.setAttribute(SpanAttributes.LLM_RESPONSE_MODEL, result.model);
322
+ span.setAttribute(ATTR_GEN_AI_RESPONSE_MODEL, result.model);
319
323
  if (type === "chat" && result.usage) {
320
324
  span.setAttribute(SpanAttributes.LLM_USAGE_TOTAL_TOKENS, ((_a = result.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) + ((_b = result.usage) === null || _b === void 0 ? void 0 : _b.output_tokens));
321
- span.setAttribute(SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, (_c = result.usage) === null || _c === void 0 ? void 0 : _c.output_tokens);
322
- span.setAttribute(SpanAttributes.LLM_USAGE_PROMPT_TOKENS, (_d = result.usage) === null || _d === void 0 ? void 0 : _d.input_tokens);
325
+ span.setAttribute(ATTR_GEN_AI_USAGE_COMPLETION_TOKENS, (_c = result.usage) === null || _c === void 0 ? void 0 : _c.output_tokens);
326
+ span.setAttribute(ATTR_GEN_AI_USAGE_PROMPT_TOKENS, (_d = result.usage) === null || _d === void 0 ? void 0 : _d.input_tokens);
323
327
  }
324
328
  if (result.stop_reason) {
325
- span.setAttribute(`${SpanAttributes.LLM_COMPLETIONS}.0.finish_reason`, result.stop_reason);
329
+ span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.finish_reason`, result.stop_reason);
326
330
  }
327
331
  if (this._shouldSendPrompts()) {
328
332
  if (type === "chat") {
329
- span.setAttribute(`${SpanAttributes.LLM_COMPLETIONS}.0.role`, "assistant");
330
- span.setAttribute(`${SpanAttributes.LLM_COMPLETIONS}.0.content`, JSON.stringify(result.content));
333
+ span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
334
+ span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.content`, JSON.stringify(result.content));
331
335
  }
332
336
  else {
333
- span.setAttribute(`${SpanAttributes.LLM_COMPLETIONS}.0.role`, "assistant");
334
- span.setAttribute(`${SpanAttributes.LLM_COMPLETIONS}.0.content`, result.completion);
337
+ span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.role`, "assistant");
338
+ span.setAttribute(`${ATTR_GEN_AI_COMPLETION}.0.content`, result.completion);
335
339
  }
336
340
  }
337
341
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@traceloop/instrumentation-anthropic",
3
- "version": "0.22.0",
3
+ "version": "0.22.5",
4
4
  "description": "Anthropic Instrumentaion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,7 +10,7 @@
10
10
  "build": "rollup -c",
11
11
  "lint": "eslint .",
12
12
  "lint:fix": "eslint . --fix",
13
- "test": "ts-mocha -p tsconfig.json 'test/**/*.test.ts'"
13
+ "test": "ts-mocha -p tsconfig.test.json 'test/**/*.test.ts'"
14
14
  },
15
15
  "keywords": [
16
16
  "opentelemetry",
@@ -41,12 +41,12 @@
41
41
  "@opentelemetry/api": "^1.9.0",
42
42
  "@opentelemetry/core": "^2.0.1",
43
43
  "@opentelemetry/instrumentation": "^0.203.0",
44
- "@opentelemetry/semantic-conventions": "^1.36.0",
45
- "@traceloop/ai-semantic-conventions": "0.22.0",
44
+ "@opentelemetry/semantic-conventions": "^1.38.0",
45
+ "@traceloop/ai-semantic-conventions": "0.22.5",
46
46
  "tslib": "^2.8.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@anthropic-ai/sdk": "^0.56.0",
49
+ "@anthropic-ai/sdk": "^0.71.0",
50
50
  "@opentelemetry/context-async-hooks": "^2.0.1",
51
51
  "@opentelemetry/sdk-trace-node": "^2.0.1",
52
52
  "@pollyjs/adapter-fetch": "^6.0.7",
@@ -57,5 +57,5 @@
57
57
  "ts-mocha": "^11.1.0"
58
58
  },
59
59
  "homepage": "https://github.com/traceloop/openllmetry-js/tree/main/packages/instrumentation-anthropic",
60
- "gitHead": "9e28821437f261486a1d956427232e054727b296"
60
+ "gitHead": "f480743514f70ab20669987d040bfec8be33fcb4"
61
61
  }