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