datadog-ux-utils
Version:
Datadog RUM focused UX & performance toolkit: API guards (retry, breaker, rate), React telemetry (error boundary, profiler, Suspense), web vitals & resource observers, offline queues.
74 lines (73 loc) • 1.52 kB
JavaScript
import { a as u } from "./datadog-irY4zUa4.js";
import { g as s } from "./config-D7lUKPO2.js";
let t = null, r = [], i = null, o = !1;
const f = {
sampleRate: 0.25,
flushIntervalMs: 5e3,
allowInDev: !1,
sink: (n) => {
n.forEach((e) => {
try {
u(
"ds_component_mount",
e,
Math.round((t?.sampleRate ?? 1) * 100)
);
} catch {
}
});
}
};
function h(n = {}) {
if (o) return;
const e = {
...f,
...n
}, a = s().env;
if (!e.allowInDev && a === "dev") {
o = !0;
return;
}
t = e, o = !0, !i && t.flushIntervalMs > 0 && (i = window.setInterval(() => l(), t.flushIntervalMs), window.addEventListener("visibilitychange", () => {
document.visibilityState === "hidden" && l(!0);
}));
}
function d(n, e) {
if (!o || !t || !e?.force && Math.random() > t.sampleRate) return;
const a = s();
r.push({
t: "component_mount",
ts: Date.now(),
component: n,
libVersion: a.version,
app: a.appName,
env: a.env,
route: e?.route ?? c(),
variant: e?.variant
}), r.length >= 50 && l();
}
function l(n = !1) {
if (!t || r.length === 0) return;
const e = r.splice(0, r.length);
try {
t.sink(e);
} catch {
}
}
function c() {
try {
return window.location.pathname;
} catch {
return;
}
}
function p() {
i && clearInterval(i), i = null, r = [], t = null, o = !1;
}
export {
p as _,
l as f,
h as i,
d as r
};
//# sourceMappingURL=componentTelemetry-B8Ifhf_1.js.map