Browse Source

ref(sdk): Use http timing experiment (#52390)

### Summary
This enables the http timing experiment from the recent sdk changes,
which will report http timings on fetch/xhr spans out of the box. This
is going to help us test out http timings experimentally by using it for
ourselves first.

Other:
- Removes custom http timing integration code
Kev 1 year ago
parent
commit
c554b64994

+ 1 - 2
static/app/bootstrap/initializeSdk.tsx

@@ -10,7 +10,6 @@ import {SENTRY_RELEASE_VERSION, SPA_DSN} from 'sentry/constants';
 import {Config} from 'sentry/types';
 import {addExtraMeasurements, addUIElementTag} from 'sentry/utils/performanceForSentry';
 import {normalizeUrl} from 'sentry/utils/withDomainRequired';
-import {HTTPTimingIntegration} from 'sentry/utils/performanceForSentry/integrations';
 import {getErrorDebugIds} from 'sentry/utils/getErrorDebugIds';
 
 const SPA_MODE_ALLOW_URLS = [
@@ -63,11 +62,11 @@ function getSentryIntegrations(routes?: Function) {
         : {}),
       _experiments: {
         enableInteractions: true,
+        enableHTTPTimings: true,
         onStartRouteTransaction: Sentry.onProfilingStartRouteTransaction,
       },
     }),
     new Sentry.BrowserProfilingIntegration(),
-    new HTTPTimingIntegration(),
   ];
 
   return integrations;

+ 0 - 79
static/app/utils/performanceForSentry/integrations.tsx

@@ -1,79 +0,0 @@
-import {addInstrumentationHandler} from '@sentry/utils';
-
-export class HTTPTimingIntegration {
-  static id = 'HTTPTimingIntegration';
-
-  name = HTTPTimingIntegration.id;
-  options = undefined;
-
-  constructor(options?) {
-    this.options = options;
-  }
-
-  static getTimingOffsets(r: PerformanceResourceTiming) {
-    const {startTime, requestStart, responseStart, domainLookupStart, connectStart} = r;
-    return {
-      startTime: 0,
-      requestStart: requestStart - startTime,
-      responseStart: responseStart - startTime,
-      connectStart: connectStart - startTime,
-      domainLookupStart: domainLookupStart - startTime,
-    };
-  }
-
-  setupOnce() {
-    addInstrumentationHandler('fetch', handlerData => {
-      setTimeout(() => {
-        try {
-          const spanId = handlerData.fetchData.__span;
-
-          const Sentry = (window as any).Sentry;
-
-          // Replace this with access to the spans object in sdk request if porting to sdk.
-          if (!Sentry) {
-            return;
-          }
-
-          const transaction = Sentry.getActiveTransaction();
-          if (!transaction) {
-            return;
-          }
-          const spans = transaction.spanRecorder?.spans;
-
-          if (!spans || spans?.length > 1000) {
-            // This should be pretty fast but incase spans is unbounded don't do O(n) lookup for spanid.
-            return;
-          }
-
-          const span = spans.find(s => s.spanId === spanId);
-
-          if (!span) {
-            return;
-          }
-          const fetches = performance
-            .getEntriesByType('resource')
-            .filter(r => (r as PerformanceResourceTiming).initiatorType === 'fetch');
-          const matching = (fetches as PerformanceResourceTiming[]).filter(r =>
-            r.name.includes(handlerData.fetchData.url)
-          );
-          if (!matching.length) {
-            return;
-          }
-
-          const latestMatch = matching.at(-1);
-          if (!latestMatch) {
-            return;
-          }
-
-          span.setData(
-            'http.timings',
-            HTTPTimingIntegration.getTimingOffsets(latestMatch)
-          );
-          span.setData('http.protocol', latestMatch.nextHopProtocol);
-        } catch (_) {
-          // defensive catch
-        }
-      }, 0);
-    });
-  }
-}