|
| 1 | +import { describe,expect } from 'vitest'; |
| 2 | +import { createEsmAndCjsTests } from '../../../../utils/runner'; |
| 3 | +import { createTestServer } from '../../../../utils/server'; |
| 4 | + |
| 5 | +describe('outgoing http requests with tracing & spans disabled xxx', () => { |
| 6 | + createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => { |
| 7 | + test('outgoing http requests are correctly instrumented with tracing & spans disabled', async () => { |
| 8 | + expect.assertions(11); |
| 9 | + |
| 10 | + const [SERVER_URL, closeTestServer] = await createTestServer() |
| 11 | + .get('/api/v0', headers => { |
| 12 | + expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/)); |
| 13 | + expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000'); |
| 14 | + expect(headers['baggage']).toEqual(expect.any(String)); |
| 15 | + }) |
| 16 | + .get('/api/v1', headers => { |
| 17 | + expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/)); |
| 18 | + expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000'); |
| 19 | + expect(headers['baggage']).toEqual(expect.any(String)); |
| 20 | + }) |
| 21 | + .get('/api/v2', headers => { |
| 22 | + expect(headers['baggage']).toBeUndefined(); |
| 23 | + expect(headers['sentry-trace']).toBeUndefined(); |
| 24 | + }) |
| 25 | + .get('/api/v3', headers => { |
| 26 | + expect(headers['baggage']).toBeUndefined(); |
| 27 | + expect(headers['sentry-trace']).toBeUndefined(); |
| 28 | + }) |
| 29 | + .start(); |
| 30 | + |
| 31 | + await createRunner() |
| 32 | + .withEnv({ SERVER_URL }) |
| 33 | + .ensureNoErrorOutput() |
| 34 | + .expect({ |
| 35 | + event: { |
| 36 | + exception: { |
| 37 | + values: [ |
| 38 | + { |
| 39 | + type: 'Error', |
| 40 | + value: 'foo', |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + breadcrumbs: [ |
| 45 | + { |
| 46 | + message: 'manual breadcrumb', |
| 47 | + timestamp: expect.any(Number), |
| 48 | + }, |
| 49 | + { |
| 50 | + category: 'http', |
| 51 | + data: { |
| 52 | + 'http.method': 'GET', |
| 53 | + url: `${SERVER_URL}/api/v0`, |
| 54 | + status_code: 200, |
| 55 | + ADDED_PATH: '/api/v0', |
| 56 | + }, |
| 57 | + timestamp: expect.any(Number), |
| 58 | + type: 'http', |
| 59 | + }, |
| 60 | + { |
| 61 | + category: 'http', |
| 62 | + data: { |
| 63 | + 'http.method': 'GET', |
| 64 | + url: `${SERVER_URL}/api/v1`, |
| 65 | + status_code: 200, |
| 66 | + ADDED_PATH: '/api/v1', |
| 67 | + }, |
| 68 | + timestamp: expect.any(Number), |
| 69 | + type: 'http', |
| 70 | + }, |
| 71 | + { |
| 72 | + category: 'http', |
| 73 | + data: { |
| 74 | + 'http.method': 'GET', |
| 75 | + url: `${SERVER_URL}/api/v2`, |
| 76 | + status_code: 200, |
| 77 | + ADDED_PATH: '/api/v2', |
| 78 | + }, |
| 79 | + timestamp: expect.any(Number), |
| 80 | + type: 'http', |
| 81 | + }, |
| 82 | + { |
| 83 | + category: 'http', |
| 84 | + data: { |
| 85 | + 'http.method': 'GET', |
| 86 | + url: `${SERVER_URL}/api/v3`, |
| 87 | + status_code: 200, |
| 88 | + ADDED_PATH: '/api/v3', |
| 89 | + }, |
| 90 | + timestamp: expect.any(Number), |
| 91 | + type: 'http', |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + }) |
| 96 | + .start() |
| 97 | + .completed(); |
| 98 | + |
| 99 | + closeTestServer(); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments