@@ -242,6 +242,11 @@ func (fs *FrameSession) initEvents() {
242
242
// If there is an active span for main frame,
243
243
// end it before exiting so it can be flushed
244
244
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 ()))
245
250
fs .mainFrameSpan .End ()
246
251
fs .mainFrameSpan = nil
247
252
}
@@ -795,10 +800,10 @@ func (fs *FrameSession) onFrameNavigated(frame *cdp.Frame, initial bool) {
795
800
}
796
801
797
802
fs .initialNavDone = true
798
- fs .processNavigationSpan (frame .URL , frame . ID )
803
+ fs .processNavigationSpan (frame .ID )
799
804
}
800
805
801
- func (fs * FrameSession ) processNavigationSpan (url string , id cdp.FrameID ) {
806
+ func (fs * FrameSession ) processNavigationSpan (id cdp.FrameID ) {
802
807
newFrame , ok := fs .manager .getFrameByID (id )
803
808
if ! ok {
804
809
return
@@ -812,11 +817,16 @@ func (fs *FrameSession) processNavigationSpan(url string, id cdp.FrameID) {
812
817
813
818
// End the navigation span if it is non-nil
814
819
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 ()))
815
825
fs .mainFrameSpan .End ()
816
826
}
817
827
818
828
_ , fs .mainFrameSpan = TraceNavigation (
819
- fs .ctx , fs .targetID .String (), trace . WithAttributes ( attribute . String ( "navigation.url" , url )),
829
+ fs .ctx , fs .targetID .String (),
820
830
)
821
831
822
832
spanID := fs .mainFrameSpan .SpanContext ().SpanID ().String ()
@@ -863,10 +873,7 @@ func (fs *FrameSession) onFrameStartedLoading(frameID cdp.FrameID) {
863
873
"sid:%v tid:%v fid:%v" ,
864
874
fs .session .ID (), fs .targetID , frameID )
865
875
866
- frame , ok := fs .manager .getFrameByID (frameID )
867
- if ok {
868
- fs .processNavigationSpan (frame .URL (), frame .id )
869
- }
876
+ fs .processNavigationSpan (frameID )
870
877
871
878
fs .manager .frameLoadingStarted (frameID )
872
879
}
0 commit comments