web: add `history` `opentelemetry` auto-instrumentation
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
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
ENABLE_OPEN_TELEMETRY=true sg start web-standalone
-
sg start otel
in a separate terminal window - Navigate between pages using links and back-forward browser buttons.
- See navigation events logged into the console for each navigation action.
App preview:
Check out the client app preview documentation to learn more.