@@ -4,10 +4,12 @@ import {
44 browserPerformanceTimeOrigin ,
55 getActiveSpan ,
66 getComponentName ,
7+ getCurrentScope ,
78 htmlTreeAsString ,
89 isPrimitive ,
910 parseUrl ,
1011 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
12+ SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE ,
1113 setMeasurement ,
1214 spanToJSON ,
1315 stringMatchesSomePattern ,
@@ -32,6 +34,7 @@ import {
3234import { getActivationStart } from './web-vitals/lib/getActivationStart' ;
3335import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry' ;
3436import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher' ;
37+ import { TRACE_FLAG_NONE , TRACE_FLAG_SAMPLED } from '@sentry/core/build/types/utils/spanUtils' ;
3538
3639interface NavigatorNetworkInformation {
3740 readonly connection ?: NetworkInformation ;
@@ -604,6 +607,7 @@ function _addRequest(span: Span, entry: PerformanceNavigationTiming, timeOrigin:
604607 const responseEndTimestamp = timeOrigin + msToSec ( entry . responseEnd as number ) ;
605608 const responseStartTimestamp = timeOrigin + msToSec ( entry . responseStart as number ) ;
606609 if ( entry . responseEnd ) {
610+ const propagationContext = getCurrentScope ( ) . getPropagationContext ( ) ;
607611 // 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.
608612 // In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
609613 // 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:
614618 attributes : {
615619 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.browser.metrics' ,
616620 } ,
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+ } ) ,
617635 } ) ;
618636
619637 startAndEndSpan ( span , responseStartTimestamp , responseEndTimestamp , {
0 commit comments