Skip to content

Commit

Permalink
fix extra span on network request
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmunz committed Nov 28, 2024
1 parent b4dc87e commit f1e8fc5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/reactnativeapp/hooks/useTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const Tracer = async () => {

registerInstrumentations({
instrumentations: [
new XMLHttpRequestInstrumentation(),
// TODO Some tiptoeing required here, propagateTraceHeaderCorsUrls is required to make the instrumentation
// work in the context of a mobile app even though we are not making CORS requests. `clearTimingResources` must
// be turned off to avoid using the web-only Performance API
Expand All @@ -93,6 +92,15 @@ const Tracer = async () => {
propagateTraceHeaderCorsUrls: /.*/,
clearTimingResources: false,
}),

// The React Native implementation of fetch is simply a polyfill on top of XMLHttpRequest:
// https://github.com/facebook/react-native/blob/7ccc5934d0f341f9bc8157f18913a7b340f5db2d/packages/react-native/Libraries/Network/fetch.js#L17
// Because of this when making requests using `fetch` there will an additional span created for the underlying
// request made with XMLHttpRequest. Since in this demo calls to /api/ are made using fetch, turn off
// instrumentation for that path to avoid the extra spans.
new XMLHttpRequestInstrumentation({
ignoreUrls: [/\/api\/.*/],
}),
],
});
};
Expand Down

0 comments on commit f1e8fc5

Please sign in to comment.