@@ -28,13 +28,15 @@ import {
28
28
} from '@opentelemetry/core' ;
29
29
import {
30
30
addSpanNetworkEvent ,
31
+ addSpanNetworkEvents ,
31
32
hasKey ,
32
33
PerformanceEntries ,
33
34
PerformanceLegacy ,
34
35
PerformanceTimingNames as PTN ,
35
36
} from '@opentelemetry/web' ;
36
37
import { AttributeNames } from './enums/AttributeNames' ;
37
38
import { VERSION } from './version' ;
39
+ import { HttpAttribute } from '@opentelemetry/semantic-conventions' ;
38
40
39
41
/**
40
42
* This class represents a document load plugin
@@ -81,21 +83,6 @@ export class DocumentLoad extends BasePlugin<unknown> {
81
83
}
82
84
}
83
85
84
- /**
85
- * Adds span network events
86
- * @param span
87
- * @param entries entries that contains performance information about resource
88
- */
89
- private _addSpanNetworkEvents ( span : Span , entries : PerformanceEntries ) {
90
- addSpanNetworkEvent ( span , PTN . DOMAIN_LOOKUP_START , entries ) ;
91
- addSpanNetworkEvent ( span , PTN . DOMAIN_LOOKUP_END , entries ) ;
92
- addSpanNetworkEvent ( span , PTN . CONNECT_START , entries ) ;
93
- addSpanNetworkEvent ( span , PTN . SECURE_CONNECTION_START , entries ) ;
94
- addSpanNetworkEvent ( span , PTN . CONNECT_END , entries ) ;
95
- addSpanNetworkEvent ( span , PTN . REQUEST_START , entries ) ;
96
- addSpanNetworkEvent ( span , PTN . RESPONSE_START , entries ) ;
97
- }
98
-
99
86
/**
100
87
* Collects information about performance and creates appropriate spans
101
88
*/
@@ -123,14 +110,15 @@ export class DocumentLoad extends BasePlugin<unknown> {
123
110
) ;
124
111
if ( fetchSpan ) {
125
112
this . _tracer . withSpan ( fetchSpan , ( ) => {
126
- this . _addSpanNetworkEvents ( fetchSpan , entries ) ;
113
+ addSpanNetworkEvents ( fetchSpan , entries ) ;
127
114
this . _endSpan ( fetchSpan , PTN . RESPONSE_END , entries ) ;
128
115
} ) ;
129
116
}
130
117
} ) ;
131
118
132
119
this . _addResourcesSpans ( rootSpan ) ;
133
120
121
+ addSpanNetworkEvent ( rootSpan , PTN . FETCH_START , entries ) ;
134
122
addSpanNetworkEvent ( rootSpan , PTN . UNLOAD_EVENT_START , entries ) ;
135
123
addSpanNetworkEvent ( rootSpan , PTN . UNLOAD_EVENT_END , entries ) ;
136
124
addSpanNetworkEvent ( rootSpan , PTN . DOM_INTERACTIVE , entries ) ;
@@ -142,6 +130,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
142
130
addSpanNetworkEvent ( rootSpan , PTN . DOM_CONTENT_LOADED_EVENT_END , entries ) ;
143
131
addSpanNetworkEvent ( rootSpan , PTN . DOM_COMPLETE , entries ) ;
144
132
addSpanNetworkEvent ( rootSpan , PTN . LOAD_EVENT_START , entries ) ;
133
+ addSpanNetworkEvent ( rootSpan , PTN . LOAD_EVENT_END , entries ) ;
145
134
146
135
this . _endSpan ( rootSpan , PTN . LOAD_EVENT_END , entries ) ;
147
136
} ) ;
@@ -161,7 +150,6 @@ export class DocumentLoad extends BasePlugin<unknown> {
161
150
// span can be undefined when entries are missing the certain performance - the span will not be created
162
151
if ( span ) {
163
152
if ( hasKey ( entries , performanceName ) ) {
164
- addSpanNetworkEvent ( span , performanceName , entries ) ;
165
153
span . end ( entries [ performanceName ] ) ;
166
154
} else {
167
155
// just end span
@@ -184,7 +172,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
184
172
keys . forEach ( ( key : string ) => {
185
173
if ( hasKey ( performanceNavigationTiming , key ) ) {
186
174
const value = performanceNavigationTiming [ key ] ;
187
- if ( typeof value === 'number' && value > 0 ) {
175
+ if ( typeof value === 'number' && value >= 0 ) {
188
176
entries [ key ] = value ;
189
177
}
190
178
}
@@ -198,7 +186,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
198
186
keys . forEach ( ( key : string ) => {
199
187
if ( hasKey ( performanceTiming , key ) ) {
200
188
const value = performanceTiming [ key ] ;
201
- if ( typeof value === 'number' && value > 0 ) {
189
+ if ( typeof value === 'number' && value >= 0 ) {
202
190
entries [ key ] = value ;
203
191
}
204
192
}
@@ -218,13 +206,14 @@ export class DocumentLoad extends BasePlugin<unknown> {
218
206
spanOptions : SpanOptions = { }
219
207
) {
220
208
const span = this . _startSpan (
221
- resource . name ,
209
+ AttributeNames . RESOURCE_FETCH ,
222
210
PTN . FETCH_START ,
223
211
resource ,
224
212
spanOptions
225
213
) ;
226
214
if ( span ) {
227
- this . _addSpanNetworkEvents ( span , resource ) ;
215
+ span . setAttribute ( HttpAttribute . HTTP_URL , resource . name ) ;
216
+ addSpanNetworkEvents ( span , resource ) ;
228
217
this . _endSpan ( span , PTN . RESPONSE_END , resource ) ;
229
218
}
230
219
}
@@ -257,7 +246,6 @@ export class DocumentLoad extends BasePlugin<unknown> {
257
246
)
258
247
) ;
259
248
span . setAttribute ( AttributeNames . COMPONENT , this . component ) ;
260
- addSpanNetworkEvent ( span , performanceName , entries ) ;
261
249
return span ;
262
250
}
263
251
return undefined ;
0 commit comments