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

Commit e7494f4

Browse files
committed
Fix url attribute on navigate and navigation span
When the navigation span is started, the new URL is not available to us yet. We have to defer the adding of the url attribute to the span to the end of the navigation span.
1 parent 98e5b84 commit e7494f4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

common/frame_session.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ func (fs *FrameSession) initEvents() {
242242
// If there is an active span for main frame,
243243
// end it before exiting so it can be flushed
244244
if fs.mainFrameSpan != nil {
245+
// The url needs to be added here instead of at the start of the span
246+
// because at the start of the span we don't know the correct url for
247+
// the page we're navigating to. At the end of the span we do have this
248+
// information.
249+
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrame().URL()))
245250
fs.mainFrameSpan.End()
246251
fs.mainFrameSpan = nil
247252
}
@@ -795,10 +800,10 @@ func (fs *FrameSession) onFrameNavigated(frame *cdp.Frame, initial bool) {
795800
}
796801

797802
fs.initialNavDone = true
798-
fs.processNavigationSpan(frame.URL, frame.ID)
803+
fs.processNavigationSpan(frame.ID)
799804
}
800805

801-
func (fs *FrameSession) processNavigationSpan(url string, id cdp.FrameID) {
806+
func (fs *FrameSession) processNavigationSpan(id cdp.FrameID) {
802807
newFrame, ok := fs.manager.getFrameByID(id)
803808
if !ok {
804809
return
@@ -812,11 +817,16 @@ func (fs *FrameSession) processNavigationSpan(url string, id cdp.FrameID) {
812817

813818
// End the navigation span if it is non-nil
814819
if fs.mainFrameSpan != nil {
820+
// The url needs to be added here instead of at the start of the span
821+
// because at the start of the span we don't know the correct url for
822+
// the page we're navigating to. At the end of the span we do have this
823+
// information.
824+
fs.mainFrameSpan.SetAttributes(attribute.String("navigation.url", fs.manager.MainFrame().URL()))
815825
fs.mainFrameSpan.End()
816826
}
817827

818828
_, fs.mainFrameSpan = TraceNavigation(
819-
fs.ctx, fs.targetID.String(), trace.WithAttributes(attribute.String("navigation.url", url)),
829+
fs.ctx, fs.targetID.String(),
820830
)
821831

822832
spanID := fs.mainFrameSpan.SpanContext().SpanID().String()
@@ -863,10 +873,7 @@ func (fs *FrameSession) onFrameStartedLoading(frameID cdp.FrameID) {
863873
"sid:%v tid:%v fid:%v",
864874
fs.session.ID(), fs.targetID, frameID)
865875

866-
frame, ok := fs.manager.getFrameByID(frameID)
867-
if ok {
868-
fs.processNavigationSpan(frame.URL(), frame.id)
869-
}
876+
fs.processNavigationSpan(frameID)
870877

871878
fs.manager.frameLoadingStarted(frameID)
872879
}

0 commit comments

Comments
 (0)