You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Subsequent network requests are associated with the user-interaction.
265
+
const btn =document.getElementById('my-btn');
266
+
btn.addEventListener('click', () => {
267
+
fetch('https://httpbin.org/get')
268
+
.then(() => {
269
+
console.log('data downloaded 1');
270
+
returnfetch('https://httpbin.org/get');
271
+
});
272
+
.then(() => {
273
+
console.log('data downloaded 2');
274
+
});
275
+
});
276
+
```
277
+
278
+
Read more at [opentelemetry/user-interaction](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction).
279
+
280
+
### Long task initiator
281
+
282
+
Tracking long tasks effectively with the [Long Tasks API](https://github.com/w3c/longtasks)
283
+
requires being able to tell where a task was spawned from.
284
+
285
+
However, OpenTelemetry is not able to associate the Long Task timing entry
286
+
with their initiating trace spans. Capturing the `AsyncContext` can help here.
287
+
288
+
Notably, this proposal doesn't solve the problem solely. It provides a path
289
+
forward to the problem and can be integrated into the Long Tasks API.
290
+
291
+
```typescript
292
+
registerInstrumentations({
293
+
instrumentations: [newLongTaskInstrumentation()],
294
+
});
295
+
// Roughly equals to
296
+
newPerformanceObserver(list=> {...})
297
+
.observe({ entryTypes: ['longtask'] });
298
+
299
+
// Perform a 50ms long task
300
+
function myTask() {
301
+
const start =Date.now();
302
+
while (Date.now() -start<=50) {}
303
+
}
304
+
305
+
myTask();
306
+
```
307
+
308
+
Read more at [opentelemetry/long-task](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-long-task).
309
+
310
+
### Resource Timing Attributes
311
+
312
+
OpenTelemetry instruments fetch API with network timings from [Resource Timing API](https://github.com/w3c/resource-timing/)
313
+
associated to the initiator fetch span.
314
+
315
+
Without resource timing initiator info, it is not an intuitive approach to
316
+
associate the resource timing with the initiator spans. Capturing the
317
+
`AsyncContext` can help here.
318
+
319
+
Notably, this proposal doesn't solve the problem solely. It provides a path
320
+
forward to the problem and can be integrated into the Long Tasks API.
321
+
322
+
```typescript
323
+
registerInstrumentations({
324
+
instrumentations: [newFetchInstrumentation()],
325
+
});
326
+
// Observes network events and associate them with spans.
Read more at [opentelemetry/fetch](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-fetch).
0 commit comments