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.
@@ -8622,6 +8622,17 @@ var require_index_cjs = __commonJS({
8622
8622
  // ../workers-shared/asset-worker/src/index.ts
8623
8623
  import { WorkerEntrypoint } from "cloudflare:workers";
8624
8624
 
8625
+ // ../workers-shared/utils/performance.ts
8626
+ var PerformanceTimer = class {
8627
+ performanceTimer;
8628
+ constructor(performanceTimer) {
8629
+ this.performanceTimer = performanceTimer;
8630
+ }
8631
+ now() {
8632
+ return this.performanceTimer ? this.performanceTimer.timeOrigin + this.performanceTimer.now() : Date.now();
8633
+ }
8634
+ };
8635
+
8625
8636
  // ../workers-shared/utils/sentry.ts
8626
8637
  var import_toucan_js = __toESM(require_index_cjs());
8627
8638
  function setupSentry(request, context, dsn, clientId, clientSecret) {
@@ -8657,6 +8668,55 @@ function setupSentry(request, context, dsn, clientId, clientSecret) {
8657
8668
  return sentry.setUser({ userAgent, colo }), sentry;
8658
8669
  }
8659
8670
 
8671
+ // ../workers-shared/asset-worker/src/analytics.ts
8672
+ var Analytics = class {
8673
+ data = {};
8674
+ readyAnalytics;
8675
+ constructor(readyAnalytics) {
8676
+ this.readyAnalytics = readyAnalytics;
8677
+ }
8678
+ setData(newData) {
8679
+ this.data = { ...this.data, ...newData };
8680
+ }
8681
+ getData(key) {
8682
+ return this.data[key];
8683
+ }
8684
+ write() {
8685
+ this.readyAnalytics && this.readyAnalytics.logEvent({
8686
+ version: 1,
8687
+ accountId: 0,
8688
+ // TODO: need to plumb through
8689
+ indexId: this.data.hostname?.substring(0, 96),
8690
+ doubles: [
8691
+ this.data.requestTime ?? -1,
8692
+ // double1
8693
+ this.data.coloId ?? -1,
8694
+ // double2
8695
+ this.data.metalId ?? -1,
8696
+ // double3
8697
+ this.data.coloTier ?? -1
8698
+ // double4
8699
+ ],
8700
+ blobs: [
8701
+ this.data.hostname?.substring(0, 256),
8702
+ // blob1 - trim to 256 bytes
8703
+ this.data.userAgent?.substring(0, 256),
8704
+ // blob2 - trim to 256 bytes
8705
+ this.data.htmlHandling,
8706
+ // blob3
8707
+ this.data.notFoundHandling,
8708
+ // blob4
8709
+ this.data.error?.substring(0, 256),
8710
+ // blob5 - trim to 256 bytes
8711
+ this.data.version,
8712
+ // blob6
8713
+ this.data.coloRegion
8714
+ // blob7
8715
+ ]
8716
+ });
8717
+ }
8718
+ };
8719
+
8660
8720
  // ../workers-shared/asset-worker/src/assets-manifest.ts
8661
8721
  var AssetsManifest = class {
8662
8722
  data;
@@ -9204,23 +9264,45 @@ async function getAssetWithMetadataFromKV(assetsKVNamespace, assetKey, retries =
9204
9264
  // ../workers-shared/asset-worker/src/index.ts
9205
9265
  var src_default = class extends WorkerEntrypoint {
9206
9266
  async fetch(request) {
9207
- let sentry;
9267
+ let sentry, analytics = new Analytics(this.env.ANALYTICS), performance = new PerformanceTimer(this.env.UNSAFE_PERFORMANCE), startTimeMs = performance.now();
9208
9268
  try {
9209
- return sentry = setupSentry(
9269
+ sentry = setupSentry(
9210
9270
  request,
9211
9271
  this.ctx,
9212
9272
  this.env.SENTRY_DSN,
9213
9273
  this.env.SENTRY_ACCESS_CLIENT_ID,
9214
9274
  this.env.SENTRY_ACCESS_CLIENT_SECRET
9215
- ), handleRequest(
9275
+ );
9276
+ let config = applyConfigurationDefaults(this.env.CONFIG), userAgent = request.headers.get("user-agent") ?? "UA UNKNOWN";
9277
+ if (sentry) {
9278
+ let colo = this.env.COLO_METADATA.coloId;
9279
+ sentry.setTag("colo", this.env.COLO_METADATA.coloId), sentry.setTag("metal", this.env.COLO_METADATA.metalId), sentry.setUser({ userAgent, colo });
9280
+ }
9281
+ if (this.env.COLO_METADATA && this.env.VERSION_METADATA) {
9282
+ let url = new URL(request.url);
9283
+ analytics.setData({
9284
+ coloId: this.env.COLO_METADATA.coloId,
9285
+ metalId: this.env.COLO_METADATA.metalId,
9286
+ coloTier: this.env.COLO_METADATA.coloTier,
9287
+ coloRegion: this.env.COLO_METADATA.coloRegion,
9288
+ version: this.env.VERSION_METADATA.id,
9289
+ hostname: url.hostname,
9290
+ htmlHandling: config.html_handling,
9291
+ notFoundHandling: config.not_found_handling,
9292
+ userAgent
9293
+ });
9294
+ }
9295
+ return handleRequest(
9216
9296
  request,
9217
- applyConfigurationDefaults(this.env.CONFIG),
9297
+ config,
9218
9298
  this.unstable_exists.bind(this),
9219
9299
  this.unstable_getByETag.bind(this)
9220
9300
  );
9221
9301
  } catch (err) {
9222
9302
  let response = new InternalServerErrorResponse(err);
9223
- return sentry && sentry.captureException(err), response;
9303
+ return sentry && sentry.captureException(err), err instanceof Error && analytics.setData({ error: err.message }), response;
9304
+ } finally {
9305
+ analytics.setData({ requestTime: performance.now() - startTimeMs }), analytics.write();
9224
9306
  }
9225
9307
  }
9226
9308
  async unstable_canFetch(request) {