File tree Expand file tree Collapse file tree 3 files changed +45
-4
lines changed Expand file tree Collapse file tree 3 files changed +45
-4
lines changed Original file line number Diff line number Diff line change 6
6
- [ tracing] fix: Add manual Location typing (#2700 )
7
7
- [ react] feat: Expose eventId on ErrorBoundary component
8
8
9
+ - [ tracing] feat: Pick up sentry-trace in JS <meta /> tag (#2703 )
10
+ - [ tracing] fix: Respect sample decision when continuing trace from header in node (#2703 )
11
+
9
12
## 5.18.1
10
13
11
14
- [ react] feat: Update peer dependencies for ` react ` and ` react-dom ` (#2694 )
Original file line number Diff line number Diff line change @@ -285,6 +285,44 @@ export class Tracing implements Integration {
285
285
} ) ;
286
286
}
287
287
288
+ /**
289
+ * Returns a new Transaction either continued from sentry-trace meta or a new one
290
+ */
291
+ private static _getNewTransaction ( hub : Hub , transactionContext : TransactionContext ) : Transaction {
292
+ let traceId ;
293
+ let parentSpanId ;
294
+ let sampled ;
295
+
296
+ const header = Tracing . _getMeta ( 'sentry-trace' ) ;
297
+ if ( header ) {
298
+ const span = SpanClass . fromTraceparent ( header ) ;
299
+ if ( span ) {
300
+ traceId = span . traceId ;
301
+ parentSpanId = span . parentSpanId ;
302
+ sampled = span . sampled ;
303
+ Tracing . _log (
304
+ `[Tracing] found 'sentry-meta' '<meta />' continuing trace with: trace_id: ${ traceId } span_id: ${ parentSpanId } ` ,
305
+ ) ;
306
+ }
307
+ }
308
+
309
+ return hub . startTransaction ( {
310
+ parentSpanId,
311
+ sampled,
312
+ traceId,
313
+ trimEnd : true ,
314
+ ...transactionContext ,
315
+ } ) as Transaction ;
316
+ }
317
+
318
+ /**
319
+ * Returns the value of a meta tag
320
+ */
321
+ private static _getMeta ( metaName : string ) : string | null {
322
+ const el = document . querySelector ( `meta[name=${ metaName } ]` ) ;
323
+ return el ? el . getAttribute ( 'content' ) : null ;
324
+ }
325
+
288
326
/**
289
327
* Pings the heartbeat
290
328
*/
@@ -456,10 +494,7 @@ export class Tracing implements Integration {
456
494
return undefined ;
457
495
}
458
496
459
- Tracing . _activeTransaction = hub . startTransaction ( {
460
- trimEnd : true ,
461
- ...transactionContext ,
462
- } ) as Transaction ;
497
+ Tracing . _activeTransaction = Tracing . _getNewTransaction ( hub , transactionContext ) ;
463
498
464
499
// We set the transaction here on the scope so error events pick up the trace context and attach it to the error
465
500
hub . configureScope ( scope => scope . setSpan ( Tracing . _activeTransaction ) ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export function tracingHandler(): (
34
34
35
35
let traceId ;
36
36
let parentSpanId ;
37
+ let sampled ;
37
38
38
39
// If there is a trace header set, we extract the data from it and set the span on the scope
39
40
// to be the origin an created transaction set the parent_span_id / trace_id
@@ -42,13 +43,15 @@ export function tracingHandler(): (
42
43
if ( span ) {
43
44
traceId = span . traceId ;
44
45
parentSpanId = span . parentSpanId ;
46
+ sampled = span . sampled ;
45
47
}
46
48
}
47
49
48
50
const transaction = startTransaction ( {
49
51
name : `${ reqMethod } ${ reqUrl } ` ,
50
52
op : 'http.server' ,
51
53
parentSpanId,
54
+ sampled,
52
55
traceId,
53
56
} ) ;
54
57
You can’t perform that action at this time.
0 commit comments