@@ -4,10 +4,12 @@ import {
4
4
browserPerformanceTimeOrigin ,
5
5
getActiveSpan ,
6
6
getComponentName ,
7
+ getCurrentScope ,
7
8
htmlTreeAsString ,
8
9
isPrimitive ,
9
10
parseUrl ,
10
11
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
12
+ SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE ,
11
13
setMeasurement ,
12
14
spanToJSON ,
13
15
stringMatchesSomePattern ,
@@ -32,6 +34,7 @@ import {
32
34
import { getActivationStart } from './web-vitals/lib/getActivationStart' ;
33
35
import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry' ;
34
36
import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher' ;
37
+ import { TRACE_FLAG_NONE , TRACE_FLAG_SAMPLED } from '@sentry/core/build/types/utils/spanUtils' ;
35
38
36
39
interface NavigatorNetworkInformation {
37
40
readonly connection ?: NetworkInformation ;
@@ -604,6 +607,7 @@ function _addRequest(span: Span, entry: PerformanceNavigationTiming, timeOrigin:
604
607
const responseEndTimestamp = timeOrigin + msToSec ( entry . responseEnd as number ) ;
605
608
const responseStartTimestamp = timeOrigin + msToSec ( entry . responseStart as number ) ;
606
609
if ( entry . responseEnd ) {
610
+ const propagationContext = getCurrentScope ( ) . getPropagationContext ( ) ;
607
611
// It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.
608
612
// In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
609
613
// In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect
@@ -614,6 +618,20 @@ function _addRequest(span: Span, entry: PerformanceNavigationTiming, timeOrigin:
614
618
attributes : {
615
619
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.browser.metrics' ,
616
620
} ,
621
+ ...( propagationContext . ssrSpanId && {
622
+ links : [
623
+ {
624
+ context : {
625
+ traceId : propagationContext . traceId ,
626
+ spanId : propagationContext . ssrSpanId ,
627
+ traceFlags : propagationContext . sampled ? TRACE_FLAG_SAMPLED : TRACE_FLAG_NONE ,
628
+ } ,
629
+ attributes : {
630
+ [ SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE ] : 'ssr_span' ,
631
+ } ,
632
+ } ,
633
+ ] ,
634
+ } ) ,
617
635
} ) ;
618
636
619
637
startAndEndSpan ( span , responseStartTimestamp , responseEndTimestamp , {
0 commit comments