Skip to content

Commit 2004e2d

Browse files
nirgaclaude
andcommitted
style: apply prettier formatting
- Format import statement in instrumentation.ts - Improve formatting in test file for better readability - Consistent code style throughout the project 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 55e294e commit 2004e2d

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

packages/instrumentation-anthropic/src/instrumentation.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ import type {
4545
Message,
4646
MessageStreamEvent,
4747
} from "@anthropic-ai/sdk/resources/messages";
48-
import type {
49-
MessageCreateParamsNonStreaming as BetaMessageCreateParamsNonStreaming,
50-
} from "@anthropic-ai/sdk/resources/beta/messages";
48+
import type { MessageCreateParamsNonStreaming as BetaMessageCreateParamsNonStreaming } from "@anthropic-ai/sdk/resources/beta/messages";
5149
import type { Stream } from "@anthropic-ai/sdk/streaming";
5250
import type { APIPromise, BaseAnthropic } from "@anthropic-ai/sdk";
5351

@@ -220,7 +218,8 @@ export class AnthropicInstrumentation extends InstrumentationBase {
220218
const betaParams = params as BetaMessageCreateParamsNonStreaming;
221219
if (betaParams.thinking && betaParams.thinking.type === "enabled") {
222220
attributes["llm.request.thinking.type"] = betaParams.thinking.type;
223-
attributes["llm.request.thinking.budget_tokens"] = betaParams.thinking.budget_tokens;
221+
attributes["llm.request.thinking.budget_tokens"] =
222+
betaParams.thinking.budget_tokens;
224223
}
225224

226225
if (type === "completion") {

packages/instrumentation-anthropic/test/instrumentation.test.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,12 @@ describe("Test Anthropic instrumentation", async function () {
332332
it("should set attributes in span for beta messages with thinking", async () => {
333333
const message = await anthropic.beta.messages.create({
334334
max_tokens: 2048,
335-
betas: ['interleaved-thinking-2025-05-14'],
335+
betas: ["interleaved-thinking-2025-05-14"],
336336
messages: [
337-
{ role: "user", content: "What is 2+2? Think through this step by step." },
337+
{
338+
role: "user",
339+
content: "What is 2+2? Think through this step by step.",
340+
},
338341
],
339342
model: "claude-opus-4-1-20250805",
340343
thinking: {
@@ -360,7 +363,7 @@ describe("Test Anthropic instrumentation", async function () {
360363
chatSpan.attributes[`${SpanAttributes.LLM_REQUEST_MAX_TOKENS}`],
361364
2048,
362365
);
363-
366+
364367
// Check if thinking parameters are captured (these will fail initially)
365368
assert.strictEqual(
366369
chatSpan.attributes["llm.request.thinking.type"],
@@ -382,28 +385,42 @@ describe("Test Anthropic instrumentation", async function () {
382385
);
383386

384387
// Check that we capture both thinking and regular content blocks
385-
const content = JSON.parse(chatSpan.attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.content`] as string);
388+
const content = JSON.parse(
389+
chatSpan.attributes[
390+
`${SpanAttributes.LLM_COMPLETIONS}.0.content`
391+
] as string,
392+
);
386393
assert.ok(Array.isArray(content));
387-
394+
388395
interface ContentBlock {
389396
type: string;
390397
thinking?: string;
391398
text?: string;
392399
}
393-
394-
const thinkingBlock = content.find((block: ContentBlock) => block.type === "thinking");
395-
const textBlock = content.find((block: ContentBlock) => block.type === "text");
396-
400+
401+
const thinkingBlock = content.find(
402+
(block: ContentBlock) => block.type === "thinking",
403+
);
404+
const textBlock = content.find(
405+
(block: ContentBlock) => block.type === "text",
406+
);
407+
397408
assert.ok(thinkingBlock, "Should contain a thinking block");
398-
assert.ok(thinkingBlock.thinking, "Thinking block should have thinking content");
409+
assert.ok(
410+
thinkingBlock.thinking,
411+
"Thinking block should have thinking content",
412+
);
399413
assert.ok(textBlock, "Should contain a text block");
400414
assert.ok(textBlock.text, "Text block should have text content");
401415

402416
// Verify token usage includes thinking tokens
403-
const completionTokens = chatSpan.attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`];
404-
const promptTokens = chatSpan.attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`];
405-
const totalTokens = chatSpan.attributes[`${SpanAttributes.LLM_USAGE_TOTAL_TOKENS}`];
406-
417+
const completionTokens =
418+
chatSpan.attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`];
419+
const promptTokens =
420+
chatSpan.attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`];
421+
const totalTokens =
422+
chatSpan.attributes[`${SpanAttributes.LLM_USAGE_TOTAL_TOKENS}`];
423+
407424
assert.ok(completionTokens && +completionTokens > 0);
408425
assert.ok(promptTokens && +promptTokens > 0);
409426
assert.equal(+promptTokens + +completionTokens, totalTokens);

0 commit comments

Comments
 (0)