@@ -136,23 +136,6 @@ conditionalTest({ min: 16 })('Undici integration', () => {
136
136
expect ( transaction . spanRecorder ?. spans . length ) . toBe ( 1 ) ;
137
137
} ) ;
138
138
139
- it ( 'does not create a span for sentry requests' , async ( ) => {
140
- const transaction = hub . startTransaction ( { name : 'test-transaction' } ) as Transaction ;
141
- hub . getScope ( ) . setSpan ( transaction ) ;
142
-
143
- expect ( transaction . spanRecorder ?. spans . length ) . toBe ( 1 ) ;
144
-
145
- try {
146
- await fetch ( `${ SENTRY_DSN } /sub/route` , {
147
- method : 'POST' ,
148
- } ) ;
149
- } catch ( e ) {
150
- // ignore
151
- }
152
-
153
- expect ( transaction . spanRecorder ?. spans . length ) . toBe ( 1 ) ;
154
- } ) ;
155
-
156
139
it ( 'does not create a span if there is no active spans' , async ( ) => {
157
140
try {
158
141
await fetch ( `${ SENTRY_DSN } /sub/route` , { method : 'POST' } ) ;
@@ -194,6 +177,24 @@ conditionalTest({ min: 16 })('Undici integration', () => {
194
177
) ;
195
178
} ) ;
196
179
180
+ it ( 'does not attach headers if `shouldCreateSpanForRequest` does not create a span' , async ( ) => {
181
+ const transaction = hub . startTransaction ( { name : 'test-transaction' } ) as Transaction ;
182
+ hub . getScope ( ) . setSpan ( transaction ) ;
183
+
184
+ const client = new NodeClient ( { ...DEFAULT_OPTIONS , shouldCreateSpanForRequest : url => url . includes ( 'yes' ) } ) ;
185
+ hub . bindClient ( client ) ;
186
+
187
+ await fetch ( 'http://localhost:18099/no' , { method : 'POST' } ) ;
188
+
189
+ expect ( requestHeaders [ 'sentry-trace' ] ) . toBeUndefined ( ) ;
190
+ expect ( requestHeaders [ 'baggage' ] ) . toBeUndefined ( ) ;
191
+
192
+ await fetch ( 'http://localhost:18099/yes' , { method : 'POST' } ) ;
193
+
194
+ expect ( requestHeaders [ 'sentry-trace' ] ) . toBeDefined ( ) ;
195
+ expect ( requestHeaders [ 'baggage' ] ) . toBeDefined ( ) ;
196
+ } ) ;
197
+
197
198
it ( 'uses tracePropagationTargets' , async ( ) => {
198
199
const transaction = hub . startTransaction ( { name : 'test-transaction' } ) as Transaction ;
199
200
hub . getScope ( ) . setSpan ( transaction ) ;
0 commit comments