|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | +import { createRunner } from '../../../runner'; |
| 3 | + |
| 4 | +// These tests are not exhaustive because the instrumentation is |
| 5 | +// already tested in the node integration tests and we merely |
| 6 | +// want to test that the instrumentation does not break in our |
| 7 | +// cloudflare SDK. |
| 8 | + |
| 9 | +it('traces langgraph compile and invoke operations', async ({ signal }) => { |
| 10 | + const runner = createRunner(__dirname) |
| 11 | + .ignore('event') |
| 12 | + .expect(envelope => { |
| 13 | + const transactionEvent = envelope[1]?.[0]?.[1] as any; |
| 14 | + |
| 15 | + expect(transactionEvent.transaction).toBe('GET /'); |
| 16 | + |
| 17 | + // Check create_agent span |
| 18 | + const createAgentSpan = transactionEvent.spans.find((span: any) => span.op === 'gen_ai.create_agent'); |
| 19 | + expect(createAgentSpan).toMatchObject({ |
| 20 | + data: { |
| 21 | + 'gen_ai.operation.name': 'create_agent', |
| 22 | + 'sentry.op': 'gen_ai.create_agent', |
| 23 | + 'sentry.origin': 'auto.ai.langgraph', |
| 24 | + 'gen_ai.agent.name': 'weather_assistant', |
| 25 | + }, |
| 26 | + description: 'create_agent weather_assistant', |
| 27 | + op: 'gen_ai.create_agent', |
| 28 | + origin: 'auto.ai.langgraph', |
| 29 | + }); |
| 30 | + |
| 31 | + // Check invoke_agent span |
| 32 | + const invokeAgentSpan = transactionEvent.spans.find((span: any) => span.op === 'gen_ai.invoke_agent'); |
| 33 | + expect(invokeAgentSpan).toMatchObject({ |
| 34 | + data: expect.objectContaining({ |
| 35 | + 'gen_ai.operation.name': 'invoke_agent', |
| 36 | + 'sentry.op': 'gen_ai.invoke_agent', |
| 37 | + 'sentry.origin': 'auto.ai.langgraph', |
| 38 | + 'gen_ai.agent.name': 'weather_assistant', |
| 39 | + 'gen_ai.pipeline.name': 'weather_assistant', |
| 40 | + 'gen_ai.request.messages': '[{"role":"user","content":"What is the weather in SF?"}]', |
| 41 | + 'gen_ai.response.model': 'mock-model', |
| 42 | + 'gen_ai.usage.input_tokens': 20, |
| 43 | + 'gen_ai.usage.output_tokens': 10, |
| 44 | + 'gen_ai.usage.total_tokens': 30, |
| 45 | + }), |
| 46 | + description: 'invoke_agent weather_assistant', |
| 47 | + op: 'gen_ai.invoke_agent', |
| 48 | + origin: 'auto.ai.langgraph', |
| 49 | + }); |
| 50 | + |
| 51 | + // Verify tools are captured |
| 52 | + if (invokeAgentSpan.data['gen_ai.request.available_tools']) { |
| 53 | + expect(invokeAgentSpan.data['gen_ai.request.available_tools']).toMatch(/get_weather/); |
| 54 | + } |
| 55 | + }) |
| 56 | + .start(signal); |
| 57 | + await runner.makeRequest('get', '/'); |
| 58 | + await runner.completed(); |
| 59 | +}); |
0 commit comments