@hanzo/event 0.3.19 → 0.3.20

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.
package/dist/react.mjs CHANGED
@@ -89,6 +89,7 @@ function defaultPublishableKey(host) {
89
89
 
90
90
  // src/events.ts
91
91
  var PAGEVIEW = "$pageview";
92
+ var EXCEPTION = "$exception";
92
93
 
93
94
  // src/scrub.ts
94
95
  var REDACTED = "[redacted]";
@@ -313,7 +314,7 @@ function hzAnonId() {
313
314
  }
314
315
 
315
316
  // src/version.ts
316
- var VERSION = "0.3.19";
317
+ var VERSION = "0.3.20";
317
318
 
318
319
  // src/sentry.ts
319
320
  var MAX_FRAMES = 50;
@@ -505,6 +506,94 @@ ${itemHeader}
505
506
  ${payload}
506
507
  `;
507
508
  }
509
+ var MAX_VALUE = 4096;
510
+ function digest(s) {
511
+ let out = "";
512
+ for (const seed of [2166136261, 16777619, 2654435769, 2246822507]) {
513
+ let h = seed >>> 0;
514
+ for (let i = 0; i < s.length; i++) {
515
+ h ^= s.charCodeAt(i);
516
+ h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
517
+ }
518
+ out += h.toString(16).padStart(8, "0");
519
+ }
520
+ return out;
521
+ }
522
+ function frameOf(f) {
523
+ const source = f.filename ?? "";
524
+ const name = f.function ?? "<anonymous>";
525
+ const line = f.lineno ?? 0;
526
+ const column = f.colno ?? 0;
527
+ return {
528
+ // Stable per code location, so the same frame groups and re-renders under one
529
+ // key. The '/part' suffix is the product's format for one raw frame expanding
530
+ // into several resolved ones; a browser frame is always part 0.
531
+ raw_id: `${digest(`${source}|${name}|${line}|${column}`)}/0`,
532
+ mangled_name: name,
533
+ source,
534
+ line,
535
+ column,
536
+ in_app: f.in_app ?? false,
537
+ lang: "javascript",
538
+ resolved: false,
539
+ resolve_failure: "no symbol set uploaded for this release",
540
+ resolved_name: null,
541
+ module: null
542
+ };
543
+ }
544
+ function truncate2(s, max) {
545
+ if (s.length <= max) return s;
546
+ let end = max;
547
+ const c = s.charCodeAt(end - 1);
548
+ if (c >= 55296 && c <= 56319) end--;
549
+ return s.slice(0, end);
550
+ }
551
+ function exceptionEntry(err, opts) {
552
+ const n = normalizeError(err);
553
+ const frames = framesFromStack(n.stack).slice(-50);
554
+ const entry = {
555
+ id: opts.id,
556
+ type: n.name,
557
+ value: truncate2(n.message, MAX_VALUE),
558
+ mechanism: {
559
+ type: "generic",
560
+ handled: opts.handled,
561
+ // An exception the app reported by hand was constructed, not thrown by the
562
+ // runtime at a real call site.
563
+ synthetic: !(err instanceof Error)
564
+ }
565
+ };
566
+ if (frames.length > 0) {
567
+ entry.stacktrace = { type: "resolved", frames: frames.map(frameOf) };
568
+ }
569
+ return entry;
570
+ }
571
+ function fingerprint(entry) {
572
+ const frames = entry.stacktrace?.frames ?? [];
573
+ const pieces = frames.filter((f) => f.in_app).map((f) => `${f.mangled_name}@${f.source}`);
574
+ return digest([entry.type, ...pieces].join("\n"));
575
+ }
576
+ function exceptionProperties(err, opts) {
577
+ const entry = exceptionEntry(err, opts);
578
+ const frames = entry.stacktrace?.frames ?? [];
579
+ const fp = fingerprint(entry);
580
+ return {
581
+ $exception_list: [entry],
582
+ $exception_fingerprint: fp,
583
+ // Records WHY this fingerprint holds. 'manual' is the honest value: the client
584
+ // supplied the key rather than a server grouper deriving one.
585
+ $exception_fingerprint_record: [{ type: "manual" }],
586
+ $exception_type: entry.type,
587
+ $exception_message: entry.value,
588
+ $exception_level: opts.level ?? "error",
589
+ $exception_handled: opts.handled,
590
+ $exception_synthetic: entry.mechanism?.synthetic ?? false,
591
+ $exception_types: [entry.type],
592
+ $exception_values: [entry.value],
593
+ $exception_sources: frames.map((f) => f.source).filter((s) => !!s),
594
+ $exception_functions: frames.map((f) => f.resolved_name ?? f.mangled_name).filter((s) => !!s)
595
+ };
596
+ }
508
597
 
509
598
  // src/storage.ts
510
599
  var KEY = {
@@ -781,9 +870,20 @@ var Analytics = class {
781
870
  } catch {
782
871
  }
783
872
  try {
873
+ const handled = context?.handled ?? true;
784
874
  const ex = normalizeError2(err);
785
- ex.handled = context?.handled ?? true;
786
- this.enqueue("error", ex.message, { error: ex, properties: context?.properties });
875
+ ex.handled = handled;
876
+ this.enqueue("event", EXCEPTION, {
877
+ error: ex,
878
+ properties: {
879
+ ...context?.properties,
880
+ ...exceptionProperties(err, {
881
+ handled,
882
+ id: hzUuidv7(),
883
+ level: context?.level
884
+ })
885
+ }
886
+ });
787
887
  this.flush();
788
888
  } catch {
789
889
  }