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