|
1 | 1 | import { Event } from '@sentry/types';
|
| 2 | +import { makeDsn } from '@sentry/utils'; |
2 | 3 |
|
3 | 4 | import { createReplayEnvelope } from '../../../src/util/createReplayEnvelope';
|
4 | 5 |
|
5 | 6 | describe('createReplayEnvelope', () => {
|
| 7 | + const REPLAY_ID = 'MY_REPLAY_ID'; |
| 8 | + |
| 9 | + const replayEvent = { |
| 10 | + type: 'replay_event', |
| 11 | + timestamp: 1670837008.634, |
| 12 | + error_ids: ['errorId'], |
| 13 | + trace_ids: ['traceId'], |
| 14 | + urls: ['https://example.com'], |
| 15 | + replay_id: REPLAY_ID, |
| 16 | + segment_id: 3, |
| 17 | + platform: 'javascript', |
| 18 | + event_id: REPLAY_ID, |
| 19 | + environment: 'production', |
| 20 | + sdk: { |
| 21 | + integrations: ['BrowserTracing', 'Replay'], |
| 22 | + name: 'sentry.javascript.browser', |
| 23 | + version: '7.25.0', |
| 24 | + }, |
| 25 | + tags: { |
| 26 | + sessionSampleRate: 1, |
| 27 | + errorSampleRate: 0, |
| 28 | + replayType: 'error', |
| 29 | + }, |
| 30 | + }; |
| 31 | + |
| 32 | + const payloadWithSequence = 'payload'; |
| 33 | + |
| 34 | + const dsn = makeDsn({ |
| 35 | + host: 'sentry.io', |
| 36 | + pass: 'xyz', |
| 37 | + port: '1234', |
| 38 | + projectId: '123', |
| 39 | + protocol: 'https', |
| 40 | + publicKey: 'abc', |
| 41 | + }); |
| 42 | + |
6 | 43 | it('creates an envelope for a given Replay event', () => {
|
7 |
| - const replayId = '1234'; |
8 |
| - const replayEvent = { |
9 |
| - type: 'replay_event', |
10 |
| - timestamp: 1670837008.634, |
11 |
| - error_ids: ['errorId'], |
12 |
| - trace_ids: ['traceId'], |
13 |
| - urls: ['https://example.com'], |
14 |
| - replay_id: 'eventId', |
15 |
| - segment_id: 3, |
16 |
| - platform: 'javascript', |
17 |
| - event_id: 'eventId', |
18 |
| - environment: 'production', |
19 |
| - sdk: { |
20 |
| - integrations: ['BrowserTracing', 'Replay'], |
21 |
| - name: 'sentry.javascript.browser', |
22 |
| - version: '7.25.0', |
23 |
| - }, |
24 |
| - tags: { |
25 |
| - sessionSampleRate: 1, |
26 |
| - errorSampleRate: 0, |
27 |
| - replayType: 'error', |
| 44 | + const envelope = createReplayEnvelope(replayEvent as Event, payloadWithSequence, dsn); |
| 45 | + |
| 46 | + expect(envelope).toEqual([ |
| 47 | + { |
| 48 | + event_id: REPLAY_ID, |
| 49 | + sdk: { name: 'sentry.javascript.browser', version: '7.25.0' }, |
| 50 | + sent_at: expect.any(String), |
28 | 51 | },
|
29 |
| - }; |
30 |
| - const payloadWithSequence = 'payload'; |
| 52 | + [ |
| 53 | + [ |
| 54 | + { type: 'replay_event' }, |
| 55 | + { |
| 56 | + environment: 'production', |
| 57 | + error_ids: ['errorId'], |
| 58 | + event_id: REPLAY_ID, |
| 59 | + platform: 'javascript', |
| 60 | + replay_id: REPLAY_ID, |
| 61 | + sdk: { integrations: ['BrowserTracing', 'Replay'], name: 'sentry.javascript.browser', version: '7.25.0' }, |
| 62 | + segment_id: 3, |
| 63 | + tags: { errorSampleRate: 0, replayType: 'error', sessionSampleRate: 1 }, |
| 64 | + timestamp: 1670837008.634, |
| 65 | + trace_ids: ['traceId'], |
| 66 | + type: 'replay_event', |
| 67 | + urls: ['https://example.com'], |
| 68 | + }, |
| 69 | + ], |
| 70 | + [{ length: 7, type: 'replay_recording' }, 'payload'], |
| 71 | + ], |
| 72 | + ]); |
| 73 | + }); |
31 | 74 |
|
32 |
| - const envelope = createReplayEnvelope(replayId, replayEvent as Event, payloadWithSequence); |
| 75 | + it('creates an envelope with the `dsn` key in the header if `tunnel` is specified', () => { |
| 76 | + const envelope = createReplayEnvelope(replayEvent as Event, payloadWithSequence, dsn, '/my-tunnel-endpoint'); |
33 | 77 |
|
34 | 78 | expect(envelope).toEqual([
|
35 | 79 | {
|
36 |
| - event_id: '1234', |
| 80 | + event_id: REPLAY_ID, |
37 | 81 | sdk: { name: 'sentry.javascript.browser', version: '7.25.0' },
|
38 | 82 | sent_at: expect.any(String),
|
| 83 | + dsn: 'https://[email protected]:1234/123', |
39 | 84 | },
|
40 | 85 | [
|
41 | 86 | [
|
42 | 87 | { type: 'replay_event' },
|
43 | 88 | {
|
44 | 89 | environment: 'production',
|
45 | 90 | error_ids: ['errorId'],
|
46 |
| - event_id: 'eventId', |
| 91 | + event_id: REPLAY_ID, |
47 | 92 | platform: 'javascript',
|
48 |
| - replay_id: 'eventId', |
| 93 | + replay_id: REPLAY_ID, |
49 | 94 | sdk: { integrations: ['BrowserTracing', 'Replay'], name: 'sentry.javascript.browser', version: '7.25.0' },
|
50 | 95 | segment_id: 3,
|
51 | 96 | tags: { errorSampleRate: 0, replayType: 'error', sessionSampleRate: 1 },
|
|
0 commit comments