11import { DsnComponents , Event } from '@sentry/types' ;
2+ import { EventTraceContext } from '@sentry/types/build/types/envelope' ;
23
34import { createEventEnvelope } from '../../src/envelope' ;
45
5- const testDsn : DsnComponents = { protocol : 'https' , projectId : 'abc' , host : 'testry.io' } ;
6+ const testDsn : DsnComponents = { protocol : 'https' , projectId : 'abc' , host : 'testry.io' , publicKey : 'pubKey123' } ;
67
78describe ( 'createEventEnvelope' , ( ) => {
8- describe ( 'baggage header' , ( ) => {
9- it ( "doesn't add baggage header if event is not a transaction" , ( ) => {
9+ describe ( 'trace header' , ( ) => {
10+ it ( "doesn't add trace header if event is not a transaction" , ( ) => {
1011 const event : Event = { } ;
1112 const envelopeHeaders = createEventEnvelope ( event , testDsn ) [ 0 ] ;
1213
1314 expect ( envelopeHeaders ) . toBeDefined ( ) ;
14- expect ( envelopeHeaders . baggage ) . toBeUndefined ( ) ;
15+ expect ( envelopeHeaders . trace ) . toBeUndefined ( ) ;
1516 } ) ;
1617
17- it ( "doesn't add baggage header if no baggage data is available" , ( ) => {
18+ it ( 'adds minimal trace data if event is a transaction and no other baggage-related data is available' , ( ) => {
1819 const event : Event = {
1920 type : 'transaction' ,
21+ contexts : {
22+ trace : {
23+ trace_id : '1234' ,
24+ } ,
25+ } ,
2026 } ;
2127 const envelopeHeaders = createEventEnvelope ( event , testDsn ) [ 0 ] ;
2228
2329 expect ( envelopeHeaders ) . toBeDefined ( ) ;
24- expect ( envelopeHeaders . baggage ) . toBeUndefined ( ) ;
30+ expect ( envelopeHeaders . trace ) . toEqual ( { trace_id : '1234' , public_key : 'pubKey123' } ) ;
2531 } ) ;
2632
27- const testTable : Array < [ string , Event , string ] > = [
28- [ 'adds only baggage item' , { type : 'transaction' , release : '1.0.0' } , 'sentry-release=1.0.0' ] ,
33+ const testTable : Array < [ string , Event , EventTraceContext ] > = [
34+ [
35+ 'adds only baggage item' ,
36+ {
37+ type : 'transaction' ,
38+ release : '1.0.0' ,
39+ contexts : {
40+ trace : {
41+ trace_id : '1234' ,
42+ } ,
43+ } ,
44+ } ,
45+ { release : '1.0.0' , trace_id : '1234' , public_key : 'pubKey123' } ,
46+ ] ,
2947 [
3048 'adds two baggage items' ,
31- { type : 'transaction' , release : '1.0.0' , environment : 'prod' } ,
32- 'sentry-environment=prod,sentry-release=1.0.0' ,
49+ {
50+ type : 'transaction' ,
51+ release : '1.0.0' ,
52+ environment : 'prod' ,
53+ contexts : {
54+ trace : {
55+ trace_id : '1234' ,
56+ } ,
57+ } ,
58+ } ,
59+ { release : '1.0.0' , environment : 'prod' , trace_id : '1234' , public_key : 'pubKey123' } ,
3360 ] ,
3461 [
3562 'adds all baggageitems' ,
@@ -39,16 +66,28 @@ describe('createEventEnvelope', () => {
3966 environment : 'prod' ,
4067 user : { id : 'bob' , segment : 'segmentA' } ,
4168 transaction : 'TX' ,
69+ contexts : {
70+ trace : {
71+ trace_id : '1234' ,
72+ } ,
73+ } ,
74+ } ,
75+ {
76+ release : '1.0.0' ,
77+ environment : 'prod' ,
78+ user : { id : 'bob' , segment : 'segmentA' } ,
79+ transaction : 'TX' ,
80+ trace_id : '1234' ,
81+ public_key : 'pubKey123' ,
4282 } ,
43- 'sentry-environment=prod,sentry-release=1.0.0,sentry-transaction=TX,sentry-userid=bob,sentry-usersegment=segmentA' ,
4483 ] ,
4584 ] ;
46- it . each ( testTable ) ( '%s' , ( _ : string , event , serializedBaggage ) => {
85+ it . each ( testTable ) ( '%s' , ( _ : string , event , trace ) => {
4786 const envelopeHeaders = createEventEnvelope ( event , testDsn ) [ 0 ] ;
4887
4988 expect ( envelopeHeaders ) . toBeDefined ( ) ;
50- expect ( envelopeHeaders . baggage ) . toBeDefined ( ) ;
51- expect ( envelopeHeaders . baggage ) . toEqual ( serializedBaggage ) ;
89+ expect ( envelopeHeaders . trace ) . toBeDefined ( ) ;
90+ expect ( envelopeHeaders . trace ) . toEqual ( trace ) ;
5291 } ) ;
5392 } ) ;
5493} ) ;
0 commit comments