|
1 | | -import type { Event, EventEnvelope } from '@sentry/types'; |
| 1 | +import type { Event, EventEnvelope, SpanAttributes } from '@sentry/types'; |
2 | 2 |
|
| 3 | +import { |
| 4 | + SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME, |
| 5 | + SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT, |
| 6 | + SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE, |
| 7 | + spanToJSON, |
| 8 | +} from '@sentry/core'; |
| 9 | +import { SentrySpan } from '@sentry/core'; |
3 | 10 | import { |
4 | 11 | addItemToEnvelope, |
5 | 12 | createEnvelope, |
| 13 | + createSpanEnvelopeItem, |
6 | 14 | forEachEnvelopeItem, |
7 | 15 | parseEnvelope, |
8 | 16 | serializeEnvelope, |
9 | 17 | } from '../src/envelope'; |
| 18 | +import { dropUndefinedKeys } from '../src/object'; |
10 | 19 | import type { InternalGlobal } from '../src/worldwide'; |
11 | 20 | import { GLOBAL_OBJ } from '../src/worldwide'; |
12 | 21 |
|
13 | 22 | describe('envelope', () => { |
| 23 | + describe('createSpanEnvelope()', () => { |
| 24 | + it('span-envelope-item of INP event has the correct object structure', () => { |
| 25 | + const attributes: SpanAttributes = dropUndefinedKeys({ |
| 26 | + release: 'releaseString', |
| 27 | + environment: 'dev', |
| 28 | + transaction: '/test-route', |
| 29 | + [SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: 80, |
| 30 | + user: 10, |
| 31 | + profile_id: 'test-profile-id', |
| 32 | + replay_id: 'test-replay-id', |
| 33 | + }); |
| 34 | + |
| 35 | + const startTime = 1713365480; |
| 36 | + |
| 37 | + const span = new SentrySpan({ |
| 38 | + startTimestamp: startTime, |
| 39 | + endTimestamp: startTime + 2, |
| 40 | + op: 'ui.interaction.click', |
| 41 | + name: '<unknown>', |
| 42 | + attributes, |
| 43 | + }); |
| 44 | + |
| 45 | + span.addEvent('inp', { |
| 46 | + [SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: 'millisecond', |
| 47 | + [SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: 100, |
| 48 | + }); |
| 49 | + |
| 50 | + const spanEnvelopeItem = createSpanEnvelopeItem(spanToJSON(span)); |
| 51 | + |
| 52 | + const expectedObj = { |
| 53 | + data: { |
| 54 | + 'sentry.origin': expect.any(String), |
| 55 | + 'sentry.op': expect.any(String), |
| 56 | + release: expect.any(String), |
| 57 | + environment: expect.any(String), |
| 58 | + transaction: expect.any(String), |
| 59 | + 'sentry.exclusive_time': expect.any(Number), |
| 60 | + user: expect.any(Number), |
| 61 | + profile_id: expect.any(String), |
| 62 | + replay_id: expect.any(String), |
| 63 | + }, |
| 64 | + description: expect.any(String), |
| 65 | + op: expect.any(String), |
| 66 | + span_id: expect.any(String), |
| 67 | + start_timestamp: expect.any(Number), |
| 68 | + timestamp: expect.any(Number), |
| 69 | + trace_id: expect.any(String), |
| 70 | + origin: expect.any(String), |
| 71 | + exclusive_time: expect.any(Number), |
| 72 | + measurements: { inp: { value: expect.any(Number), unit: expect.any(String) } }, |
| 73 | + }; |
| 74 | + |
| 75 | + expect(spanEnvelopeItem[0].type).toBe('span'); |
| 76 | + expect(spanEnvelopeItem[1]).toMatchObject(expectedObj); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
14 | 80 | describe('createEnvelope()', () => { |
15 | 81 | const testTable: Array<[string, Parameters<typeof createEnvelope>[0], Parameters<typeof createEnvelope>[1]]> = [ |
16 | 82 | ['creates an empty envelope', {}, []], |
|
0 commit comments