Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using OTEL tracing on the client for network requests #8470

Open
ccschmitz opened this issue May 6, 2024 — with Linear · 2 comments
Open

Start using OTEL tracing on the client for network requests #8470

ccschmitz opened this issue May 6, 2024 — with Linear · 2 comments

Comments

Copy link
Contributor

Ensure we use the W3C spec on the client so we can pick it up on the back end.

Copy link

linear bot commented May 6, 2024

Copy link

greptile-apps bot commented May 6, 2024

To integrate W3C-compliant OTEL tracing for network requests on the client side, follow these steps:

  1. Modify Network Request Headers:
    Update the XHRListener and fetch request functions to include OTEL trace context headers (traceparent and optionally tracestate). These headers are part of the W3C Trace Context specification.

  2. Generate Trace IDs and Span IDs:
    Use a library or custom code to generate traceId and spanId values according to the W3C Trace Context specification. These values should be unique per request and span, respectively.

  3. Set Trace Context Headers:
    For each outgoing HTTP request (XMLHttpRequest or Fetch API), set the traceparent header with the generated traceId and spanId. Optionally, include the tracestate header for additional trace context.

  4. Backend Reception:
    Ensure the backend is configured to parse and use these headers for continued tracing. This might involve configuring your backend tracing or observability tool to recognize and utilize the W3C Trace Context headers.

Example Code Snippet for XMLHttpRequest:

XHR.setRequestHeader = function (this: BrowserXHR, header: string, value: string) {
  if (header.toLowerCase() === 'traceparent') {
    // Generate or use existing traceId and spanId
    const traceValue = `00-${traceId}-${spanId}-01`;
    this._requestHeaders['traceparent'] = traceValue;
  }
  return originalSetRequestHeader.apply(this, arguments);
}

This approach ensures that the client-side network requests are traced in a manner that's compatible with the backend's observability tools, adhering to the W3C Trace Context specification.

References

highlight/highlight/sdk/client/src/listeners/network-listener/utils/utils.ts
highlight/highlight/sdk/client/src/listeners/network-listener/utils/xhr-listener.ts
highlight/highlight/docs-content/getting-started/2_frontend-backend-mapping.md
highlight/highlight/docs-content/getting-started/7_native-opentelemetry/1_overview.md
highlight/highlight/docs-content/getting-started/7_native-opentelemetry/4_tracing.md

Ask Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant