UNPKG

@jumio/websdk

Version:

Jumio WebSDK is a powerful, flexible software development kit that simplifies the integration of Jumio's services into your web applications.

228 lines (227 loc) 7.2 kB
import { R as z, a as H, c as K, s as q, b as Q, d as m, e as I, f as W, m as v, h as X, i as Y, j as Z, k as $, l as x, r as ee } from "./index.C2zhSnEu.js"; function te(t) { let n = 0; for (const i of t) i.stackId !== void 0 && n++; return n; } const b = /* @__PURE__ */ new Map(); function ne(t, n) { b.set(n, t); } function se(t) { return b.get(t); } function O(t) { for (const n of b.keys()) n < t && b.delete(n); } function re({ rawRumEvent: t, startTime: n }) { if (t.type !== z.LONG_TASK) return; const i = t.long_task.id; ne(i, n); } const oe = (t, n, i, r) => { const l = ae(t, n, i, r), f = le(t, l), c = n.build("fetch", f); return H("Sending profile to public profiling intake", { profilingIntakeURL: c, applicationId: i, sessionId: r }), fetch(c, { body: f.data, method: "POST" }); }; function ae(t, n, i, r) { const l = n.tags, f = ce(t, i, r), c = ie(l); return { ...f, attachments: ["wall-time.json"], start: new Date(t.startClocks.timeStamp).toISOString(), end: new Date(t.endClocks.timeStamp).toISOString(), family: "chrome", runtime: "chrome", format: "json", version: 4, // Ingestion event version (not the version application tag) tags_profiler: c.join(","), _dd: { clock_drift: K() } }; } function ie(t) { return t.concat(["language:javascript", "runtime:chrome", "family:chrome", "host:browser"]); } function le(t, n) { const i = new Blob([JSON.stringify(t)], { type: "application/json" }), r = new FormData(); return r.append("event", new Blob([JSON.stringify(n)], { type: "application/json" }), "event.json"), r.append("wall-time.json", i, "wall-time.json"), { data: r, bytesCount: 0 }; } function ce(t, n, i) { const r = { application: { id: n } }; i && (r.session = { id: i }); const l = Array.from(new Set(t.views.map((c) => c.viewId))); l.length && (r.view = { id: l }); const f = t.longTasks.map((c) => c.id).filter((c) => c !== void 0); return f.length && (r.long_task = { id: f }), r; } const ue = { sendProfile: oe }, de = { sampleIntervalMs: 10, // Sample stack trace every 10ms collectIntervalMs: 6e4, // Collect data every minute minProfileDurationMs: 5e3, // Require at least 5 seconds of profile data to reduce noise and cost minNumberOfSamples: 50 // Require at least 50 samples (~500 ms) to report a profile to reduce noise and cost }; function pe(t, n, i, r, l = de) { const f = q(Q.LONG_ANIMATION_FRAME); let c; const g = []; let o = { state: "stopped" }; function _(e) { o.state !== "running" && (c = e ? { startClocks: e.startClocks, viewId: e.id, viewName: e.name } : void 0, g.push(I(t, window, "visibilitychange", R).stop, I(t, window, "beforeunload", j).stop), p()); } async function L() { await T("stopped"), g.forEach((e) => e()), O(m().relative), r.set({ status: "stopped", error_reason: void 0 }); } function N(e) { if (e.state === "running") return { cleanupTasks: e.cleanupTasks, observer: e.observer }; const s = []; let a; if (t.trackLongTasks) { a = new PerformanceObserver(M), a.observe({ entryTypes: [A()] }); const u = n.subscribe(12, (h) => { re(h); }); s.push(() => a == null ? void 0 : a.disconnect()), s.push(u.unsubscribe); } const d = n.subscribe(2, (u) => { y({ viewId: u.id, viewName: u.name, startClocks: u.startClocks }); }); return s.push(d.unsubscribe), { cleanupTasks: s, observer: a }; } function p() { const e = W().Profiler; if (!e) throw r.set({ status: "error", error_reason: "not-supported-by-browser" }), new Error("RUM Profiler is not supported in this browser."); k(o).catch(v); const { cleanupTasks: s, observer: a } = N(o); let d; try { d = new e({ sampleInterval: l.sampleIntervalMs, // Keep buffer size at 1.5 times of minimum required to collect data for a profiling instance maxBufferSize: Math.round(l.collectIntervalMs * 1.5 / l.sampleIntervalMs) }); } catch (u) { u instanceof Error && u.message.includes("disabled by Document Policy") ? (X.warn("[DD_RUM] Profiler startup failed. Ensure your server includes the `Document-Policy: js-profiling` response header when serving HTML pages.", u), r.set({ status: "error", error_reason: "missing-document-policy-header" })) : r.set({ status: "error", error_reason: "unexpected-exception" }); return; } r.set({ status: "running", error_reason: void 0 }), o = { state: "running", startClocks: m(), profiler: d, timeoutId: Y(p, l.collectIntervalMs), longTasks: [], views: [], cleanupTasks: s, observer: a }, y(c), d.addEventListener("samplebufferfull", w); } async function k(e) { var s, a; if (e.state !== "running") return; S((a = (s = e.observer) === null || s === void 0 ? void 0 : s.takeRecords()) !== null && a !== void 0 ? a : []), Z(e.timeoutId), e.profiler.removeEventListener("samplebufferfull", w); const { startClocks: d, longTasks: u, views: h } = e, C = m(); await e.profiler.stop().then((P) => { const E = m(), G = u.length > 0, V = $(d.timeStamp, E.timeStamp) < l.minProfileDurationMs, J = te(P.samples) < l.minNumberOfSamples; !G && (V || J) || (D( // Enrich trace with time and instance data Object.assign(P, { startClocks: d, endClocks: E, clocksOrigin: x(), longTasks: u, views: h, sampleInterval: l.sampleIntervalMs }) ), O(C.relative)); }).catch(v); } async function T(e) { o.state === "running" && (o.cleanupTasks.forEach((s) => s()), await k(o), o = { state: e }); } function y(e) { o.state !== "running" || !e || o.views.push(e); } function D(e) { var s; const a = (s = i.findTrackedSession()) === null || s === void 0 ? void 0 : s.id; ue.sendProfile(e, t.profilingEndpointBuilder, t.applicationId, a).catch(v); } function w() { p(); } function M(e) { S(e.getEntries()); } function S(e) { if (o.state === "running") for (const s of e) { if (s.duration < l.sampleIntervalMs) continue; const a = ee(s.startTime), d = se(a.relative); o.longTasks.push({ id: d, duration: s.duration, entryType: s.entryType, startClocks: a }); } } function R() { document.visibilityState === "hidden" && o.state === "running" ? T("paused").catch(v) : document.visibilityState === "visible" && o.state === "paused" && p(); } function j() { p(); } function A() { return f ? "long-animation-frame" : "longtask"; } function B() { return o.state === "stopped"; } function F() { return o.state === "running"; } function U() { return o.state === "paused"; } return { start: _, stop: L, isStopped: B, isRunning: F, isPaused: U }; } export { de as DEFAULT_RUM_PROFILER_CONFIGURATION, pe as createRumProfiler }; //# sourceMappingURL=profiler.9_ek2EsJ.js.map