@hanzo/event 0.3.19 → 0.3.21
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/{core-D4PaPlOB.d.cts → core-CHLpJy51.d.cts} +56 -1
- package/dist/{core-D4PaPlOB.d.ts → core-CHLpJy51.d.ts} +56 -1
- package/dist/index.cjs +124 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -10
- package/dist/index.d.ts +66 -10
- package/dist/index.mjs +120 -27
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +119 -26
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +119 -26
- package/dist/react.mjs.map +1 -1
- package/hz.js +7 -8
- package/package.json +1 -1
- package/src/core.test.ts +48 -49
- package/src/core.ts +48 -27
- package/src/dsn.test.ts +28 -18
- package/src/dsn.ts +14 -34
- package/src/events.ts +5 -0
- package/src/exception.test.ts +188 -0
- package/src/exception.ts +200 -0
- package/src/hz.test.ts +4 -10
- package/src/index.ts +5 -1
- package/src/types.ts +53 -0
- package/src/version.ts +1 -1
package/dist/react.mjs
CHANGED
|
@@ -76,19 +76,16 @@ var PRODUCT_PROJECT = Object.freeze({
|
|
|
76
76
|
site: "019f9b1e-5785-7359-ad0b-f75db8e58c99"
|
|
77
77
|
// hanzo.ai (marketing; product `site`)
|
|
78
78
|
});
|
|
79
|
-
function dsnForProduct(product) {
|
|
80
|
-
if (!product) return void 0;
|
|
79
|
+
function dsnForProduct(product, key) {
|
|
80
|
+
if (!product || !key) return void 0;
|
|
81
81
|
const projectId = PRODUCT_PROJECT[product];
|
|
82
82
|
if (!projectId) return void 0;
|
|
83
|
-
return `https://${
|
|
84
|
-
}
|
|
85
|
-
var HANZO_PUBLISHABLE_KEY = "pk-live-c88649f1085fb6ad441d8a0072933a9b";
|
|
86
|
-
function defaultPublishableKey(host) {
|
|
87
|
-
return host === void 0 || host === "https://api.hanzo.ai" ? HANZO_PUBLISHABLE_KEY : void 0;
|
|
83
|
+
return `https://${key}@api.hanzo.ai/v1/sentry/${projectId}`;
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
// src/events.ts
|
|
91
87
|
var PAGEVIEW = "$pageview";
|
|
88
|
+
var EXCEPTION = "$exception";
|
|
92
89
|
|
|
93
90
|
// src/scrub.ts
|
|
94
91
|
var REDACTED = "[redacted]";
|
|
@@ -313,7 +310,7 @@ function hzAnonId() {
|
|
|
313
310
|
}
|
|
314
311
|
|
|
315
312
|
// src/version.ts
|
|
316
|
-
var VERSION = "0.3.
|
|
313
|
+
var VERSION = "0.3.21";
|
|
317
314
|
|
|
318
315
|
// src/sentry.ts
|
|
319
316
|
var MAX_FRAMES = 50;
|
|
@@ -505,6 +502,94 @@ ${itemHeader}
|
|
|
505
502
|
${payload}
|
|
506
503
|
`;
|
|
507
504
|
}
|
|
505
|
+
var MAX_VALUE = 4096;
|
|
506
|
+
function digest(s) {
|
|
507
|
+
let out = "";
|
|
508
|
+
for (const seed of [2166136261, 16777619, 2654435769, 2246822507]) {
|
|
509
|
+
let h = seed >>> 0;
|
|
510
|
+
for (let i = 0; i < s.length; i++) {
|
|
511
|
+
h ^= s.charCodeAt(i);
|
|
512
|
+
h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
|
|
513
|
+
}
|
|
514
|
+
out += h.toString(16).padStart(8, "0");
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
function frameOf(f) {
|
|
519
|
+
const source = f.filename ?? "";
|
|
520
|
+
const name = f.function ?? "<anonymous>";
|
|
521
|
+
const line = f.lineno ?? 0;
|
|
522
|
+
const column = f.colno ?? 0;
|
|
523
|
+
return {
|
|
524
|
+
// Stable per code location, so the same frame groups and re-renders under one
|
|
525
|
+
// key. The '/part' suffix is the product's format for one raw frame expanding
|
|
526
|
+
// into several resolved ones; a browser frame is always part 0.
|
|
527
|
+
raw_id: `${digest(`${source}|${name}|${line}|${column}`)}/0`,
|
|
528
|
+
mangled_name: name,
|
|
529
|
+
source,
|
|
530
|
+
line,
|
|
531
|
+
column,
|
|
532
|
+
in_app: f.in_app ?? false,
|
|
533
|
+
lang: "javascript",
|
|
534
|
+
resolved: false,
|
|
535
|
+
resolve_failure: "no symbol set uploaded for this release",
|
|
536
|
+
resolved_name: null,
|
|
537
|
+
module: null
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function truncate2(s, max) {
|
|
541
|
+
if (s.length <= max) return s;
|
|
542
|
+
let end = max;
|
|
543
|
+
const c = s.charCodeAt(end - 1);
|
|
544
|
+
if (c >= 55296 && c <= 56319) end--;
|
|
545
|
+
return s.slice(0, end);
|
|
546
|
+
}
|
|
547
|
+
function exceptionEntry(err, opts) {
|
|
548
|
+
const n = normalizeError(err);
|
|
549
|
+
const frames = framesFromStack(n.stack).slice(-50);
|
|
550
|
+
const entry = {
|
|
551
|
+
id: opts.id,
|
|
552
|
+
type: n.name,
|
|
553
|
+
value: truncate2(n.message, MAX_VALUE),
|
|
554
|
+
mechanism: {
|
|
555
|
+
type: "generic",
|
|
556
|
+
handled: opts.handled,
|
|
557
|
+
// An exception the app reported by hand was constructed, not thrown by the
|
|
558
|
+
// runtime at a real call site.
|
|
559
|
+
synthetic: !(err instanceof Error)
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
if (frames.length > 0) {
|
|
563
|
+
entry.stacktrace = { type: "resolved", frames: frames.map(frameOf) };
|
|
564
|
+
}
|
|
565
|
+
return entry;
|
|
566
|
+
}
|
|
567
|
+
function fingerprint(entry) {
|
|
568
|
+
const frames = entry.stacktrace?.frames ?? [];
|
|
569
|
+
const pieces = frames.filter((f) => f.in_app).map((f) => `${f.mangled_name}@${f.source}`);
|
|
570
|
+
return digest([entry.type, ...pieces].join("\n"));
|
|
571
|
+
}
|
|
572
|
+
function exceptionProperties(err, opts) {
|
|
573
|
+
const entry = exceptionEntry(err, opts);
|
|
574
|
+
const frames = entry.stacktrace?.frames ?? [];
|
|
575
|
+
const fp = fingerprint(entry);
|
|
576
|
+
return {
|
|
577
|
+
$exception_list: [entry],
|
|
578
|
+
$exception_fingerprint: fp,
|
|
579
|
+
// Records WHY this fingerprint holds. 'manual' is the honest value: the client
|
|
580
|
+
// supplied the key rather than a server grouper deriving one.
|
|
581
|
+
$exception_fingerprint_record: [{ type: "manual" }],
|
|
582
|
+
$exception_type: entry.type,
|
|
583
|
+
$exception_message: entry.value,
|
|
584
|
+
$exception_level: opts.level ?? "error",
|
|
585
|
+
$exception_handled: opts.handled,
|
|
586
|
+
$exception_synthetic: entry.mechanism?.synthetic ?? false,
|
|
587
|
+
$exception_types: [entry.type],
|
|
588
|
+
$exception_values: [entry.value],
|
|
589
|
+
$exception_sources: frames.map((f) => f.source).filter((s) => !!s),
|
|
590
|
+
$exception_functions: frames.map((f) => f.resolved_name ?? f.mangled_name).filter((s) => !!s)
|
|
591
|
+
};
|
|
592
|
+
}
|
|
508
593
|
|
|
509
594
|
// src/storage.ts
|
|
510
595
|
var KEY = {
|
|
@@ -676,27 +761,24 @@ var Analytics = class {
|
|
|
676
761
|
enabled: true,
|
|
677
762
|
captureErrors: true,
|
|
678
763
|
...config,
|
|
679
|
-
// The publishable key resolves
|
|
680
|
-
//
|
|
681
|
-
// enough. Most specific first:
|
|
764
|
+
// The publishable key resolves from ONE live source, never a literal baked
|
|
765
|
+
// beside the code. Most specific first:
|
|
682
766
|
// 1. an explicit `ingestKey` in config;
|
|
683
767
|
// 2. NEXT_PUBLIC_PUBLISHABLE_KEY, the inlined build-time env the fleet
|
|
684
|
-
// carries end to end
|
|
685
|
-
// build-arg -> the NEXT_PUBLIC_ prefix Next inlines
|
|
686
|
-
// 3. the hanzo org key baked in `dsn.ts`, on the hanzo cloud only.
|
|
768
|
+
// carries end to end — KMS `deploy/PUBLISHABLE_KEY` -> the PUBLISHABLE_KEY
|
|
769
|
+
// build-arg -> the NEXT_PUBLIC_ prefix Next inlines.
|
|
687
770
|
//
|
|
688
|
-
//
|
|
689
|
-
//
|
|
690
|
-
//
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
-
|
|
694
|
-
// its own cloud (a non-default host) gets no default, so the org this
|
|
695
|
-
// attributes to is never the wrong one.
|
|
696
|
-
ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY") ?? defaultPublishableKey(config.host ?? DEFAULT_HOST)
|
|
771
|
+
// A surface that provides neither has no key, and its anonymous traffic
|
|
772
|
+
// files under `$public` (which drops track/identify/group and answers 200);
|
|
773
|
+
// the fix is to give it the KMS-sourced env, not to hardcode the org key
|
|
774
|
+
// here. The key is a credential-class value: its home is KMS, and the ONE
|
|
775
|
+
// build reads it from there.
|
|
776
|
+
ingestKey: config.ingestKey ?? readEnv("NEXT_PUBLIC_PUBLISHABLE_KEY")
|
|
697
777
|
};
|
|
698
778
|
this.transport = config.transport ?? new DefaultTransport();
|
|
699
|
-
this.dsn = parseDsn(
|
|
779
|
+
this.dsn = parseDsn(
|
|
780
|
+
config.dsn ?? readEnvDsn() ?? dsnForProduct(this.cfg.product, this.cfg.ingestKey)
|
|
781
|
+
);
|
|
700
782
|
}
|
|
701
783
|
/** errorPlaneEnabled reports whether captured exceptions can actually reach the
|
|
702
784
|
* error host. False means a DSN was never configured — the documented
|
|
@@ -781,9 +863,20 @@ var Analytics = class {
|
|
|
781
863
|
} catch {
|
|
782
864
|
}
|
|
783
865
|
try {
|
|
866
|
+
const handled = context?.handled ?? true;
|
|
784
867
|
const ex = normalizeError2(err);
|
|
785
|
-
ex.handled =
|
|
786
|
-
this.enqueue("
|
|
868
|
+
ex.handled = handled;
|
|
869
|
+
this.enqueue("event", EXCEPTION, {
|
|
870
|
+
error: ex,
|
|
871
|
+
properties: {
|
|
872
|
+
...context?.properties,
|
|
873
|
+
...exceptionProperties(err, {
|
|
874
|
+
handled,
|
|
875
|
+
id: hzUuidv7(),
|
|
876
|
+
level: context?.level
|
|
877
|
+
})
|
|
878
|
+
}
|
|
879
|
+
});
|
|
787
880
|
this.flush();
|
|
788
881
|
} catch {
|
|
789
882
|
}
|