Skip to content

Commit a0fb758

Browse files
authored
test(node): Fix flaky Anthropic integration test (#21034)
This particular test was looking up the completion span by matching on `GEN_AI_INPUT_MESSAGES_ATTRIBUTE` which is not unique. Four spans have that same input message, with varying span ordering, the find lookup could match on the wrong span which lacked `max_tokens`. The fix is to find th espan by `GEN_AI_RESPONSE_ID_ATTRIBUTE` which identifies the span better. Closes: #21029
1 parent c392487 commit a0fb758

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/anthropic

dev-packages/node-integration-tests/suites/tracing/anthropic/test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ describe('Anthropic integration', () => {
210210
span: container => {
211211
expect(container.items).toHaveLength(5);
212212
const completionSpan = container.items.find(
213-
span =>
214-
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value ===
215-
'[{"role":"user","content":"What is the capital of France?"}]',
213+
span => span.attributes[GEN_AI_RESPONSE_ID_ATTRIBUTE]?.value === 'msg_mock123',
216214
);
217215
expect(completionSpan).toBeDefined();
218216
expect(completionSpan!.name).toBe('chat claude-3-haiku-20240307');
@@ -224,6 +222,9 @@ describe('Anthropic integration', () => {
224222
expect(completionSpan!.attributes[GEN_AI_RESPONSE_MODEL_ATTRIBUTE].value).toBe('claude-3-haiku-20240307');
225223
expect(completionSpan!.attributes[GEN_AI_RESPONSE_ID_ATTRIBUTE].value).toBe('msg_mock123');
226224
expect(completionSpan!.attributes[GEN_AI_RESPONSE_TEXT_ATTRIBUTE].value).toBe('Hello from Anthropic mock!');
225+
expect(completionSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toBe(
226+
'[{"role":"user","content":"What is the capital of France?"}]',
227+
);
227228
expect(completionSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('anthropic');
228229
expect(completionSpan!.attributes[GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE].value).toBe(10);
229230
expect(completionSpan!.attributes[GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE].value).toBe(15);

0 commit comments

Comments
 (0)