miniflare 0.0.0-ecef68635 → 0.0.0-eec2a7074

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8619,6 +8619,17 @@ var require_index_cjs = __commonJS({
8619
8619
  }
8620
8620
  });
8621
8621
 
8622
+ // ../workers-shared/utils/performance.ts
8623
+ var PerformanceTimer = class {
8624
+ performanceTimer;
8625
+ constructor(performanceTimer) {
8626
+ this.performanceTimer = performanceTimer;
8627
+ }
8628
+ now() {
8629
+ return this.performanceTimer ? this.performanceTimer.timeOrigin + this.performanceTimer.now() : Date.now();
8630
+ }
8631
+ };
8632
+
8622
8633
  // ../workers-shared/utils/sentry.ts
8623
8634
  var import_toucan_js = __toESM(require_index_cjs());
8624
8635
  function setupSentry(request, context, dsn, clientId, clientSecret) {
@@ -8654,20 +8665,74 @@ function setupSentry(request, context, dsn, clientId, clientSecret) {
8654
8665
  return sentry.setUser({ userAgent, colo }), sentry;
8655
8666
  }
8656
8667
 
8668
+ // ../workers-shared/router-worker/src/analytics.ts
8669
+ var Analytics = class {
8670
+ data = {};
8671
+ setData(newData) {
8672
+ this.data = { ...this.data, ...newData };
8673
+ }
8674
+ getData(key) {
8675
+ return this.data[key];
8676
+ }
8677
+ write(env, readyAnalytics, hostname) {
8678
+ readyAnalytics && readyAnalytics.logEvent({
8679
+ version: 1,
8680
+ accountId: 0,
8681
+ // TODO: need to plumb through
8682
+ indexId: hostname,
8683
+ doubles: [
8684
+ this.data.requestTime ?? -1,
8685
+ // double1
8686
+ this.data.coloId ?? -1,
8687
+ // double2
8688
+ this.data.metalId ?? -1,
8689
+ // double3
8690
+ this.data.coloTier ?? -1
8691
+ // double4
8692
+ ],
8693
+ blobs: [
8694
+ this.data.hostname?.substring(0, 256),
8695
+ // blob1 - trim to 256 bytes
8696
+ this.data.dispatchtype,
8697
+ // blob2
8698
+ this.data.error?.substring(0, 256),
8699
+ // blob3 - trim to 256 bytes
8700
+ this.data.version,
8701
+ // blob4
8702
+ this.data.coloRegion
8703
+ // blob5
8704
+ ]
8705
+ });
8706
+ }
8707
+ };
8708
+
8657
8709
  // ../workers-shared/router-worker/src/index.ts
8658
8710
  var src_default = {
8659
8711
  async fetch(request, env, ctx) {
8660
- let sentry, maybeSecondRequest = request.clone();
8712
+ let sentry, analytics = new Analytics(), performance = new PerformanceTimer(env.UNSAFE_PERFORMANCE), startTimeMs = performance.now();
8661
8713
  try {
8662
- return sentry = setupSentry(
8714
+ sentry = setupSentry(
8663
8715
  request,
8664
8716
  ctx,
8665
8717
  env.SENTRY_DSN,
8666
8718
  env.SENTRY_ACCESS_CLIENT_ID,
8667
8719
  env.SENTRY_ACCESS_CLIENT_SECRET
8668
- ), env.CONFIG.has_user_worker ? await env.ASSET_WORKER.unstable_canFetch(request) ? await env.ASSET_WORKER.fetch(maybeSecondRequest) : env.USER_WORKER.fetch(maybeSecondRequest) : await env.ASSET_WORKER.fetch(request);
8720
+ );
8721
+ let url = new URL(request.url);
8722
+ sentry && (sentry.setUser({ username: url.hostname }), sentry.setTag("colo", env.COLO_METADATA.coloId), sentry.setTag("metal", env.COLO_METADATA.metalId)), env.COLO_METADATA && env.VERSION_METADATA && analytics.setData({
8723
+ coloId: env.COLO_METADATA.coloId,
8724
+ metalId: env.COLO_METADATA.metalId,
8725
+ coloTier: env.COLO_METADATA.coloTier,
8726
+ coloRegion: env.COLO_METADATA.coloRegion,
8727
+ hostname: url.hostname,
8728
+ version: env.VERSION_METADATA.id
8729
+ });
8730
+ let maybeSecondRequest = request.clone();
8731
+ return env.CONFIG.has_user_worker ? await env.ASSET_WORKER.unstable_canFetch(request) ? (analytics.setData({ dispatchtype: "asset" /* ASSETS */ }), await env.ASSET_WORKER.fetch(maybeSecondRequest)) : (analytics.setData({ dispatchtype: "worker" /* WORKER */ }), env.USER_WORKER.fetch(maybeSecondRequest)) : (analytics.setData({ dispatchtype: "asset" /* ASSETS */ }), await env.ASSET_WORKER.fetch(request));
8669
8732
  } catch (err) {
8670
- throw sentry && sentry.captureException(err), err;
8733
+ throw err instanceof Error && analytics.setData({ error: err.message }), sentry && sentry.captureException(err), err;
8734
+ } finally {
8735
+ analytics.setData({ requestTime: performance.now() - startTimeMs }), analytics.write(env.ENVIRONMENT, env.ANALYTICS);
8671
8736
  }
8672
8737
  }
8673
8738
  };