|
| 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 a basic chat completion request', async () => { |
| 10 | + const runner = createRunner(__dirname) |
| 11 | + .ignore('event') |
| 12 | + .expect(envelope => { |
| 13 | + const transactionEvent = envelope[1]?.[0]?.[1]; |
| 14 | + |
| 15 | + expect(transactionEvent.transaction).toBe('GET /'); |
| 16 | + expect(transactionEvent.spans).toEqual( |
| 17 | + expect.arrayContaining([ |
| 18 | + expect.objectContaining({ |
| 19 | + data: expect.objectContaining({ |
| 20 | + 'gen_ai.operation.name': 'chat', |
| 21 | + 'sentry.op': 'gen_ai.chat', |
| 22 | + 'gen_ai.system': 'openai', |
| 23 | + 'gen_ai.request.model': 'gpt-3.5-turbo', |
| 24 | + 'gen_ai.request.temperature': 0.7, |
| 25 | + 'gen_ai.response.model': 'gpt-3.5-turbo', |
| 26 | + 'gen_ai.response.id': 'chatcmpl-mock123', |
| 27 | + 'gen_ai.usage.input_tokens': 10, |
| 28 | + 'gen_ai.usage.output_tokens': 15, |
| 29 | + 'gen_ai.usage.total_tokens': 25, |
| 30 | + 'gen_ai.response.finish_reasons': '["stop"]', |
| 31 | + }), |
| 32 | + description: 'chat gpt-3.5-turbo', |
| 33 | + op: 'gen_ai.chat', |
| 34 | + origin: 'manual', |
| 35 | + }), |
| 36 | + ]), |
| 37 | + ); |
| 38 | + }) |
| 39 | + .start(); |
| 40 | + await runner.makeRequest('get', '/'); |
| 41 | + await runner.completed(); |
| 42 | +}); |
0 commit comments