|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('GET command emits an http.server transaction containing a db.redis child span', async ({ baseURL }) => { |
| 5 | + // Each incoming request gets a Sentry http.server transaction (via the |
| 6 | + // default denoServeIntegration); the redis command runs inside it, so the |
| 7 | + // child span attaches to that transaction. |
| 8 | + const transactionPromise = waitForTransaction('deno-redis', event => { |
| 9 | + return ( |
| 10 | + event?.contexts?.trace?.op === 'http.server' && |
| 11 | + (event.request?.url ?? '').includes('/redis-get') && |
| 12 | + (event.spans?.some(span => span.op === 'db.redis') ?? false) |
| 13 | + ); |
| 14 | + }); |
| 15 | + |
| 16 | + const res = await fetch(`${baseURL}/redis-get?key=cache:user:42`); |
| 17 | + expect(res.status).toBe(200); |
| 18 | + await res.json(); |
| 19 | + |
| 20 | + const transaction = await transactionPromise; |
| 21 | + const redisSpan = transaction.spans!.find(span => span.op === 'db.redis'); |
| 22 | + expect(redisSpan).toBeDefined(); |
| 23 | + expect(redisSpan!.description).toBe('redis-GET'); |
| 24 | + expect(redisSpan!.data?.['db.system']).toBe('redis'); |
| 25 | + // Statement omits the value; for GET the only allowed arg is the key. |
| 26 | + expect(redisSpan!.data?.['db.statement']).toBe('GET cache:user:42'); |
| 27 | + expect(redisSpan!.data?.['net.peer.port']).toBe(6379); |
| 28 | +}); |
| 29 | + |
| 30 | +test('SET then GET emit two db.redis child spans on the same transaction', async ({ baseURL }) => { |
| 31 | + const transactionPromise = waitForTransaction('deno-redis', event => { |
| 32 | + return ( |
| 33 | + event?.contexts?.trace?.op === 'http.server' && |
| 34 | + (event.request?.url ?? '').includes('/redis-set-get') && |
| 35 | + (event.spans?.filter(span => span.op === 'db.redis').length ?? 0) >= 2 |
| 36 | + ); |
| 37 | + }); |
| 38 | + |
| 39 | + const res = await fetch(`${baseURL}/redis-set-get?key=cache:greeting&value=hello`); |
| 40 | + expect(res.status).toBe(200); |
| 41 | + await res.json(); |
| 42 | + |
| 43 | + const transaction = await transactionPromise; |
| 44 | + const redisSpans = transaction.spans!.filter(span => span.op === 'db.redis'); |
| 45 | + expect(redisSpans.length).toBeGreaterThanOrEqual(2); |
| 46 | + const ops = redisSpans.map(s => s.description); |
| 47 | + expect(ops).toContain('redis-SET'); |
| 48 | + expect(ops).toContain('redis-GET'); |
| 49 | +}); |
| 50 | + |
| 51 | +test('MULTI batch emits a PIPELINE/MULTI batch span', async ({ baseURL }) => { |
| 52 | + const transactionPromise = waitForTransaction('deno-redis', event => { |
| 53 | + return ( |
| 54 | + event?.contexts?.trace?.op === 'http.server' && |
| 55 | + (event.request?.url ?? '').includes('/redis-multi') && |
| 56 | + (event.spans?.some(span => span.description === 'MULTI' || span.description === 'PIPELINE') ?? false) |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + const res = await fetch(`${baseURL}/redis-multi`); |
| 61 | + expect(res.status).toBe(200); |
| 62 | + await res.json(); |
| 63 | + |
| 64 | + const transaction = await transactionPromise; |
| 65 | + const batchSpan = transaction.spans!.find( |
| 66 | + span => span.description === 'MULTI' || span.description === 'PIPELINE', |
| 67 | + ); |
| 68 | + expect(batchSpan).toBeDefined(); |
| 69 | + expect(batchSpan!.op).toBe('db.redis'); |
| 70 | + expect(batchSpan!.data?.['db.system']).toBe('redis'); |
| 71 | +}); |
0 commit comments