Skip to content

Commit ff1d6a8

Browse files
committed
change test
1 parent 8528f24 commit ff1d6a8

File tree

5 files changed

+230
-163
lines changed

5 files changed

+230
-163
lines changed

packages/instrumentation-anthropic/src/instrumentation.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ export class AnthropicInstrumentation extends InstrumentationBase {
204204
};
205205
}): Span {
206206
const attributes: Attributes = {
207-
[SpanAttributes.LLM_SYSTEM]: "Anthropic",
207+
[SpanAttributes.ATTR_GEN_AI_SYSTEM]: "Anthropic",
208208
[SpanAttributes.LLM_REQUEST_TYPE]: type,
209209
};
210210

211211
try {
212-
attributes[SpanAttributes.LLM_REQUEST_MODEL] = params.model;
213-
attributes[SpanAttributes.LLM_REQUEST_TEMPERATURE] = params.temperature;
214-
attributes[SpanAttributes.LLM_REQUEST_TOP_P] = params.top_p;
212+
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MODEL] = params.model;
213+
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_TEMPERATURE] = params.temperature;
214+
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_TOP_P] = params.top_p;
215215
attributes[SpanAttributes.LLM_TOP_K] = params.top_k;
216216

217217
// Handle thinking parameters (for beta messages)
@@ -223,10 +223,10 @@ export class AnthropicInstrumentation extends InstrumentationBase {
223223
}
224224

225225
if (type === "completion") {
226-
attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] =
226+
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MAX_TOKENS] =
227227
params.max_tokens_to_sample;
228228
} else {
229-
attributes[SpanAttributes.LLM_REQUEST_MAX_TOKENS] = params.max_tokens;
229+
attributes[SpanAttributes.ATTR_GEN_AI_REQUEST_MAX_TOKENS] = params.max_tokens;
230230
}
231231

232232
if (
@@ -244,8 +244,8 @@ export class AnthropicInstrumentation extends InstrumentationBase {
244244

245245
// If a system prompt is provided, it should always be first
246246
if ("system" in params && params.system !== undefined) {
247-
attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "system";
248-
attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] =
247+
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.role`] = "system";
248+
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.content`] =
249249
typeof params.system === "string"
250250
? params.system
251251
: JSON.stringify(params.system);
@@ -254,21 +254,21 @@ export class AnthropicInstrumentation extends InstrumentationBase {
254254

255255
params.messages.forEach((message, index) => {
256256
const currentIndex = index + promptIndex;
257-
attributes[`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.role`] =
257+
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.role`] =
258258
message.role;
259259
if (typeof message.content === "string") {
260260
attributes[
261-
`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`
261+
`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`
262262
] = (message.content as string) || "";
263263
} else {
264264
attributes[
265-
`${SpanAttributes.LLM_PROMPTS}.${currentIndex}.content`
265+
`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${currentIndex}.content`
266266
] = JSON.stringify(message.content);
267267
}
268268
});
269269
} else {
270-
attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "user";
271-
attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] = params.prompt;
270+
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.role`] = "user";
271+
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.content`] = params.prompt;
272272
}
273273
}
274274
} catch (e) {
@@ -477,46 +477,46 @@ export class AnthropicInstrumentation extends InstrumentationBase {
477477
result: Completion;
478478
}) {
479479
try {
480-
span.setAttribute(SpanAttributes.LLM_RESPONSE_MODEL, result.model);
480+
span.setAttribute(SpanAttributes.ATTR_GEN_AI_RESPONSE_MODEL, result.model);
481481
if (type === "chat" && result.usage) {
482482
span.setAttribute(
483483
SpanAttributes.LLM_USAGE_TOTAL_TOKENS,
484484
result.usage?.input_tokens + result.usage?.output_tokens,
485485
);
486486
span.setAttribute(
487-
SpanAttributes.LLM_USAGE_COMPLETION_TOKENS,
487+
SpanAttributes.ATTR_GEN_AI_USAGE_COMPLETION_TOKENS,
488488
result.usage?.output_tokens,
489489
);
490490
span.setAttribute(
491-
SpanAttributes.LLM_USAGE_PROMPT_TOKENS,
491+
SpanAttributes.ATTR_GEN_AI_USAGE_PROMPT_TOKENS,
492492
result.usage?.input_tokens,
493493
);
494494
}
495495

496496
if (result.stop_reason) {
497497
span.setAttribute(
498-
`${SpanAttributes.LLM_COMPLETIONS}.0.finish_reason`,
498+
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.finish_reason`,
499499
result.stop_reason,
500500
);
501501
}
502502

503503
if (this._shouldSendPrompts()) {
504504
if (type === "chat") {
505505
span.setAttribute(
506-
`${SpanAttributes.LLM_COMPLETIONS}.0.role`,
506+
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.role`,
507507
"assistant",
508508
);
509509
span.setAttribute(
510-
`${SpanAttributes.LLM_COMPLETIONS}.0.content`,
510+
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.content`,
511511
JSON.stringify(result.content),
512512
);
513513
} else {
514514
span.setAttribute(
515-
`${SpanAttributes.LLM_COMPLETIONS}.0.role`,
515+
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.role`,
516516
"assistant",
517517
);
518518
span.setAttribute(
519-
`${SpanAttributes.LLM_COMPLETIONS}.0.content`,
519+
`${SpanAttributes.ATTR_GEN_AI_COMPLETION}.0.content`,
520520
result.completion,
521521
);
522522
}

0 commit comments

Comments
 (0)