|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/event-proxy-server'; |
| 3 | + |
| 4 | +test('Should record exceptions captured inside handlers', async ({ request }) => { |
| 5 | + const errorEventPromise = waitForError('node-express-cjs-preload', errorEvent => { |
| 6 | + return !!errorEvent?.exception?.values?.[0]?.value?.includes('This is an error'); |
| 7 | + }); |
| 8 | + |
| 9 | + await request.get('/test-error'); |
| 10 | + |
| 11 | + await expect(errorEventPromise).resolves.toBeDefined(); |
| 12 | +}); |
| 13 | + |
| 14 | +test('Should record a transaction for a parameterless route', async ({ request }) => { |
| 15 | + const transactionEventPromise = waitForTransaction('node-express-cjs-preload', transactionEvent => { |
| 16 | + return transactionEvent?.transaction === 'GET /test-success'; |
| 17 | + }); |
| 18 | + |
| 19 | + await request.get('/test-success'); |
| 20 | + |
| 21 | + await expect(transactionEventPromise).resolves.toBeDefined(); |
| 22 | +}); |
| 23 | + |
| 24 | +test('Should record a transaction for route with parameters', async ({ request }) => { |
| 25 | + const transactionEventPromise = waitForTransaction('node-express-cjs-preload', transactionEvent => { |
| 26 | + return transactionEvent.contexts?.trace?.data?.['http.target'] === '/test-transaction/1'; |
| 27 | + }); |
| 28 | + |
| 29 | + await request.get('/test-transaction/1'); |
| 30 | + |
| 31 | + const transactionEvent = await transactionEventPromise; |
| 32 | + |
| 33 | + expect(transactionEvent).toBeDefined(); |
| 34 | + expect(transactionEvent.transaction).toEqual('GET /test-transaction/:param'); |
| 35 | + expect(transactionEvent.contexts?.trace?.data).toEqual( |
| 36 | + expect.objectContaining({ |
| 37 | + 'http.flavor': '1.1', |
| 38 | + 'http.host': 'localhost:3030', |
| 39 | + 'http.method': 'GET', |
| 40 | + 'http.response.status_code': 200, |
| 41 | + 'http.route': '/test-transaction/:param', |
| 42 | + 'http.scheme': 'http', |
| 43 | + 'http.status_code': 200, |
| 44 | + 'http.status_text': 'OK', |
| 45 | + 'http.target': '/test-transaction/1', |
| 46 | + 'http.url': 'http://localhost:3030/test-transaction/1', |
| 47 | + 'http.user_agent': expect.any(String), |
| 48 | + 'net.host.ip': expect.any(String), |
| 49 | + 'net.host.name': 'localhost', |
| 50 | + 'net.host.port': 3030, |
| 51 | + 'net.peer.ip': expect.any(String), |
| 52 | + 'net.peer.port': expect.any(Number), |
| 53 | + 'net.transport': 'ip_tcp', |
| 54 | + 'otel.kind': 'SERVER', |
| 55 | + 'sentry.op': 'http.server', |
| 56 | + 'sentry.origin': 'auto.http.otel.http', |
| 57 | + 'sentry.sample_rate': 1, |
| 58 | + 'sentry.source': 'route', |
| 59 | + url: 'http://localhost:3030/test-transaction/1', |
| 60 | + }), |
| 61 | + ); |
| 62 | + |
| 63 | + const spans = transactionEvent.spans || []; |
| 64 | + expect(spans).toContainEqual({ |
| 65 | + data: { |
| 66 | + 'express.name': 'query', |
| 67 | + 'express.type': 'middleware', |
| 68 | + 'http.route': '/', |
| 69 | + 'otel.kind': 'INTERNAL', |
| 70 | + 'sentry.origin': 'auto.http.otel.express', |
| 71 | + 'sentry.op': 'middleware.express', |
| 72 | + }, |
| 73 | + op: 'middleware.express', |
| 74 | + description: 'query', |
| 75 | + origin: 'auto.http.otel.express', |
| 76 | + parent_span_id: expect.any(String), |
| 77 | + span_id: expect.any(String), |
| 78 | + start_timestamp: expect.any(Number), |
| 79 | + status: 'ok', |
| 80 | + timestamp: expect.any(Number), |
| 81 | + trace_id: expect.any(String), |
| 82 | + }); |
| 83 | + |
| 84 | + expect(spans).toContainEqual({ |
| 85 | + data: { |
| 86 | + 'express.name': 'expressInit', |
| 87 | + 'express.type': 'middleware', |
| 88 | + 'http.route': '/', |
| 89 | + 'otel.kind': 'INTERNAL', |
| 90 | + 'sentry.origin': 'auto.http.otel.express', |
| 91 | + 'sentry.op': 'middleware.express', |
| 92 | + }, |
| 93 | + op: 'middleware.express', |
| 94 | + description: 'expressInit', |
| 95 | + origin: 'auto.http.otel.express', |
| 96 | + parent_span_id: expect.any(String), |
| 97 | + span_id: expect.any(String), |
| 98 | + start_timestamp: expect.any(Number), |
| 99 | + status: 'ok', |
| 100 | + timestamp: expect.any(Number), |
| 101 | + trace_id: expect.any(String), |
| 102 | + }); |
| 103 | + |
| 104 | + expect(spans).toContainEqual({ |
| 105 | + data: { |
| 106 | + 'express.name': '/test-transaction/:param', |
| 107 | + 'express.type': 'request_handler', |
| 108 | + 'http.route': '/test-transaction/:param', |
| 109 | + 'otel.kind': 'INTERNAL', |
| 110 | + 'sentry.origin': 'auto.http.otel.express', |
| 111 | + 'sentry.op': 'request_handler.express', |
| 112 | + }, |
| 113 | + op: 'request_handler.express', |
| 114 | + description: '/test-transaction/:param', |
| 115 | + origin: 'auto.http.otel.express', |
| 116 | + parent_span_id: expect.any(String), |
| 117 | + span_id: expect.any(String), |
| 118 | + start_timestamp: expect.any(Number), |
| 119 | + status: 'ok', |
| 120 | + timestamp: expect.any(Number), |
| 121 | + trace_id: expect.any(String), |
| 122 | + }); |
| 123 | +}); |
0 commit comments