|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | +import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; |
| 3 | +import { createRunner } from '../../../runner'; |
| 4 | + |
| 5 | +it('D1 database queries create spans with correct attributes', async ({ signal }) => { |
| 6 | + const runner = createRunner(__dirname) |
| 7 | + .expect(envelope => { |
| 8 | + const transactionEvent = envelope[1]?.[0]?.[1]; |
| 9 | + expect(transactionEvent).toEqual( |
| 10 | + expect.objectContaining({ |
| 11 | + type: 'transaction', |
| 12 | + transaction: 'GET /init', |
| 13 | + spans: [ |
| 14 | + { |
| 15 | + data: { |
| 16 | + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.query', |
| 17 | + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.d1', |
| 18 | + 'cloudflare.d1.query_type': 'run', |
| 19 | + 'cloudflare.d1.duration': expect.any(Number), |
| 20 | + 'cloudflare.d1.rows_read': expect.any(Number), |
| 21 | + 'cloudflare.d1.rows_written': expect.any(Number), |
| 22 | + }, |
| 23 | + description: 'INSERT INTO users (name) VALUES (?)', |
| 24 | + op: 'db.query', |
| 25 | + origin: 'auto.db.cloudflare.d1', |
| 26 | + parent_span_id: expect.any(String), |
| 27 | + span_id: expect.any(String), |
| 28 | + start_timestamp: expect.any(Number), |
| 29 | + timestamp: expect.any(Number), |
| 30 | + trace_id: expect.any(String), |
| 31 | + }, |
| 32 | + ], |
| 33 | + }), |
| 34 | + ); |
| 35 | + }) |
| 36 | + .expect(envelope => { |
| 37 | + const transactionEvent = envelope[1]?.[0]?.[1]; |
| 38 | + expect(transactionEvent).toEqual( |
| 39 | + expect.objectContaining({ |
| 40 | + type: 'transaction', |
| 41 | + transaction: 'GET /query', |
| 42 | + spans: [ |
| 43 | + { |
| 44 | + data: { |
| 45 | + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.query', |
| 46 | + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.d1', |
| 47 | + 'cloudflare.d1.query_type': 'first', |
| 48 | + }, |
| 49 | + description: 'SELECT * FROM users WHERE name = ?', |
| 50 | + op: 'db.query', |
| 51 | + origin: 'auto.db.cloudflare.d1', |
| 52 | + parent_span_id: expect.any(String), |
| 53 | + span_id: expect.any(String), |
| 54 | + start_timestamp: expect.any(Number), |
| 55 | + timestamp: expect.any(Number), |
| 56 | + trace_id: expect.any(String), |
| 57 | + }, |
| 58 | + ], |
| 59 | + }), |
| 60 | + ); |
| 61 | + }) |
| 62 | + .start(signal); |
| 63 | + |
| 64 | + await runner.makeRequest('get', '/init'); |
| 65 | + await runner.makeRequest('get', '/query'); |
| 66 | + await runner.completed(); |
| 67 | +}); |
0 commit comments