Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 98e5b84

Browse files
committed
Fix the navigation span's starting point
The navigation span was started a lot later than it should have. This meant that child spans (such as web vitals) looked incorrect since the values of those child spans were longer than the navigation span. Now the navigation span is started a lot earlier, and this means that the child span values are safely within the permitted navigation span. We still have a navigation span start from onFrameNavigated which is needed when the iteration starts on a new page, since onFrameStartedLoading isn't called when a new page is called and it navigates to about:blank.
1 parent c61a234 commit 98e5b84

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

common/frame_session.go

+18
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ type FrameSession struct {
7878
// Keep a reference to the main frame span so we can end it
7979
// when FrameSession.ctx is Done
8080
mainFrameSpan trace.Span
81+
// The initial navigation when a new page is created navigates to about:blank.
82+
// We want to make sure that the the navigation span is created for this in
83+
// onFrameNavigated, but subsequent calls to onFrameNavigated in the same
84+
// mainframe never again create a navigation span.
85+
initialNavDone bool
8186
}
8287

8388
// NewFrameSession initializes and returns a new FrameSession.
@@ -782,6 +787,14 @@ func (fs *FrameSession) onFrameNavigated(frame *cdp.Frame, initial bool) {
782787
frame.URL+frame.URLFragment, err)
783788
}
784789

790+
// Only create a navigation span once from here, since a new page navigating
791+
// to about:blank doesn't call onFrameStartedLoading. All subsequent
792+
// navigations call onFrameStartedLoading.
793+
if fs.initialNavDone {
794+
return
795+
}
796+
797+
fs.initialNavDone = true
785798
fs.processNavigationSpan(frame.URL, frame.ID)
786799
}
787800

@@ -850,6 +863,11 @@ func (fs *FrameSession) onFrameStartedLoading(frameID cdp.FrameID) {
850863
"sid:%v tid:%v fid:%v",
851864
fs.session.ID(), fs.targetID, frameID)
852865

866+
frame, ok := fs.manager.getFrameByID(frameID)
867+
if ok {
868+
fs.processNavigationSpan(frame.URL(), frame.id)
869+
}
870+
853871
fs.manager.frameLoadingStarted(frameID)
854872
}
855873

0 commit comments

Comments
 (0)