|
| 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 LangChain instrumentation sends gen_ai transactions', async ({ getLocalTestUrl, page }) => { |
| 11 | + const transactionPromise = waitForTransactionRequest(page, event => { |
| 12 | + return !!event.transaction?.includes('claude-3-haiku-20240307'); |
| 13 | + }); |
| 14 | + |
| 15 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 16 | + await page.goto(url); |
| 17 | + |
| 18 | + const req = await transactionPromise; |
| 19 | + |
| 20 | + const eventData = envelopeRequestParser(req); |
| 21 | + |
| 22 | + // Verify it's a gen_ai transaction |
| 23 | + expect(eventData.transaction).toBe('chat claude-3-haiku-20240307'); |
| 24 | + expect(eventData.contexts?.trace?.op).toBe('gen_ai.chat'); |
| 25 | + expect(eventData.contexts?.trace?.origin).toBe('auto.ai.langchain'); |
| 26 | + expect(eventData.contexts?.trace?.data).toMatchObject({ |
| 27 | + 'gen_ai.operation.name': 'chat', |
| 28 | + 'gen_ai.system': 'anthropic', |
| 29 | + 'gen_ai.request.model': 'claude-3-haiku-20240307', |
| 30 | + 'gen_ai.request.temperature': 0.7, |
| 31 | + 'gen_ai.response.model': 'claude-3-haiku-20240307', |
| 32 | + 'gen_ai.response.id': 'msg_mock123', |
| 33 | + 'gen_ai.usage.input_tokens': 10, |
| 34 | + 'gen_ai.usage.output_tokens': 15, |
| 35 | + 'gen_ai.usage.total_tokens': 25, |
| 36 | + }); |
| 37 | +}); |
0 commit comments