Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Aaron Lord :csharp:
Aaron Lord :csharp:
@devlord@hachyderm.io  ·  activity timestamp last month

OK, search on Ecosia isn't helping so I'm turning to Mastodon. This is a #react #OpenTelemetry question. I'm using XMLHttpRequestInstrumentation to log traces but my web app has multiple requests in order to render a page. How do I put multiple requests in the same trace id? Perhaps I can use DocumentLoadInstrumentation, but sometimes the app behaves like a SPA and the lifespan will be way too long. I could also use UserInteractionInstrumentation but it's WAY too noisy. I don't need to track every click event. For budgetary reasons, in the end, I'd like to only dispatch to the collector if an error occurs in any part of the span.

  registerInstrumentations({
    instrumentations: [
      new XMLHttpRequestInstrumentation({
        propagateTraceHeaderCorsUrls: [ new RegExp(Configuration.ApiBaseUrl + ".*") ],
        applyCustomAttributesOnSpan: (span, xhr) => {
          const userContext = store.getState().userContext as UserContextState | undefined;
          if (userContext && userContext.userId) {
            span.setAttribute("user.id", userContext.userId);
          }
          if (xhr.status >= 400) {
            span.setStatus({
              code: SpanStatusCode.ERROR,
              message: `HTTP Error ${xhr.status}`
            });
          }
        }
      }),
registerInstrumentations({ instrumentations: [ new XMLHttpRequestInstrumentation({ propagateTraceHeaderCorsUrls: [ new RegExp(Configuration.ApiBaseUrl + ".*") ], applyCustomAttributesOnSpan: (span, xhr) => { const userContext = store.getState().userContext as UserContextState | undefined; if (userContext && userContext.userId) { span.setAttribute("user.id", userContext.userId); } if (xhr.status >= 400) { span.setStatus({ code: SpanStatusCode.ERROR, message: `HTTP Error ${xhr.status}` }); } } }),
registerInstrumentations({ instrumentations: [ new XMLHttpRequestInstrumentation({ propagateTraceHeaderCorsUrls: [ new RegExp(Configuration.ApiBaseUrl + ".*") ], applyCustomAttributesOnSpan: (span, xhr) => { const userContext = store.getState().userContext as UserContextState | undefined; if (userContext && userContext.userId) { span.setAttribute("user.id", userContext.userId); } if (xhr.status >= 400) { span.setStatus({ code: SpanStatusCode.ERROR, message: `HTTP Error ${xhr.status}` }); } } }),
  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.2-alpha.7 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct