|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 3 | +import { envelopeRequestParser, waitForTransactionRequest } from '../../../../utils/helpers'; |
| 4 | + |
| 5 | +// These tests are not exhaustive because the instrumentation is |
| 6 | +// already tested in the node integration tests and we merely |
| 7 | +// want to test that the instrumentation does not crash in the browser |
| 8 | +// and that gen_ai transactions are sent. |
| 9 | + |
| 10 | +sentryTest('manual LangGraph instrumentation sends gen_ai transactions', async ({ getLocalTestUrl, page }) => { |
| 11 | + const createTransactionPromise = waitForTransactionRequest(page, event => { |
| 12 | + return !!event.transaction?.includes('create_agent mock-graph'); |
| 13 | + }); |
| 14 | + |
| 15 | + const invokeTransactionPromise = waitForTransactionRequest(page, event => { |
| 16 | + return !!event.transaction?.includes('invoke_agent mock-graph'); |
| 17 | + }); |
| 18 | + |
| 19 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 20 | + await page.goto(url); |
| 21 | + |
| 22 | + const createReq = await createTransactionPromise; |
| 23 | + const invokeReq = await invokeTransactionPromise; |
| 24 | + |
| 25 | + const createEventData = envelopeRequestParser(createReq); |
| 26 | + const invokeEventData = envelopeRequestParser(invokeReq); |
| 27 | + |
| 28 | + // Verify create_agent transaction |
| 29 | + expect(createEventData.transaction).toBe('create_agent mock-graph'); |
| 30 | + expect(createEventData.contexts?.trace?.op).toBe('gen_ai.create_agent'); |
| 31 | + expect(createEventData.contexts?.trace?.origin).toBe('auto.ai.langgraph'); |
| 32 | + expect(createEventData.contexts?.trace?.data).toMatchObject({ |
| 33 | + 'gen_ai.operation.name': 'create_agent', |
| 34 | + 'gen_ai.agent.name': 'mock-graph', |
| 35 | + }); |
| 36 | + |
| 37 | + // Verify invoke_agent transaction |
| 38 | + expect(invokeEventData.transaction).toBe('invoke_agent mock-graph'); |
| 39 | + expect(invokeEventData.contexts?.trace?.op).toBe('gen_ai.invoke_agent'); |
| 40 | + expect(invokeEventData.contexts?.trace?.origin).toBe('auto.ai.langgraph'); |
| 41 | + expect(invokeEventData.contexts?.trace?.data).toMatchObject({ |
| 42 | + 'gen_ai.operation.name': 'invoke_agent', |
| 43 | + 'gen_ai.agent.name': 'mock-graph', |
| 44 | + }); |
| 45 | +}); |
0 commit comments