Skip to content

web: add react tracer and instrument the blob page

Warren Gifford requested to merge vb/react-trace-provider into main

Created by: valerybugakov

Context

This PR introduces a couple of components and hooks to facilitate our React code instrumentation. It is the first stab into the React instrumentation that gives us data about component mount timings relative to the page load event and other key components of instrumented pages.

Usage example:

const Traced = () => (
  <TraceSpanProvider name="RepositoryFileTreePage">
      <RepositoryFileTreePage {...props} />,
  </TraceSpanProvider>
)

TraceSpanProvider creates the OpenTelemetry tracing span on the first component render call, and it ends the span automatically on the component mount event. Does nothing and returns children if OpenTelemetry tracing is disabled.

Closes https://github.com/sourcegraph/sourcegraph/issues/39282 Closes https://github.com/sourcegraph/sourcegraph/issues/40467

Example

Honeycomb trace link

Screen Shot 2022-08-17 at 17 05 11

Why use React context instead of OpenTelemetry context manager?

The proposed implementation uses React context to correctly connect spans created by nested components.

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. Open the browser console and ensure that debug level output is enabled.
  3. Navigate between to the Blob page.
  4. See navigation events logged into the console with nested events created by React components.
Screen Shot 2022-08-18 at 22 46 14

The web application should function as usual with disabled OpenTelemetry.

  1. sg start web-standalone
  2. Ensure that the Blob page works as expected.

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading