faro-web-sdk icon indicating copy to clipboard operation
faro-web-sdk copied to clipboard

Fetch/XHR Instrumentation: Annotate server side context

Open cedricziel opened this issue 2 years ago • 2 comments

Goal

Create links between events this instrumentation created and server-side spans.

Description

When a server communicates their span context down via headers, the fetch instrumentation should pick it up and annotate the trace / span id on the event.

On the server side, we should be able to pick up a request from a client side session and we should be able to annotate the session id on the server span.

Proposed solution

  1. instrumentation watches request
  2. instrumentations adds header x-grafana-session with a value of the session id
  3. server works request, extracts x-grafana-session and adds it to the server span
  4. instrumentation sees server-timing, traceparent or traceresponse headers containing a traceparent compatible value in response
  5. instrumentation adds value to log event

Resources

  • traceresponse working draft - https://w3c.github.io/trace-context/#trace-context-http-response-headers-format
  • traceparent standard - https://w3c.github.io/trace-context/#trace-context-http-request-headers-format
  • https://raintank-corp.slack.com/archives/C04LHN01GN7/p1688052486783109?thread_ts=1688040850.841279&cid=C04LHN01GN7
### Tasks
- [ ] https://github.com/grafana/faro-web-sdk/issues/151#issuecomment-1678233608

cedricziel avatar Jun 20 '23 08:06 cedricziel

Some info I got form Gabor.

We can get the traceId for the "backend request", The traceId that is created for every grafana ajax request, and arrives back in the browser in the Grafana-Trace-Id: response-header

there’s even some code to show that traceId as a “debug” thing in the query-inspector (but that’s behind the showTraceId feature flag).

codecapitano avatar Jun 29 '23 15:06 codecapitano