@@ -11,18 +11,21 @@ import * as nock from 'nock';
11
11
import { Breadcrumb } from '../../src' ;
12
12
import { NodeClient } from '../../src/client' ;
13
13
import { Http as HttpIntegration } from '../../src/integrations/http' ;
14
+ import { NodeClientOptions } from '../../src/types' ;
14
15
import { getDefaultNodeClientOptions } from '../helper/node-client-options' ;
15
16
16
17
const NODE_VERSION = parseSemver ( process . versions . node ) ;
17
18
18
19
describe ( 'tracing' , ( ) => {
19
- function createTransactionOnScope ( ) {
20
+ function createTransactionOnScope ( customOptions : Partial < NodeClientOptions > = { } ) {
20
21
const options = getDefaultNodeClientOptions ( {
21
22
dsn :
'https://[email protected] /12312012' ,
22
23
tracesSampleRate : 1.0 ,
23
24
integrations : [ new HttpIntegration ( { tracing : true } ) ] ,
24
25
release : '1.0.0' ,
25
26
environment : 'production' ,
27
+ sendDefaultPii : true ,
28
+ ...customOptions ,
26
29
} ) ;
27
30
const hub = new Hub ( new NodeClient ( options ) ) ;
28
31
addExtensionMethods ( ) ;
@@ -133,6 +136,23 @@ describe('tracing', () => {
133
136
) ;
134
137
} ) ;
135
138
139
+ it ( 'does not add the user_id to the baggage header if sendDefaultPii is set to false' , async ( ) => {
140
+ nock ( 'http://dogs.are.great' ) . get ( '/' ) . reply ( 200 ) ;
141
+
142
+ createTransactionOnScope ( { sendDefaultPii : false } ) ;
143
+
144
+ const request = http . get ( { host : 'http://dogs.are.great/' , headers : { baggage : 'dog=great' } } ) ;
145
+ const baggageHeader = request . getHeader ( 'baggage' ) as string ;
146
+
147
+ expect ( baggageHeader ) . toBeDefined ( ) ;
148
+ expect ( typeof baggageHeader ) . toEqual ( 'string' ) ;
149
+ expect ( baggageHeader ) . toEqual (
150
+ 'dog=great,sentry-environment=production,sentry-release=1.0.0,sentry-transaction=dogpark,' +
151
+ 'sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,' +
152
+ 'sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1' ,
153
+ ) ;
154
+ } ) ;
155
+
136
156
it ( "doesn't attach the sentry-trace header to outgoing sentry requests" , ( ) => {
137
157
nock ( 'http://squirrelchasers.ingest.sentry.io' ) . get ( '/api/12312012/store/' ) . reply ( 200 ) ;
138
158
0 commit comments