miniflare 0.0.0-ecef68635 → 0.0.0-ee305dd67

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,78 @@ 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
+ readyAnalytics;
8672
+ constructor(readyAnalytics) {
8673
+ this.readyAnalytics = readyAnalytics;
8674
+ }
8675
+ setData(newData) {
8676
+ this.data = { ...this.data, ...newData };
8677
+ }
8678
+ getData(key) {
8679
+ return this.data[key];
8680
+ }
8681
+ write() {
8682
+ this.readyAnalytics && this.readyAnalytics.logEvent({
8683
+ version: 1,
8684
+ accountId: 0,
8685
+ // TODO: need to plumb through
8686
+ indexId: this.data.hostname?.substring(0, 96),
8687
+ doubles: [
8688
+ this.data.requestTime ?? -1,
8689
+ // double1
8690
+ this.data.coloId ?? -1,
8691
+ // double2
8692
+ this.data.metalId ?? -1,
8693
+ // double3
8694
+ this.data.coloTier ?? -1
8695
+ // double4
8696
+ ],
8697
+ blobs: [
8698
+ this.data.hostname?.substring(0, 256),
8699
+ // blob1 - trim to 256 bytes
8700
+ this.data.dispatchtype,
8701
+ // blob2
8702
+ this.data.error?.substring(0, 256),
8703
+ // blob3 - trim to 256 bytes
8704
+ this.data.version,
8705
+ // blob4
8706
+ this.data.coloRegion
8707
+ // blob5
8708
+ ]
8709
+ });
8710
+ }
8711
+ };
8712
+
8657
8713
  // ../workers-shared/router-worker/src/index.ts
8658
8714
  var src_default = {
8659
8715
  async fetch(request, env, ctx) {
8660
- let sentry, maybeSecondRequest = request.clone();
8716
+ let sentry, analytics = new Analytics(env.ANALYTICS), performance = new PerformanceTimer(env.UNSAFE_PERFORMANCE), startTimeMs = performance.now();
8661
8717
  try {
8662
- return sentry = setupSentry(
8718
+ sentry = setupSentry(
8663
8719
  request,
8664
8720
  ctx,
8665
8721
  env.SENTRY_DSN,
8666
8722
  env.SENTRY_ACCESS_CLIENT_ID,
8667
8723
  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);
8724
+ );
8725
+ let url = new URL(request.url);
8726
+ 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({
8727
+ coloId: env.COLO_METADATA.coloId,
8728
+ metalId: env.COLO_METADATA.metalId,
8729
+ coloTier: env.COLO_METADATA.coloTier,
8730
+ coloRegion: env.COLO_METADATA.coloRegion,
8731
+ hostname: url.hostname,
8732
+ version: env.VERSION_METADATA.id
8733
+ });
8734
+ let maybeSecondRequest = request.clone();
8735
+ 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
8736
  } catch (err) {
8670
- throw sentry && sentry.captureException(err), err;
8737
+ throw err instanceof Error && analytics.setData({ error: err.message }), sentry && sentry.captureException(err), err;
8738
+ } finally {
8739
+ analytics.setData({ requestTime: performance.now() - startTimeMs }), analytics.write();
8671
8740
  }
8672
8741
  }
8673
8742
  };