Skip to content

web: add `history` `opentelemetry` auto-instrumentation

Warren Gifford requested to merge vb/history-instrumentation into main

Created by: valerybugakov

Context

This PR adds OpenTelemetry auto-instrumentation of the window popstate event and history API that creates the PageView span on every URL change. These navigation spans are later used as parents for other spans created by the application.

Having top-level navigation allows grouping other spans in one trace bound to the page view, which helps analyze data in Honeycomb. This experimental approach will be improved based on our experience with events received from the production environment.

Closes https://github.com/sourcegraph/sourcegraph/issues/40466

Example

Honeycomb trace link

Screen Shot 2022-08-17 at 17 05 11

Why have a separate store instead of sharing via context manager?

The OpenTelemetry context is immutable and can only be passed down with a callback. If there's no way to wrap the function execution into a parent span via callback, we need to implement another sharing mechanism like a store. This issue is raised in the OpenTelemetry repo and currently does not have a recommended solution.

Test plan

  1. ENABLE_OPEN_TELEMETRY=true sg start web-standalone
  2. sg start otel in a separate terminal window
  3. Navigate between pages using links and back-forward browser buttons.
  4. See navigation events logged into the console for each navigation action.

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading