@aidenappleby/monitor-js 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -52,8 +52,15 @@ monitor.shutdown();
52
52
  Uncaught errors and unhandled rejections are captured automatically in **both** the
53
53
  browser (`window`) and Node (`process.on`) — disable with `captureErrors: false` /
54
54
  `captureUnhandledRejections: false`. Filter noise with
55
- `ignoreErrors: [/extension/i, "ResizeObserver"]`. The Node handlers report and return;
56
- they do not alter process-crash behavior.
55
+ `ignoreErrors: [/extension/i, "ResizeObserver"]`.
56
+
57
+ In Node, installing a process listener would normally stop an uncaught exception from
58
+ crashing the process. The SDK keeps Node's behavior: when it is the **only**
59
+ `uncaughtException` listener, it reports, prints the error, waits up to 1.5s for the batch
60
+ to leave, and exits 1; an unhandled rejection with no other listener is re-raised as an
61
+ uncaught exception, exactly as Node does by default. If your app has its own listener, the
62
+ SDK only reports. Server code that manages its own crash handling (e.g. a Next.js
63
+ `instrumentation.ts`) should pass `captureErrors: false, captureUnhandledRejections: false`.
57
64
 
58
65
  ### Correlation ids
59
66
 
package/dist/index.d.mts CHANGED
@@ -152,8 +152,18 @@ declare class Monitor {
152
152
  private currentPath;
153
153
  private errorHandler;
154
154
  private rejectionHandler;
155
+ /** Grace for the final batch to leave before a Node-style crash exits. */
156
+ private static readonly NODE_CRASH_GRACE_MS;
157
+ /** Rejections already reported, so the re-raise below is not reported twice. */
158
+ private reportedRejections;
155
159
  private nodeExceptionHandler;
156
160
  private nodeRejectionHandler;
161
+ /** Hand an unhandled rejection back to Node as an uncaught exception. */
162
+ private reraise;
163
+ /** True when this instance's own handler is the only listener for the event. */
164
+ private isSoleListener;
165
+ /** Print the error as Node would, give the batch a moment to leave, exit 1. */
166
+ private crashLikeNode;
157
167
  private installErrorHandler;
158
168
  private installRejectionHandler;
159
169
  private removeListeners;
package/dist/index.d.ts CHANGED
@@ -152,8 +152,18 @@ declare class Monitor {
152
152
  private currentPath;
153
153
  private errorHandler;
154
154
  private rejectionHandler;
155
+ /** Grace for the final batch to leave before a Node-style crash exits. */
156
+ private static readonly NODE_CRASH_GRACE_MS;
157
+ /** Rejections already reported, so the re-raise below is not reported twice. */
158
+ private reportedRejections;
155
159
  private nodeExceptionHandler;
156
160
  private nodeRejectionHandler;
161
+ /** Hand an unhandled rejection back to Node as an uncaught exception. */
162
+ private reraise;
163
+ /** True when this instance's own handler is the only listener for the event. */
164
+ private isSoleListener;
165
+ /** Print the error as Node would, give the batch a moment to leave, exit 1. */
166
+ private crashLikeNode;
157
167
  private installErrorHandler;
158
168
  private installRejectionHandler;
159
169
  private removeListeners;
package/dist/index.js CHANGED
@@ -93,7 +93,7 @@ function normalizeLevel(level) {
93
93
  const l = (level || "info").toLowerCase();
94
94
  return l === "warning" ? "warn" : l;
95
95
  }
96
- var Monitor = class {
96
+ var Monitor = class _Monitor {
97
97
  config;
98
98
  ignoreErrors = [];
99
99
  onDrop;
@@ -431,33 +431,72 @@ var Monitor = class {
431
431
  });
432
432
  };
433
433
  // --- Node process handlers ---
434
- // uncaughtException/unhandledRejection are non-terminating here: we report the
435
- // error and return without calling process.exit, matching the browser handlers'
436
- // non-terminating behavior. Consumers keep their own crash semantics.
434
+ // Adding an uncaughtException or unhandledRejection listener changes what Node
435
+ // does. With no listener, either one prints the error and exits with code 1;
436
+ // with any listener, Node assumes it was handled and keeps running — in
437
+ // whatever state the failure left it. So when this SDK is the only listener,
438
+ // it reports the error and then does what Node would have done. When the app
439
+ // has a listener of its own, the app has already decided; the SDK only reports.
440
+ /** Grace for the final batch to leave before a Node-style crash exits. */
441
+ static NODE_CRASH_GRACE_MS = 1500;
442
+ /** Rejections already reported, so the re-raise below is not reported twice. */
443
+ reportedRejections = /* @__PURE__ */ new WeakSet();
437
444
  nodeExceptionHandler = (err) => {
445
+ const alreadyReported = typeof err === "object" && err !== null && this.reportedRejections.has(err);
438
446
  const e = err;
439
447
  const message = e?.message ?? String(err);
440
448
  const stack = e?.stack;
441
- if (this.shouldIgnoreError(message, stack)) return;
442
- this.emit("client.error.uncaught", "error", {
443
- data: {
444
- message,
445
- stack
446
- }
447
- });
449
+ if (!alreadyReported && !this.shouldIgnoreError(message, stack)) {
450
+ this.emit("client.error.uncaught", "error", {
451
+ data: {
452
+ message,
453
+ stack
454
+ }
455
+ });
456
+ }
457
+ if (this.isSoleListener("uncaughtException")) {
458
+ this.crashLikeNode(err);
459
+ }
448
460
  };
449
461
  nodeRejectionHandler = (reason) => {
450
462
  const r = reason;
451
463
  const message = r?.message ?? String(reason);
452
464
  const stack = r?.stack;
453
- if (this.shouldIgnoreError(message, stack)) return;
454
- this.emit("client.error.unhandled_rejection", "error", {
455
- data: {
456
- message,
457
- stack
465
+ if (!this.shouldIgnoreError(message, stack)) {
466
+ this.emit("client.error.unhandled_rejection", "error", {
467
+ data: {
468
+ message,
469
+ stack
470
+ }
471
+ });
472
+ }
473
+ if (this.isSoleListener("unhandledRejection")) {
474
+ if (typeof reason === "object" && reason !== null) {
475
+ this.reportedRejections.add(reason);
458
476
  }
459
- });
477
+ this.reraise(reason);
478
+ }
460
479
  };
480
+ /** Hand an unhandled rejection back to Node as an uncaught exception. */
481
+ reraise(reason) {
482
+ process?.nextTick?.(() => {
483
+ throw reason;
484
+ });
485
+ }
486
+ /** True when this instance's own handler is the only listener for the event. */
487
+ isSoleListener(event) {
488
+ const count = typeof process === "undefined" ? void 0 : process.listenerCount;
489
+ if (typeof count !== "function") {
490
+ return false;
491
+ }
492
+ return count.call(process, event) <= 1;
493
+ }
494
+ /** Print the error as Node would, give the batch a moment to leave, exit 1. */
495
+ crashLikeNode(err) {
496
+ console.error(err);
497
+ this.flush();
498
+ setTimeout(() => process?.exit?.(1), _Monitor.NODE_CRASH_GRACE_MS);
499
+ }
461
500
  installErrorHandler() {
462
501
  if (typeof window !== "undefined") {
463
502
  window.addEventListener("error", this.errorHandler);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ids.ts","../src/client.ts","../src/axios.ts"],"sourcesContent":["export { Monitor } from \"./client\";\nexport { attachAxiosMonitor } from \"./axios\";\nexport { isValidCorrelationId, newRequestId, newTraceId, newJobId } from \"./ids\";\nexport type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nexport type { AxiosMonitorOptions } from \"./axios\";\n","/**\n * monitor-core's correlation-id rule (structs.correlationIDRegex), verbatim.\n *\n * Ingest validates job_id, request_id and trace_id against it and rejects the\n * WHOLE request when any line fails — so one malformed id, passed through\n * unchecked, loses every event batched with it.\n */\nconst CORRELATION_ID =\n /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|[0-9a-fA-F]{8,64})$/;\n\n/**\n * Whether monitor-core would accept `id` as a job_id, request_id or trace_id.\n * The empty string is valid: the server skips empty ids.\n */\nexport function isValidCorrelationId(id: string): boolean {\n return id === \"\" || CORRELATION_ID.test(id);\n}\n\nfunction randomBytes(n: number): Uint8Array {\n const out = new Uint8Array(n);\n const c = (globalThis as { crypto?: { getRandomValues?: (a: Uint8Array) => Uint8Array } }).crypto;\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(out);\n return out;\n }\n // Node 18 has no global crypto. Correlation ids need uniqueness, not secrecy.\n for (let i = 0; i < n; i++) out[i] = Math.floor(Math.random() * 256);\n return out;\n}\n\nfunction hex(bytes: Uint8Array): string {\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** A request_id monitor-core accepts: 16 hex characters. */\nexport function newRequestId(): string {\n return hex(randomBytes(8));\n}\n\n/** A job_id monitor-core accepts: 16 hex characters. */\nexport function newJobId(): string {\n return hex(randomBytes(8));\n}\n\n/** A trace_id monitor-core accepts: a hyphenated UUID v4. */\nexport function newTraceId(): string {\n const b = randomBytes(16);\n b[6] = (b[6] & 0x0f) | 0x40; // version 4\n b[8] = (b[8] & 0x3f) | 0x80; // RFC 4122 variant\n const h = hex(b);\n return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;\n}\n","import type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nimport { isValidCorrelationId, newJobId } from \"./ids\";\n\n// Minimal ambient shape for the Node `process` global — this package has no\n// @types/node dependency and targets the browser too, so `process` may be absent.\n// Guarded with `typeof process !== \"undefined\"` before use.\ndeclare const process:\n | {\n on?(event: string, listener: (...args: unknown[]) => void): void;\n removeListener?(event: string, listener: (...args: unknown[]) => void): void;\n }\n | undefined;\n\nconst DEFAULT_FLUSH_INTERVAL = 2000;\nconst DEFAULT_BATCH_SIZE = 20;\nconst MAX_QUEUE_SIZE = 500;\n\n/**\n * monitor-core scans NDJSON with a 1 MiB line buffer and rejects the WHOLE\n * request when one line overflows it, so an oversized event is shrunk before it\n * is sent rather than discovered by a 400.\n */\nconst MAX_LINE_BYTES = 1_000_000;\n/** Characters kept per grouping field when an oversized event is shrunk. */\nconst MAX_FIELD_CHARS = 4096;\n/**\n * Browsers refuse a keepalive request once the page's in-flight keepalive\n * bodies exceed 64 KiB, and the refusal is a plain TypeError. Asking for\n * keepalive on a bigger body would fail — and be retried — forever.\n */\nconst KEEPALIVE_MAX_BYTES = 60_000;\n/** Backoff bounds after a transient ingest failure. */\nconst BASE_BACKOFF_MS = 1000;\nconst MAX_BACKOFF_MS = 60_000;\n\n/** The data keys monitor-core's issue fingerprint reads; they survive shrinking. */\nconst GROUPING_KEYS = [\"error\", \"error_message\", \"message\", \"path\", \"uri\", \"method\", \"reason\", \"status_code\"];\n\ntype Outcome = \"delivered\" | \"rejected\" | \"misconfigured\" | \"retryable\";\n\n/** How an ingest response should be handled. Mirrors go-monitor's classifyStatus. */\nfunction classify(status: number): Outcome {\n if (status >= 200 && status < 400) return \"delivered\";\n if (status === 408 || status === 429) return \"retryable\";\n if (status === 401 || status === 403 || status === 404 || status === 405) return \"misconfigured\";\n if (status >= 400 && status < 500) return \"rejected\";\n return \"retryable\";\n}\n\n/** Extra requests allowed to isolate malformed events in a batch of n. */\nfunction bisectBudget(n: number): number {\n let depth = 0;\n for (let x = n; x > 1; x = Math.ceil(x / 2)) depth++;\n return 4 * depth + 4;\n}\n\nlet encoder: TextEncoder | undefined;\nfunction byteLength(s: string): number {\n if (typeof TextEncoder === \"undefined\") return s.length * 3;\n encoder ??= new TextEncoder();\n return encoder.encode(s).length;\n}\n\n/**\n * monitor-core stores level verbatim and groups only exact \"error\"/\"fatal\" into\n * issues, so \"ERROR\" or \"warning\" would land and silently never be tracked.\n */\nfunction normalizeLevel(level: string): string {\n const l = (level || \"info\").toLowerCase();\n return l === \"warning\" ? \"warn\" : l;\n}\n\nexport class Monitor {\n private config: Required<\n Pick<MonitorConfig, \"service\" | \"ingestUrl\" | \"apiKey\" | \"env\" | \"flushInterval\" | \"batchSize\" | \"debug\">\n >;\n private ignoreErrors: (string | RegExp)[] = [];\n private onDrop?: (total: number) => void;\n private queue: MonitorEvent[] = [];\n private timer: ReturnType<typeof setInterval> | null = null;\n private userId: string = \"\";\n private jobId: string;\n private active = false;\n private backoffUntil = 0;\n private failures = 0;\n private warnedMisconfigured = false;\n private counters = { enqueued: 0, flushed: 0, dropped: 0, quarantined: 0 };\n\n constructor(config: MonitorConfig) {\n this.config = {\n service: config.service,\n ingestUrl: config.ingestUrl,\n apiKey: config.apiKey,\n env: config.env ?? \"production\",\n flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n debug: config.debug ?? false,\n };\n this.ignoreErrors = config.ignoreErrors ?? [];\n this.onDrop = config.onDrop;\n // One id per page load (or process): every event from this session\n // shares it, so a session's events can be pulled up together.\n this.jobId = newJobId();\n\n this.start();\n\n if (config.captureErrors !== false) {\n this.installErrorHandler();\n }\n if (config.captureUnhandledRejections !== false) {\n this.installRejectionHandler();\n }\n }\n\n /** Set a persistent user ID for all subsequent events */\n setUser(userId: string): void {\n this.userId = userId;\n }\n\n /** Clear the user ID */\n clearUser(): void {\n this.userId = \"\";\n }\n\n /**\n * Set a persistent job ID (session-level identifier). It must be a UUID or\n * 8-64 hex characters — see `isValidCorrelationId`; anything else is\n * cleared from each event and kept in data.invalid_job_id.\n */\n setJobId(jobId: string): void {\n this.jobId = jobId;\n }\n\n /** Emit an event at a specific level */\n emit(name: string, level: LogLevel, opts?: EmitOptions): void {\n if (!this.active) return;\n\n // An id monitor-core would reject is cleared, not sent: one bad id\n // fails the whole request. The original is kept where it is useful.\n let data: Record<string, unknown> = opts?.data ?? {};\n const repair = (field: string, value: string): string => {\n if (isValidCorrelationId(value)) return value;\n data = { ...data, [`invalid_${field}`]: value.slice(0, 128) };\n if (this.config.debug) {\n console.warn(`[monitor] cleared invalid ${field} ${JSON.stringify(value)} (monitor-core accepts a UUID or 8-64 hex characters)`);\n }\n return \"\";\n };\n const jobId = repair(\"job_id\", this.jobId);\n const requestId = repair(\"request_id\", opts?.requestId ?? \"\");\n const traceId = repair(\"trace_id\", opts?.traceId ?? \"\");\n\n const event: MonitorEvent = {\n timestamp: new Date().toISOString(),\n service: this.config.service,\n env: this.config.env,\n job_id: jobId,\n request_id: requestId,\n trace_id: traceId,\n user_id: opts?.userId ?? this.userId,\n name: name || \"event.unnamed\",\n level: normalizeLevel(level),\n data,\n };\n\n if (this.queue.length >= MAX_QUEUE_SIZE) {\n // Drop oldest events to prevent unbounded memory growth\n this.queue.shift();\n this.recordDrop(1);\n }\n\n this.queue.push(event);\n this.counters.enqueued++;\n\n if (this.config.debug) {\n console.debug(`[monitor] ${level} ${name}`, opts?.data);\n }\n\n if (this.queue.length >= this.config.batchSize) {\n this.flush();\n }\n }\n\n /** Emit a debug event */\n debug(name: string, opts?: EmitOptions): void {\n this.emit(name, \"debug\", opts);\n }\n\n /** Emit an info event */\n info(name: string, opts?: EmitOptions): void {\n this.emit(name, \"info\", opts);\n }\n\n /** Emit a warning event */\n warn(name: string, opts?: EmitOptions): void {\n this.emit(name, \"warn\", opts);\n }\n\n /** Emit an error event */\n error(name: string, opts?: EmitOptions): void {\n this.emit(name, \"error\", opts);\n }\n\n /** Emit a fatal event */\n fatal(name: string, opts?: EmitOptions): void {\n this.emit(name, \"fatal\", opts);\n }\n\n /**\n * Lifetime counters. Surface them wherever loss would otherwise go\n * unnoticed: the system that would report dropped telemetry is the one\n * dropping it.\n */\n stats(): MonitorStats {\n return { ...this.counters, queued: this.queue.length };\n }\n\n /** Flush all queued events to the ingest endpoint */\n flush(): void {\n this.flushQueue(false);\n }\n\n /** Stop the monitor and flush remaining events */\n shutdown(): void {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n this.flushQueue(true);\n this.removeListeners();\n this.active = false;\n }\n\n /**\n * @param unloading the page (or process) is going away: ignore the backoff,\n * since this is the last chance these events get.\n */\n private flushQueue(unloading: boolean): void {\n if (this.queue.length === 0) return;\n\n // Check for global fetch BEFORE removing events from the queue — otherwise\n // on a runtime without fetch (Node <18) the batch would be dropped and lost.\n if (typeof fetch === \"undefined\") return;\n\n // After a transient failure, wait out the backoff instead of hitting a\n // struggling ingest again on every emit.\n if (!unloading && Date.now() < this.backoffUntil) return;\n\n const batch = this.queue.splice(0);\n this.send(batch, { remaining: bisectBudget(batch.length) });\n }\n\n private send(events: MonitorEvent[], budget: { remaining: number }): void {\n const lines: string[] = [];\n const sent: MonitorEvent[] = [];\n for (const e of events) {\n const line = this.serialize(e);\n if (line === null) {\n this.recordDrop(1);\n continue;\n }\n lines.push(line);\n sent.push(e);\n }\n if (lines.length === 0) return;\n\n const body = lines.join(\"\\n\");\n let request: Promise<{ ok?: boolean; status?: number } | undefined>;\n try {\n request = fetch(this.config.ingestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-ndjson\",\n \"X-Api-Key\": this.config.apiKey,\n },\n body,\n keepalive: byteLength(body) <= KEEPALIVE_MAX_BYTES,\n });\n } catch (err) {\n request = Promise.reject(err);\n }\n\n request.then(\n (res) => this.handleResponse(res, sent, budget),\n (err) => {\n if (this.config.debug) {\n console.warn(\"[monitor] flush failed:\", err);\n }\n this.retryLater(sent);\n }\n );\n }\n\n private handleResponse(\n res: { ok?: boolean; status?: number } | undefined,\n events: MonitorEvent[],\n budget: { remaining: number }\n ): void {\n const status = typeof res?.status === \"number\" ? res.status : 0;\n const outcome: Outcome = res?.ok ? \"delivered\" : classify(status);\n\n switch (outcome) {\n case \"delivered\":\n this.counters.flushed += events.length;\n this.failures = 0;\n this.backoffUntil = 0;\n return;\n\n case \"rejected\":\n // Ingest refuses a whole request when one event in it is\n // malformed. Split and resend until the bad one stands alone.\n if (events.length > 1 && budget.remaining > 0) {\n budget.remaining--;\n const mid = events.length >> 1;\n this.send(events.slice(0, mid), budget);\n this.send(events.slice(mid), budget);\n return;\n }\n this.counters.quarantined += events.length;\n this.recordDrop(events.length);\n if (this.config.debug) {\n console.warn(`[monitor] ingest rejected ${events.length} event(s) as malformed (status ${status}):`, events.map((e) => e.name));\n }\n return;\n\n case \"misconfigured\":\n // Nothing will be accepted until the key or URL changes.\n this.recordDrop(events.length);\n if (!this.warnedMisconfigured) {\n this.warnedMisconfigured = true;\n console.warn(`[monitor] ingest refused events with status ${status} — check ingestUrl and apiKey. Events are being dropped.`);\n }\n return;\n\n default:\n this.retryLater(events);\n }\n }\n\n /** Put events back at the front of the queue and back off before retrying. */\n private retryLater(events: MonitorEvent[]): void {\n this.failures++;\n const ceiling = Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** Math.min(this.failures - 1, 16));\n // Full jitter: every open tab sees ingest recover at the same moment.\n this.backoffUntil = Date.now() + 50 + Math.random() * ceiling;\n\n const room = MAX_QUEUE_SIZE - this.queue.length;\n const keep = room <= 0 ? [] : events.length > room ? events.slice(events.length - room) : events;\n this.recordDrop(events.length - keep.length);\n if (keep.length > 0) {\n this.queue = keep.concat(this.queue);\n }\n }\n\n /**\n * One NDJSON line for e, or null if it cannot be serialized. Never throws:\n * flush runs inside emit's auto-flush, and emit must never throw into the\n * caller.\n */\n private serialize(e: MonitorEvent): string | null {\n try {\n const line = JSON.stringify(e);\n // Only strings this long can exceed the limit once UTF-8 encoded.\n if (line.length <= MAX_LINE_BYTES / 3) return line;\n const size = byteLength(line);\n if (size <= MAX_LINE_BYTES) return line;\n\n const kept: Record<string, unknown> = { truncated: true, original_size_bytes: size };\n for (const k of GROUPING_KEYS) {\n const v = e.data[k];\n if (typeof v === \"string\") kept[k] = v.slice(0, MAX_FIELD_CHARS);\n else if (typeof v === \"number\" || typeof v === \"boolean\") kept[k] = v;\n }\n const shrunk = JSON.stringify({ ...e, data: kept });\n return byteLength(shrunk) <= MAX_LINE_BYTES ? shrunk : null;\n } catch {\n return null;\n }\n }\n\n private recordDrop(n: number): void {\n if (n <= 0) return;\n this.counters.dropped += n;\n if (this.onDrop) {\n try {\n this.onDrop(this.counters.dropped);\n } catch {\n // A broken callback must not break delivery.\n }\n }\n }\n\n private start(): void {\n if (this.active) return;\n this.active = true;\n\n const t = setInterval(() => this.flush(), this.config.flushInterval);\n // In Node, unref() lets the process exit even while the flush timer is pending.\n // Browser timers have no unref(), so guard on its presence.\n if (typeof (t as any).unref === \"function\") (t as any).unref();\n this.timer = t;\n\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"pagehide\", this.handlePageHide);\n }\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"hidden\") {\n this.flushQueue(true);\n }\n };\n\n private handlePageHide = (): void => {\n this.flushQueue(true);\n };\n\n private shouldIgnoreError(message: string, stack?: string): boolean {\n if (this.ignoreErrors.length === 0) return false;\n for (const pattern of this.ignoreErrors) {\n if (typeof pattern === \"string\") {\n if (message.includes(pattern) || (stack !== undefined && stack.includes(pattern))) {\n return true;\n }\n } else {\n if (pattern.test(message) || (stack !== undefined && pattern.test(stack))) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * The route a browser error happened on.\n *\n * Deliberately `pathname` only — never the search string or hash. Query\n * parameters routinely carry tokens, emails and other personal data, and this\n * value is both stored on the event and folded into the server-side issue\n * fingerprint, so anything included here is retained and grouped on.\n *\n * Returns undefined outside a browser so the Node handlers stay unaffected.\n */\n private currentPath(): string | undefined {\n if (typeof window === \"undefined\" || !window.location) return undefined;\n return window.location.pathname;\n }\n\n private errorHandler = (event: ErrorEvent): void => {\n const stack = event.error?.stack;\n if (this.shouldIgnoreError(event.message ?? \"\", stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n private rejectionHandler = (event: PromiseRejectionEvent): void => {\n const reason = event.reason;\n const message = reason?.message ?? String(reason);\n const stack = reason?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n // --- Node process handlers ---\n // uncaughtException/unhandledRejection are non-terminating here: we report the\n // error and return without calling process.exit, matching the browser handlers'\n // non-terminating behavior. Consumers keep their own crash semantics.\n\n private nodeExceptionHandler = (err: unknown): void => {\n const e = err as { message?: string; stack?: string } | undefined;\n const message = e?.message ?? String(err);\n const stack = e?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n };\n\n private nodeRejectionHandler = (reason: unknown): void => {\n const r = reason as { message?: string; stack?: string } | undefined;\n const message = r?.message ?? String(reason);\n const stack = r?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n };\n\n private installErrorHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"error\", this.errorHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"uncaughtException\", this.nodeExceptionHandler);\n }\n }\n\n private installRejectionHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"unhandledrejection\", this.rejectionHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n\n private removeListeners(): void {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"error\", this.errorHandler);\n window.removeEventListener(\"unhandledrejection\", this.rejectionHandler);\n window.removeEventListener(\"pagehide\", this.handlePageHide);\n }\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof process !== \"undefined\" && typeof process.removeListener === \"function\") {\n process.removeListener(\"uncaughtException\", this.nodeExceptionHandler);\n process.removeListener(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n}\n","import type { Monitor } from \"./client\";\nimport type { LogLevel } from \"./types\";\n\ninterface AxiosInstance {\n interceptors: {\n request: { use: (onFulfilled: (config: any) => any) => void };\n response: {\n use: (onFulfilled: (response: any) => any, onRejected: (error: any) => any) => void;\n };\n };\n}\n\nexport interface AxiosMonitorOptions {\n /** Only report events for responses with these status codes or above (default: 400) */\n minStatus?: number;\n /** Report successful requests too (default: false) */\n reportSuccess?: boolean;\n /** Paths to ignore (e.g. [\"/healthcheck\", \"/api/health\"]) */\n ignorePaths?: string[];\n}\n\n/**\n * The request URL without its query string or fragment. Query strings are where\n * tokens and email addresses travel in URLs, and anything reported is retained\n * for the life of the event store.\n */\nfunction stripQuery(url: string): string {\n const i = url.search(/[?#]/);\n return i === -1 ? url : url.slice(0, i);\n}\n\n/**\n * Attaches Monitor interceptors to an Axios instance.\n * Automatically reports API failures with request_id correlation.\n *\n * Works with both standard axios error handling AND `validateStatus: () => true`\n * (where all HTTP responses go through the fulfilled handler).\n */\nexport function attachAxiosMonitor(\n axiosInstance: AxiosInstance,\n monitor: Monitor,\n opts?: AxiosMonitorOptions\n): void {\n const minStatus = opts?.minStatus ?? 400;\n const reportSuccess = opts?.reportSuccess ?? false;\n const ignorePaths = opts?.ignorePaths ?? [];\n\n // Stamp request start time\n axiosInstance.interceptors.request.use((config: any) => {\n config.metadata = { startTime: Date.now() };\n return config;\n });\n\n axiosInstance.interceptors.response.use(\n (response: any) => {\n const url: string = stripQuery(response.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) return response;\n\n const statusCode: number = response.status ?? 0;\n const requestId: string = response.headers?.[\"x-request-id\"] ?? \"\";\n const durationMs = response.config?.metadata?.startTime\n ? Date.now() - response.config.metadata.startTime\n : undefined;\n\n // Handle error responses that come through fulfilled handler\n // (when validateStatus: () => true is used)\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: response.data?.error,\n error_message: response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n\n return response;\n }\n\n // Report successful requests if enabled\n if (reportSuccess && statusCode > 0) {\n monitor.info(\"api.request.success\", {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n duration_ms: durationMs,\n },\n });\n }\n\n return response;\n },\n (error: any) => {\n const url: string = stripQuery(error.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) {\n return Promise.reject(error);\n }\n\n const durationMs = error.config?.metadata?.startTime\n ? Date.now() - error.config.metadata.startTime\n : undefined;\n\n // Network errors (no response — timeout, DNS failure, CORS blocked)\n if (!error.response) {\n monitor.error(\"api.request.network_error\", {\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n error_code: error.code,\n error_message: error.message,\n duration_ms: durationMs,\n },\n });\n return Promise.reject(error);\n }\n\n // HTTP errors (when validateStatus is default — throws on non-2xx)\n const statusCode: number = error.response.status ?? 0;\n const requestId: string = error.response.headers?.[\"x-request-id\"] ?? \"\";\n\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: error.response.data?.error,\n error_message: error.response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n }\n\n return Promise.reject(error);\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAM,iBACF;AAMG,SAAS,qBAAqB,IAAqB;AACtD,SAAO,OAAO,MAAM,eAAe,KAAK,EAAE;AAC9C;AAEA,SAAS,YAAY,GAAuB;AACxC,QAAM,MAAM,IAAI,WAAW,CAAC;AAC5B,QAAM,IAAK,WAAgF;AAC3F,MAAI,KAAK,OAAO,EAAE,oBAAoB,YAAY;AAC9C,MAAE,gBAAgB,GAAG;AACrB,WAAO;AAAA,EACX;AAEA,WAAS,IAAI,GAAG,IAAI,GAAG,IAAK,KAAI,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AACnE,SAAO;AACX;AAEA,SAAS,IAAI,OAA2B;AACpC,SAAO,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC5E;AAGO,SAAS,eAAuB;AACnC,SAAO,IAAI,YAAY,CAAC,CAAC;AAC7B;AAGO,SAAS,WAAmB;AAC/B,SAAO,IAAI,YAAY,CAAC,CAAC;AAC7B;AAGO,SAAS,aAAqB;AACjC,QAAM,IAAI,YAAY,EAAE;AACxB,IAAE,CAAC,IAAK,EAAE,CAAC,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eAAO,QAAQ,OAAO,KAAK;AAAA,MAC/B;AAEA,YAAM,aAAa,MAAM,QAAQ,UAAU,YACrC,KAAK,IAAI,IAAI,MAAM,OAAO,SAAS,YACnC;AAGN,UAAI,CAAC,MAAM,UAAU;AACjB,gBAAQ,MAAM,6BAA6B;AAAA,UACvC,MAAM;AAAA,YACF,SAAS,MAAM,QAAQ,UAAU,IAAI,YAAY;AAAA,YACjD;AAAA,YACA,YAAY,MAAM;AAAA,YAClB,eAAe,MAAM;AAAA,YACrB,aAAa;AAAA,UACjB;AAAA,QACJ,CAAC;AACD,eAAO,QAAQ,OAAO,KAAK;AAAA,MAC/B;AAGA,YAAM,aAAqB,MAAM,SAAS,UAAU;AACpD,YAAM,YAAoB,MAAM,SAAS,UAAU,cAAc,KAAK;AAEtE,UAAI,cAAc,WAAW;AACzB,cAAM,QAAkB,cAAc,MAAM,UAAU;AACtD,cAAM,OACF,cAAc,MAAM,6BAA6B;AAErD,gBAAQ,KAAK,MAAM,OAAO;AAAA,UACtB;AAAA,UACA,MAAM;AAAA,YACF,SAAS,MAAM,QAAQ,UAAU,IAAI,YAAY;AAAA,YACjD;AAAA,YACA,aAAa;AAAA,YACb,OAAO,MAAM,SAAS,MAAM;AAAA,YAC5B,eAAe,MAAM,SAAS,MAAM;AAAA,YACpC,aAAa;AAAA,UACjB;AAAA,QACJ,CAAC;AAAA,MACL;AAEA,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC/B;AAAA,EACJ;AACJ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ids.ts","../src/client.ts","../src/axios.ts"],"sourcesContent":["export { Monitor } from \"./client\";\nexport { attachAxiosMonitor } from \"./axios\";\nexport { isValidCorrelationId, newRequestId, newTraceId, newJobId } from \"./ids\";\nexport type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nexport type { AxiosMonitorOptions } from \"./axios\";\n","/**\n * monitor-core's correlation-id rule (structs.correlationIDRegex), verbatim.\n *\n * Ingest validates job_id, request_id and trace_id against it and rejects the\n * WHOLE request when any line fails — so one malformed id, passed through\n * unchecked, loses every event batched with it.\n */\nconst CORRELATION_ID =\n /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|[0-9a-fA-F]{8,64})$/;\n\n/**\n * Whether monitor-core would accept `id` as a job_id, request_id or trace_id.\n * The empty string is valid: the server skips empty ids.\n */\nexport function isValidCorrelationId(id: string): boolean {\n return id === \"\" || CORRELATION_ID.test(id);\n}\n\nfunction randomBytes(n: number): Uint8Array {\n const out = new Uint8Array(n);\n const c = (globalThis as { crypto?: { getRandomValues?: (a: Uint8Array) => Uint8Array } }).crypto;\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(out);\n return out;\n }\n // Node 18 has no global crypto. Correlation ids need uniqueness, not secrecy.\n for (let i = 0; i < n; i++) out[i] = Math.floor(Math.random() * 256);\n return out;\n}\n\nfunction hex(bytes: Uint8Array): string {\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** A request_id monitor-core accepts: 16 hex characters. */\nexport function newRequestId(): string {\n return hex(randomBytes(8));\n}\n\n/** A job_id monitor-core accepts: 16 hex characters. */\nexport function newJobId(): string {\n return hex(randomBytes(8));\n}\n\n/** A trace_id monitor-core accepts: a hyphenated UUID v4. */\nexport function newTraceId(): string {\n const b = randomBytes(16);\n b[6] = (b[6] & 0x0f) | 0x40; // version 4\n b[8] = (b[8] & 0x3f) | 0x80; // RFC 4122 variant\n const h = hex(b);\n return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;\n}\n","import type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nimport { isValidCorrelationId, newJobId } from \"./ids\";\n\n// Minimal ambient shape for the Node `process` global — this package has no\n// @types/node dependency and targets the browser too, so `process` may be absent.\n// Guarded with `typeof process !== \"undefined\"` before use.\ndeclare const process:\n | {\n on?(event: string, listener: (...args: unknown[]) => void): void;\n removeListener?(event: string, listener: (...args: unknown[]) => void): void;\n listenerCount?(event: string): number;\n nextTick?(callback: () => void): void;\n exit?(code?: number): void;\n }\n | undefined;\n\nconst DEFAULT_FLUSH_INTERVAL = 2000;\nconst DEFAULT_BATCH_SIZE = 20;\nconst MAX_QUEUE_SIZE = 500;\n\n/**\n * monitor-core scans NDJSON with a 1 MiB line buffer and rejects the WHOLE\n * request when one line overflows it, so an oversized event is shrunk before it\n * is sent rather than discovered by a 400.\n */\nconst MAX_LINE_BYTES = 1_000_000;\n/** Characters kept per grouping field when an oversized event is shrunk. */\nconst MAX_FIELD_CHARS = 4096;\n/**\n * Browsers refuse a keepalive request once the page's in-flight keepalive\n * bodies exceed 64 KiB, and the refusal is a plain TypeError. Asking for\n * keepalive on a bigger body would fail — and be retried — forever.\n */\nconst KEEPALIVE_MAX_BYTES = 60_000;\n/** Backoff bounds after a transient ingest failure. */\nconst BASE_BACKOFF_MS = 1000;\nconst MAX_BACKOFF_MS = 60_000;\n\n/** The data keys monitor-core's issue fingerprint reads; they survive shrinking. */\nconst GROUPING_KEYS = [\"error\", \"error_message\", \"message\", \"path\", \"uri\", \"method\", \"reason\", \"status_code\"];\n\ntype Outcome = \"delivered\" | \"rejected\" | \"misconfigured\" | \"retryable\";\n\n/** How an ingest response should be handled. Mirrors go-monitor's classifyStatus. */\nfunction classify(status: number): Outcome {\n if (status >= 200 && status < 400) return \"delivered\";\n if (status === 408 || status === 429) return \"retryable\";\n if (status === 401 || status === 403 || status === 404 || status === 405) return \"misconfigured\";\n if (status >= 400 && status < 500) return \"rejected\";\n return \"retryable\";\n}\n\n/** Extra requests allowed to isolate malformed events in a batch of n. */\nfunction bisectBudget(n: number): number {\n let depth = 0;\n for (let x = n; x > 1; x = Math.ceil(x / 2)) depth++;\n return 4 * depth + 4;\n}\n\nlet encoder: TextEncoder | undefined;\nfunction byteLength(s: string): number {\n if (typeof TextEncoder === \"undefined\") return s.length * 3;\n encoder ??= new TextEncoder();\n return encoder.encode(s).length;\n}\n\n/**\n * monitor-core stores level verbatim and groups only exact \"error\"/\"fatal\" into\n * issues, so \"ERROR\" or \"warning\" would land and silently never be tracked.\n */\nfunction normalizeLevel(level: string): string {\n const l = (level || \"info\").toLowerCase();\n return l === \"warning\" ? \"warn\" : l;\n}\n\nexport class Monitor {\n private config: Required<\n Pick<MonitorConfig, \"service\" | \"ingestUrl\" | \"apiKey\" | \"env\" | \"flushInterval\" | \"batchSize\" | \"debug\">\n >;\n private ignoreErrors: (string | RegExp)[] = [];\n private onDrop?: (total: number) => void;\n private queue: MonitorEvent[] = [];\n private timer: ReturnType<typeof setInterval> | null = null;\n private userId: string = \"\";\n private jobId: string;\n private active = false;\n private backoffUntil = 0;\n private failures = 0;\n private warnedMisconfigured = false;\n private counters = { enqueued: 0, flushed: 0, dropped: 0, quarantined: 0 };\n\n constructor(config: MonitorConfig) {\n this.config = {\n service: config.service,\n ingestUrl: config.ingestUrl,\n apiKey: config.apiKey,\n env: config.env ?? \"production\",\n flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n debug: config.debug ?? false,\n };\n this.ignoreErrors = config.ignoreErrors ?? [];\n this.onDrop = config.onDrop;\n // One id per page load (or process): every event from this session\n // shares it, so a session's events can be pulled up together.\n this.jobId = newJobId();\n\n this.start();\n\n if (config.captureErrors !== false) {\n this.installErrorHandler();\n }\n if (config.captureUnhandledRejections !== false) {\n this.installRejectionHandler();\n }\n }\n\n /** Set a persistent user ID for all subsequent events */\n setUser(userId: string): void {\n this.userId = userId;\n }\n\n /** Clear the user ID */\n clearUser(): void {\n this.userId = \"\";\n }\n\n /**\n * Set a persistent job ID (session-level identifier). It must be a UUID or\n * 8-64 hex characters — see `isValidCorrelationId`; anything else is\n * cleared from each event and kept in data.invalid_job_id.\n */\n setJobId(jobId: string): void {\n this.jobId = jobId;\n }\n\n /** Emit an event at a specific level */\n emit(name: string, level: LogLevel, opts?: EmitOptions): void {\n if (!this.active) return;\n\n // An id monitor-core would reject is cleared, not sent: one bad id\n // fails the whole request. The original is kept where it is useful.\n let data: Record<string, unknown> = opts?.data ?? {};\n const repair = (field: string, value: string): string => {\n if (isValidCorrelationId(value)) return value;\n data = { ...data, [`invalid_${field}`]: value.slice(0, 128) };\n if (this.config.debug) {\n console.warn(`[monitor] cleared invalid ${field} ${JSON.stringify(value)} (monitor-core accepts a UUID or 8-64 hex characters)`);\n }\n return \"\";\n };\n const jobId = repair(\"job_id\", this.jobId);\n const requestId = repair(\"request_id\", opts?.requestId ?? \"\");\n const traceId = repair(\"trace_id\", opts?.traceId ?? \"\");\n\n const event: MonitorEvent = {\n timestamp: new Date().toISOString(),\n service: this.config.service,\n env: this.config.env,\n job_id: jobId,\n request_id: requestId,\n trace_id: traceId,\n user_id: opts?.userId ?? this.userId,\n name: name || \"event.unnamed\",\n level: normalizeLevel(level),\n data,\n };\n\n if (this.queue.length >= MAX_QUEUE_SIZE) {\n // Drop oldest events to prevent unbounded memory growth\n this.queue.shift();\n this.recordDrop(1);\n }\n\n this.queue.push(event);\n this.counters.enqueued++;\n\n if (this.config.debug) {\n console.debug(`[monitor] ${level} ${name}`, opts?.data);\n }\n\n if (this.queue.length >= this.config.batchSize) {\n this.flush();\n }\n }\n\n /** Emit a debug event */\n debug(name: string, opts?: EmitOptions): void {\n this.emit(name, \"debug\", opts);\n }\n\n /** Emit an info event */\n info(name: string, opts?: EmitOptions): void {\n this.emit(name, \"info\", opts);\n }\n\n /** Emit a warning event */\n warn(name: string, opts?: EmitOptions): void {\n this.emit(name, \"warn\", opts);\n }\n\n /** Emit an error event */\n error(name: string, opts?: EmitOptions): void {\n this.emit(name, \"error\", opts);\n }\n\n /** Emit a fatal event */\n fatal(name: string, opts?: EmitOptions): void {\n this.emit(name, \"fatal\", opts);\n }\n\n /**\n * Lifetime counters. Surface them wherever loss would otherwise go\n * unnoticed: the system that would report dropped telemetry is the one\n * dropping it.\n */\n stats(): MonitorStats {\n return { ...this.counters, queued: this.queue.length };\n }\n\n /** Flush all queued events to the ingest endpoint */\n flush(): void {\n this.flushQueue(false);\n }\n\n /** Stop the monitor and flush remaining events */\n shutdown(): void {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n this.flushQueue(true);\n this.removeListeners();\n this.active = false;\n }\n\n /**\n * @param unloading the page (or process) is going away: ignore the backoff,\n * since this is the last chance these events get.\n */\n private flushQueue(unloading: boolean): void {\n if (this.queue.length === 0) return;\n\n // Check for global fetch BEFORE removing events from the queue — otherwise\n // on a runtime without fetch (Node <18) the batch would be dropped and lost.\n if (typeof fetch === \"undefined\") return;\n\n // After a transient failure, wait out the backoff instead of hitting a\n // struggling ingest again on every emit.\n if (!unloading && Date.now() < this.backoffUntil) return;\n\n const batch = this.queue.splice(0);\n this.send(batch, { remaining: bisectBudget(batch.length) });\n }\n\n private send(events: MonitorEvent[], budget: { remaining: number }): void {\n const lines: string[] = [];\n const sent: MonitorEvent[] = [];\n for (const e of events) {\n const line = this.serialize(e);\n if (line === null) {\n this.recordDrop(1);\n continue;\n }\n lines.push(line);\n sent.push(e);\n }\n if (lines.length === 0) return;\n\n const body = lines.join(\"\\n\");\n let request: Promise<{ ok?: boolean; status?: number } | undefined>;\n try {\n request = fetch(this.config.ingestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-ndjson\",\n \"X-Api-Key\": this.config.apiKey,\n },\n body,\n keepalive: byteLength(body) <= KEEPALIVE_MAX_BYTES,\n });\n } catch (err) {\n request = Promise.reject(err);\n }\n\n request.then(\n (res) => this.handleResponse(res, sent, budget),\n (err) => {\n if (this.config.debug) {\n console.warn(\"[monitor] flush failed:\", err);\n }\n this.retryLater(sent);\n }\n );\n }\n\n private handleResponse(\n res: { ok?: boolean; status?: number } | undefined,\n events: MonitorEvent[],\n budget: { remaining: number }\n ): void {\n const status = typeof res?.status === \"number\" ? res.status : 0;\n const outcome: Outcome = res?.ok ? \"delivered\" : classify(status);\n\n switch (outcome) {\n case \"delivered\":\n this.counters.flushed += events.length;\n this.failures = 0;\n this.backoffUntil = 0;\n return;\n\n case \"rejected\":\n // Ingest refuses a whole request when one event in it is\n // malformed. Split and resend until the bad one stands alone.\n if (events.length > 1 && budget.remaining > 0) {\n budget.remaining--;\n const mid = events.length >> 1;\n this.send(events.slice(0, mid), budget);\n this.send(events.slice(mid), budget);\n return;\n }\n this.counters.quarantined += events.length;\n this.recordDrop(events.length);\n if (this.config.debug) {\n console.warn(`[monitor] ingest rejected ${events.length} event(s) as malformed (status ${status}):`, events.map((e) => e.name));\n }\n return;\n\n case \"misconfigured\":\n // Nothing will be accepted until the key or URL changes.\n this.recordDrop(events.length);\n if (!this.warnedMisconfigured) {\n this.warnedMisconfigured = true;\n console.warn(`[monitor] ingest refused events with status ${status} — check ingestUrl and apiKey. Events are being dropped.`);\n }\n return;\n\n default:\n this.retryLater(events);\n }\n }\n\n /** Put events back at the front of the queue and back off before retrying. */\n private retryLater(events: MonitorEvent[]): void {\n this.failures++;\n const ceiling = Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** Math.min(this.failures - 1, 16));\n // Full jitter: every open tab sees ingest recover at the same moment.\n this.backoffUntil = Date.now() + 50 + Math.random() * ceiling;\n\n const room = MAX_QUEUE_SIZE - this.queue.length;\n const keep = room <= 0 ? [] : events.length > room ? events.slice(events.length - room) : events;\n this.recordDrop(events.length - keep.length);\n if (keep.length > 0) {\n this.queue = keep.concat(this.queue);\n }\n }\n\n /**\n * One NDJSON line for e, or null if it cannot be serialized. Never throws:\n * flush runs inside emit's auto-flush, and emit must never throw into the\n * caller.\n */\n private serialize(e: MonitorEvent): string | null {\n try {\n const line = JSON.stringify(e);\n // Only strings this long can exceed the limit once UTF-8 encoded.\n if (line.length <= MAX_LINE_BYTES / 3) return line;\n const size = byteLength(line);\n if (size <= MAX_LINE_BYTES) return line;\n\n const kept: Record<string, unknown> = { truncated: true, original_size_bytes: size };\n for (const k of GROUPING_KEYS) {\n const v = e.data[k];\n if (typeof v === \"string\") kept[k] = v.slice(0, MAX_FIELD_CHARS);\n else if (typeof v === \"number\" || typeof v === \"boolean\") kept[k] = v;\n }\n const shrunk = JSON.stringify({ ...e, data: kept });\n return byteLength(shrunk) <= MAX_LINE_BYTES ? shrunk : null;\n } catch {\n return null;\n }\n }\n\n private recordDrop(n: number): void {\n if (n <= 0) return;\n this.counters.dropped += n;\n if (this.onDrop) {\n try {\n this.onDrop(this.counters.dropped);\n } catch {\n // A broken callback must not break delivery.\n }\n }\n }\n\n private start(): void {\n if (this.active) return;\n this.active = true;\n\n const t = setInterval(() => this.flush(), this.config.flushInterval);\n // In Node, unref() lets the process exit even while the flush timer is pending.\n // Browser timers have no unref(), so guard on its presence.\n if (typeof (t as any).unref === \"function\") (t as any).unref();\n this.timer = t;\n\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"pagehide\", this.handlePageHide);\n }\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"hidden\") {\n this.flushQueue(true);\n }\n };\n\n private handlePageHide = (): void => {\n this.flushQueue(true);\n };\n\n private shouldIgnoreError(message: string, stack?: string): boolean {\n if (this.ignoreErrors.length === 0) return false;\n for (const pattern of this.ignoreErrors) {\n if (typeof pattern === \"string\") {\n if (message.includes(pattern) || (stack !== undefined && stack.includes(pattern))) {\n return true;\n }\n } else {\n if (pattern.test(message) || (stack !== undefined && pattern.test(stack))) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * The route a browser error happened on.\n *\n * Deliberately `pathname` only — never the search string or hash. Query\n * parameters routinely carry tokens, emails and other personal data, and this\n * value is both stored on the event and folded into the server-side issue\n * fingerprint, so anything included here is retained and grouped on.\n *\n * Returns undefined outside a browser so the Node handlers stay unaffected.\n */\n private currentPath(): string | undefined {\n if (typeof window === \"undefined\" || !window.location) return undefined;\n return window.location.pathname;\n }\n\n private errorHandler = (event: ErrorEvent): void => {\n const stack = event.error?.stack;\n if (this.shouldIgnoreError(event.message ?? \"\", stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n private rejectionHandler = (event: PromiseRejectionEvent): void => {\n const reason = event.reason;\n const message = reason?.message ?? String(reason);\n const stack = reason?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n // --- Node process handlers ---\n // Adding an uncaughtException or unhandledRejection listener changes what Node\n // does. With no listener, either one prints the error and exits with code 1;\n // with any listener, Node assumes it was handled and keeps running — in\n // whatever state the failure left it. So when this SDK is the only listener,\n // it reports the error and then does what Node would have done. When the app\n // has a listener of its own, the app has already decided; the SDK only reports.\n\n /** Grace for the final batch to leave before a Node-style crash exits. */\n private static readonly NODE_CRASH_GRACE_MS = 1500;\n\n /** Rejections already reported, so the re-raise below is not reported twice. */\n private reportedRejections = new WeakSet<object>();\n\n private nodeExceptionHandler = (err: unknown): void => {\n const alreadyReported =\n typeof err === \"object\" && err !== null && this.reportedRejections.has(err);\n const e = err as { message?: string; stack?: string } | undefined;\n const message = e?.message ?? String(err);\n const stack = e?.stack;\n if (!alreadyReported && !this.shouldIgnoreError(message, stack)) {\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n }\n if (this.isSoleListener(\"uncaughtException\")) {\n this.crashLikeNode(err);\n }\n };\n\n private nodeRejectionHandler = (reason: unknown): void => {\n const r = reason as { message?: string; stack?: string } | undefined;\n const message = r?.message ?? String(reason);\n const stack = r?.stack;\n if (!this.shouldIgnoreError(message, stack)) {\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n }\n // Node's default is to raise an unhandled rejection as an uncaught\n // exception. This listener suppressed that, so re-raise it when nothing\n // else listens for rejections: the app's own uncaughtException handling,\n // or Node's crash, then applies exactly as it would without the SDK.\n if (this.isSoleListener(\"unhandledRejection\")) {\n if (typeof reason === \"object\" && reason !== null) {\n this.reportedRejections.add(reason);\n }\n this.reraise(reason);\n }\n };\n\n /** Hand an unhandled rejection back to Node as an uncaught exception. */\n private reraise(reason: unknown): void {\n process?.nextTick?.(() => {\n throw reason;\n });\n }\n\n /** True when this instance's own handler is the only listener for the event. */\n private isSoleListener(event: \"uncaughtException\" | \"unhandledRejection\"): boolean {\n const count = typeof process === \"undefined\" ? undefined : process.listenerCount;\n if (typeof count !== \"function\") {\n return false;\n }\n return count.call(process, event) <= 1;\n }\n\n /** Print the error as Node would, give the batch a moment to leave, exit 1. */\n private crashLikeNode(err: unknown): void {\n console.error(err);\n this.flush();\n setTimeout(() => process?.exit?.(1), Monitor.NODE_CRASH_GRACE_MS);\n }\n\n private installErrorHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"error\", this.errorHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"uncaughtException\", this.nodeExceptionHandler);\n }\n }\n\n private installRejectionHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"unhandledrejection\", this.rejectionHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n\n private removeListeners(): void {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"error\", this.errorHandler);\n window.removeEventListener(\"unhandledrejection\", this.rejectionHandler);\n window.removeEventListener(\"pagehide\", this.handlePageHide);\n }\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof process !== \"undefined\" && typeof process.removeListener === \"function\") {\n process.removeListener(\"uncaughtException\", this.nodeExceptionHandler);\n process.removeListener(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n}\n","import type { Monitor } from \"./client\";\nimport type { LogLevel } from \"./types\";\n\ninterface AxiosInstance {\n interceptors: {\n request: { use: (onFulfilled: (config: any) => any) => void };\n response: {\n use: (onFulfilled: (response: any) => any, onRejected: (error: any) => any) => void;\n };\n };\n}\n\nexport interface AxiosMonitorOptions {\n /** Only report events for responses with these status codes or above (default: 400) */\n minStatus?: number;\n /** Report successful requests too (default: false) */\n reportSuccess?: boolean;\n /** Paths to ignore (e.g. [\"/healthcheck\", \"/api/health\"]) */\n ignorePaths?: string[];\n}\n\n/**\n * The request URL without its query string or fragment. Query strings are where\n * tokens and email addresses travel in URLs, and anything reported is retained\n * for the life of the event store.\n */\nfunction stripQuery(url: string): string {\n const i = url.search(/[?#]/);\n return i === -1 ? url : url.slice(0, i);\n}\n\n/**\n * Attaches Monitor interceptors to an Axios instance.\n * Automatically reports API failures with request_id correlation.\n *\n * Works with both standard axios error handling AND `validateStatus: () => true`\n * (where all HTTP responses go through the fulfilled handler).\n */\nexport function attachAxiosMonitor(\n axiosInstance: AxiosInstance,\n monitor: Monitor,\n opts?: AxiosMonitorOptions\n): void {\n const minStatus = opts?.minStatus ?? 400;\n const reportSuccess = opts?.reportSuccess ?? false;\n const ignorePaths = opts?.ignorePaths ?? [];\n\n // Stamp request start time\n axiosInstance.interceptors.request.use((config: any) => {\n config.metadata = { startTime: Date.now() };\n return config;\n });\n\n axiosInstance.interceptors.response.use(\n (response: any) => {\n const url: string = stripQuery(response.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) return response;\n\n const statusCode: number = response.status ?? 0;\n const requestId: string = response.headers?.[\"x-request-id\"] ?? \"\";\n const durationMs = response.config?.metadata?.startTime\n ? Date.now() - response.config.metadata.startTime\n : undefined;\n\n // Handle error responses that come through fulfilled handler\n // (when validateStatus: () => true is used)\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: response.data?.error,\n error_message: response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n\n return response;\n }\n\n // Report successful requests if enabled\n if (reportSuccess && statusCode > 0) {\n monitor.info(\"api.request.success\", {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n duration_ms: durationMs,\n },\n });\n }\n\n return response;\n },\n (error: any) => {\n const url: string = stripQuery(error.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) {\n return Promise.reject(error);\n }\n\n const durationMs = error.config?.metadata?.startTime\n ? Date.now() - error.config.metadata.startTime\n : undefined;\n\n // Network errors (no response — timeout, DNS failure, CORS blocked)\n if (!error.response) {\n monitor.error(\"api.request.network_error\", {\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n error_code: error.code,\n error_message: error.message,\n duration_ms: durationMs,\n },\n });\n return Promise.reject(error);\n }\n\n // HTTP errors (when validateStatus is default — throws on non-2xx)\n const statusCode: number = error.response.status ?? 0;\n const requestId: string = error.response.headers?.[\"x-request-id\"] ?? \"\";\n\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: error.response.data?.error,\n error_message: error.response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n }\n\n return Promise.reject(error);\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAM,iBACF;AAMG,SAAS,qBAAqB,IAAqB;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aAAO,QAAQ,OAAO,KAAK;AAAA,IAC/B;AAAA,EACJ;AACJ;","names":[]}
package/dist/index.mjs CHANGED
@@ -62,7 +62,7 @@ function normalizeLevel(level) {
62
62
  const l = (level || "info").toLowerCase();
63
63
  return l === "warning" ? "warn" : l;
64
64
  }
65
- var Monitor = class {
65
+ var Monitor = class _Monitor {
66
66
  config;
67
67
  ignoreErrors = [];
68
68
  onDrop;
@@ -400,33 +400,72 @@ var Monitor = class {
400
400
  });
401
401
  };
402
402
  // --- Node process handlers ---
403
- // uncaughtException/unhandledRejection are non-terminating here: we report the
404
- // error and return without calling process.exit, matching the browser handlers'
405
- // non-terminating behavior. Consumers keep their own crash semantics.
403
+ // Adding an uncaughtException or unhandledRejection listener changes what Node
404
+ // does. With no listener, either one prints the error and exits with code 1;
405
+ // with any listener, Node assumes it was handled and keeps running — in
406
+ // whatever state the failure left it. So when this SDK is the only listener,
407
+ // it reports the error and then does what Node would have done. When the app
408
+ // has a listener of its own, the app has already decided; the SDK only reports.
409
+ /** Grace for the final batch to leave before a Node-style crash exits. */
410
+ static NODE_CRASH_GRACE_MS = 1500;
411
+ /** Rejections already reported, so the re-raise below is not reported twice. */
412
+ reportedRejections = /* @__PURE__ */ new WeakSet();
406
413
  nodeExceptionHandler = (err) => {
414
+ const alreadyReported = typeof err === "object" && err !== null && this.reportedRejections.has(err);
407
415
  const e = err;
408
416
  const message = e?.message ?? String(err);
409
417
  const stack = e?.stack;
410
- if (this.shouldIgnoreError(message, stack)) return;
411
- this.emit("client.error.uncaught", "error", {
412
- data: {
413
- message,
414
- stack
415
- }
416
- });
418
+ if (!alreadyReported && !this.shouldIgnoreError(message, stack)) {
419
+ this.emit("client.error.uncaught", "error", {
420
+ data: {
421
+ message,
422
+ stack
423
+ }
424
+ });
425
+ }
426
+ if (this.isSoleListener("uncaughtException")) {
427
+ this.crashLikeNode(err);
428
+ }
417
429
  };
418
430
  nodeRejectionHandler = (reason) => {
419
431
  const r = reason;
420
432
  const message = r?.message ?? String(reason);
421
433
  const stack = r?.stack;
422
- if (this.shouldIgnoreError(message, stack)) return;
423
- this.emit("client.error.unhandled_rejection", "error", {
424
- data: {
425
- message,
426
- stack
434
+ if (!this.shouldIgnoreError(message, stack)) {
435
+ this.emit("client.error.unhandled_rejection", "error", {
436
+ data: {
437
+ message,
438
+ stack
439
+ }
440
+ });
441
+ }
442
+ if (this.isSoleListener("unhandledRejection")) {
443
+ if (typeof reason === "object" && reason !== null) {
444
+ this.reportedRejections.add(reason);
427
445
  }
428
- });
446
+ this.reraise(reason);
447
+ }
429
448
  };
449
+ /** Hand an unhandled rejection back to Node as an uncaught exception. */
450
+ reraise(reason) {
451
+ process?.nextTick?.(() => {
452
+ throw reason;
453
+ });
454
+ }
455
+ /** True when this instance's own handler is the only listener for the event. */
456
+ isSoleListener(event) {
457
+ const count = typeof process === "undefined" ? void 0 : process.listenerCount;
458
+ if (typeof count !== "function") {
459
+ return false;
460
+ }
461
+ return count.call(process, event) <= 1;
462
+ }
463
+ /** Print the error as Node would, give the batch a moment to leave, exit 1. */
464
+ crashLikeNode(err) {
465
+ console.error(err);
466
+ this.flush();
467
+ setTimeout(() => process?.exit?.(1), _Monitor.NODE_CRASH_GRACE_MS);
468
+ }
430
469
  installErrorHandler() {
431
470
  if (typeof window !== "undefined") {
432
471
  window.addEventListener("error", this.errorHandler);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ids.ts","../src/client.ts","../src/axios.ts"],"sourcesContent":["/**\n * monitor-core's correlation-id rule (structs.correlationIDRegex), verbatim.\n *\n * Ingest validates job_id, request_id and trace_id against it and rejects the\n * WHOLE request when any line fails — so one malformed id, passed through\n * unchecked, loses every event batched with it.\n */\nconst CORRELATION_ID =\n /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|[0-9a-fA-F]{8,64})$/;\n\n/**\n * Whether monitor-core would accept `id` as a job_id, request_id or trace_id.\n * The empty string is valid: the server skips empty ids.\n */\nexport function isValidCorrelationId(id: string): boolean {\n return id === \"\" || CORRELATION_ID.test(id);\n}\n\nfunction randomBytes(n: number): Uint8Array {\n const out = new Uint8Array(n);\n const c = (globalThis as { crypto?: { getRandomValues?: (a: Uint8Array) => Uint8Array } }).crypto;\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(out);\n return out;\n }\n // Node 18 has no global crypto. Correlation ids need uniqueness, not secrecy.\n for (let i = 0; i < n; i++) out[i] = Math.floor(Math.random() * 256);\n return out;\n}\n\nfunction hex(bytes: Uint8Array): string {\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** A request_id monitor-core accepts: 16 hex characters. */\nexport function newRequestId(): string {\n return hex(randomBytes(8));\n}\n\n/** A job_id monitor-core accepts: 16 hex characters. */\nexport function newJobId(): string {\n return hex(randomBytes(8));\n}\n\n/** A trace_id monitor-core accepts: a hyphenated UUID v4. */\nexport function newTraceId(): string {\n const b = randomBytes(16);\n b[6] = (b[6] & 0x0f) | 0x40; // version 4\n b[8] = (b[8] & 0x3f) | 0x80; // RFC 4122 variant\n const h = hex(b);\n return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;\n}\n","import type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nimport { isValidCorrelationId, newJobId } from \"./ids\";\n\n// Minimal ambient shape for the Node `process` global — this package has no\n// @types/node dependency and targets the browser too, so `process` may be absent.\n// Guarded with `typeof process !== \"undefined\"` before use.\ndeclare const process:\n | {\n on?(event: string, listener: (...args: unknown[]) => void): void;\n removeListener?(event: string, listener: (...args: unknown[]) => void): void;\n }\n | undefined;\n\nconst DEFAULT_FLUSH_INTERVAL = 2000;\nconst DEFAULT_BATCH_SIZE = 20;\nconst MAX_QUEUE_SIZE = 500;\n\n/**\n * monitor-core scans NDJSON with a 1 MiB line buffer and rejects the WHOLE\n * request when one line overflows it, so an oversized event is shrunk before it\n * is sent rather than discovered by a 400.\n */\nconst MAX_LINE_BYTES = 1_000_000;\n/** Characters kept per grouping field when an oversized event is shrunk. */\nconst MAX_FIELD_CHARS = 4096;\n/**\n * Browsers refuse a keepalive request once the page's in-flight keepalive\n * bodies exceed 64 KiB, and the refusal is a plain TypeError. Asking for\n * keepalive on a bigger body would fail — and be retried — forever.\n */\nconst KEEPALIVE_MAX_BYTES = 60_000;\n/** Backoff bounds after a transient ingest failure. */\nconst BASE_BACKOFF_MS = 1000;\nconst MAX_BACKOFF_MS = 60_000;\n\n/** The data keys monitor-core's issue fingerprint reads; they survive shrinking. */\nconst GROUPING_KEYS = [\"error\", \"error_message\", \"message\", \"path\", \"uri\", \"method\", \"reason\", \"status_code\"];\n\ntype Outcome = \"delivered\" | \"rejected\" | \"misconfigured\" | \"retryable\";\n\n/** How an ingest response should be handled. Mirrors go-monitor's classifyStatus. */\nfunction classify(status: number): Outcome {\n if (status >= 200 && status < 400) return \"delivered\";\n if (status === 408 || status === 429) return \"retryable\";\n if (status === 401 || status === 403 || status === 404 || status === 405) return \"misconfigured\";\n if (status >= 400 && status < 500) return \"rejected\";\n return \"retryable\";\n}\n\n/** Extra requests allowed to isolate malformed events in a batch of n. */\nfunction bisectBudget(n: number): number {\n let depth = 0;\n for (let x = n; x > 1; x = Math.ceil(x / 2)) depth++;\n return 4 * depth + 4;\n}\n\nlet encoder: TextEncoder | undefined;\nfunction byteLength(s: string): number {\n if (typeof TextEncoder === \"undefined\") return s.length * 3;\n encoder ??= new TextEncoder();\n return encoder.encode(s).length;\n}\n\n/**\n * monitor-core stores level verbatim and groups only exact \"error\"/\"fatal\" into\n * issues, so \"ERROR\" or \"warning\" would land and silently never be tracked.\n */\nfunction normalizeLevel(level: string): string {\n const l = (level || \"info\").toLowerCase();\n return l === \"warning\" ? \"warn\" : l;\n}\n\nexport class Monitor {\n private config: Required<\n Pick<MonitorConfig, \"service\" | \"ingestUrl\" | \"apiKey\" | \"env\" | \"flushInterval\" | \"batchSize\" | \"debug\">\n >;\n private ignoreErrors: (string | RegExp)[] = [];\n private onDrop?: (total: number) => void;\n private queue: MonitorEvent[] = [];\n private timer: ReturnType<typeof setInterval> | null = null;\n private userId: string = \"\";\n private jobId: string;\n private active = false;\n private backoffUntil = 0;\n private failures = 0;\n private warnedMisconfigured = false;\n private counters = { enqueued: 0, flushed: 0, dropped: 0, quarantined: 0 };\n\n constructor(config: MonitorConfig) {\n this.config = {\n service: config.service,\n ingestUrl: config.ingestUrl,\n apiKey: config.apiKey,\n env: config.env ?? \"production\",\n flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n debug: config.debug ?? false,\n };\n this.ignoreErrors = config.ignoreErrors ?? [];\n this.onDrop = config.onDrop;\n // One id per page load (or process): every event from this session\n // shares it, so a session's events can be pulled up together.\n this.jobId = newJobId();\n\n this.start();\n\n if (config.captureErrors !== false) {\n this.installErrorHandler();\n }\n if (config.captureUnhandledRejections !== false) {\n this.installRejectionHandler();\n }\n }\n\n /** Set a persistent user ID for all subsequent events */\n setUser(userId: string): void {\n this.userId = userId;\n }\n\n /** Clear the user ID */\n clearUser(): void {\n this.userId = \"\";\n }\n\n /**\n * Set a persistent job ID (session-level identifier). It must be a UUID or\n * 8-64 hex characters — see `isValidCorrelationId`; anything else is\n * cleared from each event and kept in data.invalid_job_id.\n */\n setJobId(jobId: string): void {\n this.jobId = jobId;\n }\n\n /** Emit an event at a specific level */\n emit(name: string, level: LogLevel, opts?: EmitOptions): void {\n if (!this.active) return;\n\n // An id monitor-core would reject is cleared, not sent: one bad id\n // fails the whole request. The original is kept where it is useful.\n let data: Record<string, unknown> = opts?.data ?? {};\n const repair = (field: string, value: string): string => {\n if (isValidCorrelationId(value)) return value;\n data = { ...data, [`invalid_${field}`]: value.slice(0, 128) };\n if (this.config.debug) {\n console.warn(`[monitor] cleared invalid ${field} ${JSON.stringify(value)} (monitor-core accepts a UUID or 8-64 hex characters)`);\n }\n return \"\";\n };\n const jobId = repair(\"job_id\", this.jobId);\n const requestId = repair(\"request_id\", opts?.requestId ?? \"\");\n const traceId = repair(\"trace_id\", opts?.traceId ?? \"\");\n\n const event: MonitorEvent = {\n timestamp: new Date().toISOString(),\n service: this.config.service,\n env: this.config.env,\n job_id: jobId,\n request_id: requestId,\n trace_id: traceId,\n user_id: opts?.userId ?? this.userId,\n name: name || \"event.unnamed\",\n level: normalizeLevel(level),\n data,\n };\n\n if (this.queue.length >= MAX_QUEUE_SIZE) {\n // Drop oldest events to prevent unbounded memory growth\n this.queue.shift();\n this.recordDrop(1);\n }\n\n this.queue.push(event);\n this.counters.enqueued++;\n\n if (this.config.debug) {\n console.debug(`[monitor] ${level} ${name}`, opts?.data);\n }\n\n if (this.queue.length >= this.config.batchSize) {\n this.flush();\n }\n }\n\n /** Emit a debug event */\n debug(name: string, opts?: EmitOptions): void {\n this.emit(name, \"debug\", opts);\n }\n\n /** Emit an info event */\n info(name: string, opts?: EmitOptions): void {\n this.emit(name, \"info\", opts);\n }\n\n /** Emit a warning event */\n warn(name: string, opts?: EmitOptions): void {\n this.emit(name, \"warn\", opts);\n }\n\n /** Emit an error event */\n error(name: string, opts?: EmitOptions): void {\n this.emit(name, \"error\", opts);\n }\n\n /** Emit a fatal event */\n fatal(name: string, opts?: EmitOptions): void {\n this.emit(name, \"fatal\", opts);\n }\n\n /**\n * Lifetime counters. Surface them wherever loss would otherwise go\n * unnoticed: the system that would report dropped telemetry is the one\n * dropping it.\n */\n stats(): MonitorStats {\n return { ...this.counters, queued: this.queue.length };\n }\n\n /** Flush all queued events to the ingest endpoint */\n flush(): void {\n this.flushQueue(false);\n }\n\n /** Stop the monitor and flush remaining events */\n shutdown(): void {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n this.flushQueue(true);\n this.removeListeners();\n this.active = false;\n }\n\n /**\n * @param unloading the page (or process) is going away: ignore the backoff,\n * since this is the last chance these events get.\n */\n private flushQueue(unloading: boolean): void {\n if (this.queue.length === 0) return;\n\n // Check for global fetch BEFORE removing events from the queue — otherwise\n // on a runtime without fetch (Node <18) the batch would be dropped and lost.\n if (typeof fetch === \"undefined\") return;\n\n // After a transient failure, wait out the backoff instead of hitting a\n // struggling ingest again on every emit.\n if (!unloading && Date.now() < this.backoffUntil) return;\n\n const batch = this.queue.splice(0);\n this.send(batch, { remaining: bisectBudget(batch.length) });\n }\n\n private send(events: MonitorEvent[], budget: { remaining: number }): void {\n const lines: string[] = [];\n const sent: MonitorEvent[] = [];\n for (const e of events) {\n const line = this.serialize(e);\n if (line === null) {\n this.recordDrop(1);\n continue;\n }\n lines.push(line);\n sent.push(e);\n }\n if (lines.length === 0) return;\n\n const body = lines.join(\"\\n\");\n let request: Promise<{ ok?: boolean; status?: number } | undefined>;\n try {\n request = fetch(this.config.ingestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-ndjson\",\n \"X-Api-Key\": this.config.apiKey,\n },\n body,\n keepalive: byteLength(body) <= KEEPALIVE_MAX_BYTES,\n });\n } catch (err) {\n request = Promise.reject(err);\n }\n\n request.then(\n (res) => this.handleResponse(res, sent, budget),\n (err) => {\n if (this.config.debug) {\n console.warn(\"[monitor] flush failed:\", err);\n }\n this.retryLater(sent);\n }\n );\n }\n\n private handleResponse(\n res: { ok?: boolean; status?: number } | undefined,\n events: MonitorEvent[],\n budget: { remaining: number }\n ): void {\n const status = typeof res?.status === \"number\" ? res.status : 0;\n const outcome: Outcome = res?.ok ? \"delivered\" : classify(status);\n\n switch (outcome) {\n case \"delivered\":\n this.counters.flushed += events.length;\n this.failures = 0;\n this.backoffUntil = 0;\n return;\n\n case \"rejected\":\n // Ingest refuses a whole request when one event in it is\n // malformed. Split and resend until the bad one stands alone.\n if (events.length > 1 && budget.remaining > 0) {\n budget.remaining--;\n const mid = events.length >> 1;\n this.send(events.slice(0, mid), budget);\n this.send(events.slice(mid), budget);\n return;\n }\n this.counters.quarantined += events.length;\n this.recordDrop(events.length);\n if (this.config.debug) {\n console.warn(`[monitor] ingest rejected ${events.length} event(s) as malformed (status ${status}):`, events.map((e) => e.name));\n }\n return;\n\n case \"misconfigured\":\n // Nothing will be accepted until the key or URL changes.\n this.recordDrop(events.length);\n if (!this.warnedMisconfigured) {\n this.warnedMisconfigured = true;\n console.warn(`[monitor] ingest refused events with status ${status} — check ingestUrl and apiKey. Events are being dropped.`);\n }\n return;\n\n default:\n this.retryLater(events);\n }\n }\n\n /** Put events back at the front of the queue and back off before retrying. */\n private retryLater(events: MonitorEvent[]): void {\n this.failures++;\n const ceiling = Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** Math.min(this.failures - 1, 16));\n // Full jitter: every open tab sees ingest recover at the same moment.\n this.backoffUntil = Date.now() + 50 + Math.random() * ceiling;\n\n const room = MAX_QUEUE_SIZE - this.queue.length;\n const keep = room <= 0 ? [] : events.length > room ? events.slice(events.length - room) : events;\n this.recordDrop(events.length - keep.length);\n if (keep.length > 0) {\n this.queue = keep.concat(this.queue);\n }\n }\n\n /**\n * One NDJSON line for e, or null if it cannot be serialized. Never throws:\n * flush runs inside emit's auto-flush, and emit must never throw into the\n * caller.\n */\n private serialize(e: MonitorEvent): string | null {\n try {\n const line = JSON.stringify(e);\n // Only strings this long can exceed the limit once UTF-8 encoded.\n if (line.length <= MAX_LINE_BYTES / 3) return line;\n const size = byteLength(line);\n if (size <= MAX_LINE_BYTES) return line;\n\n const kept: Record<string, unknown> = { truncated: true, original_size_bytes: size };\n for (const k of GROUPING_KEYS) {\n const v = e.data[k];\n if (typeof v === \"string\") kept[k] = v.slice(0, MAX_FIELD_CHARS);\n else if (typeof v === \"number\" || typeof v === \"boolean\") kept[k] = v;\n }\n const shrunk = JSON.stringify({ ...e, data: kept });\n return byteLength(shrunk) <= MAX_LINE_BYTES ? shrunk : null;\n } catch {\n return null;\n }\n }\n\n private recordDrop(n: number): void {\n if (n <= 0) return;\n this.counters.dropped += n;\n if (this.onDrop) {\n try {\n this.onDrop(this.counters.dropped);\n } catch {\n // A broken callback must not break delivery.\n }\n }\n }\n\n private start(): void {\n if (this.active) return;\n this.active = true;\n\n const t = setInterval(() => this.flush(), this.config.flushInterval);\n // In Node, unref() lets the process exit even while the flush timer is pending.\n // Browser timers have no unref(), so guard on its presence.\n if (typeof (t as any).unref === \"function\") (t as any).unref();\n this.timer = t;\n\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"pagehide\", this.handlePageHide);\n }\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"hidden\") {\n this.flushQueue(true);\n }\n };\n\n private handlePageHide = (): void => {\n this.flushQueue(true);\n };\n\n private shouldIgnoreError(message: string, stack?: string): boolean {\n if (this.ignoreErrors.length === 0) return false;\n for (const pattern of this.ignoreErrors) {\n if (typeof pattern === \"string\") {\n if (message.includes(pattern) || (stack !== undefined && stack.includes(pattern))) {\n return true;\n }\n } else {\n if (pattern.test(message) || (stack !== undefined && pattern.test(stack))) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * The route a browser error happened on.\n *\n * Deliberately `pathname` only — never the search string or hash. Query\n * parameters routinely carry tokens, emails and other personal data, and this\n * value is both stored on the event and folded into the server-side issue\n * fingerprint, so anything included here is retained and grouped on.\n *\n * Returns undefined outside a browser so the Node handlers stay unaffected.\n */\n private currentPath(): string | undefined {\n if (typeof window === \"undefined\" || !window.location) return undefined;\n return window.location.pathname;\n }\n\n private errorHandler = (event: ErrorEvent): void => {\n const stack = event.error?.stack;\n if (this.shouldIgnoreError(event.message ?? \"\", stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n private rejectionHandler = (event: PromiseRejectionEvent): void => {\n const reason = event.reason;\n const message = reason?.message ?? String(reason);\n const stack = reason?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n // --- Node process handlers ---\n // uncaughtException/unhandledRejection are non-terminating here: we report the\n // error and return without calling process.exit, matching the browser handlers'\n // non-terminating behavior. Consumers keep their own crash semantics.\n\n private nodeExceptionHandler = (err: unknown): void => {\n const e = err as { message?: string; stack?: string } | undefined;\n const message = e?.message ?? String(err);\n const stack = e?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n };\n\n private nodeRejectionHandler = (reason: unknown): void => {\n const r = reason as { message?: string; stack?: string } | undefined;\n const message = r?.message ?? String(reason);\n const stack = r?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n };\n\n private installErrorHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"error\", this.errorHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"uncaughtException\", this.nodeExceptionHandler);\n }\n }\n\n private installRejectionHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"unhandledrejection\", this.rejectionHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n\n private removeListeners(): void {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"error\", this.errorHandler);\n window.removeEventListener(\"unhandledrejection\", this.rejectionHandler);\n window.removeEventListener(\"pagehide\", this.handlePageHide);\n }\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof process !== \"undefined\" && typeof process.removeListener === \"function\") {\n process.removeListener(\"uncaughtException\", this.nodeExceptionHandler);\n process.removeListener(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n}\n","import type { Monitor } from \"./client\";\nimport type { LogLevel } from \"./types\";\n\ninterface AxiosInstance {\n interceptors: {\n request: { use: (onFulfilled: (config: any) => any) => void };\n response: {\n use: (onFulfilled: (response: any) => any, onRejected: (error: any) => any) => void;\n };\n };\n}\n\nexport interface AxiosMonitorOptions {\n /** Only report events for responses with these status codes or above (default: 400) */\n minStatus?: number;\n /** Report successful requests too (default: false) */\n reportSuccess?: boolean;\n /** Paths to ignore (e.g. [\"/healthcheck\", \"/api/health\"]) */\n ignorePaths?: string[];\n}\n\n/**\n * The request URL without its query string or fragment. Query strings are where\n * tokens and email addresses travel in URLs, and anything reported is retained\n * for the life of the event store.\n */\nfunction stripQuery(url: string): string {\n const i = url.search(/[?#]/);\n return i === -1 ? url : url.slice(0, i);\n}\n\n/**\n * Attaches Monitor interceptors to an Axios instance.\n * Automatically reports API failures with request_id correlation.\n *\n * Works with both standard axios error handling AND `validateStatus: () => true`\n * (where all HTTP responses go through the fulfilled handler).\n */\nexport function attachAxiosMonitor(\n axiosInstance: AxiosInstance,\n monitor: Monitor,\n opts?: AxiosMonitorOptions\n): void {\n const minStatus = opts?.minStatus ?? 400;\n const reportSuccess = opts?.reportSuccess ?? false;\n const ignorePaths = opts?.ignorePaths ?? [];\n\n // Stamp request start time\n axiosInstance.interceptors.request.use((config: any) => {\n config.metadata = { startTime: Date.now() };\n return config;\n });\n\n axiosInstance.interceptors.response.use(\n (response: any) => {\n const url: string = stripQuery(response.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) return response;\n\n const statusCode: number = response.status ?? 0;\n const requestId: string = response.headers?.[\"x-request-id\"] ?? \"\";\n const durationMs = response.config?.metadata?.startTime\n ? Date.now() - response.config.metadata.startTime\n : undefined;\n\n // Handle error responses that come through fulfilled handler\n // (when validateStatus: () => true is used)\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: response.data?.error,\n error_message: response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n\n return response;\n }\n\n // Report successful requests if enabled\n if (reportSuccess && statusCode > 0) {\n monitor.info(\"api.request.success\", {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n duration_ms: durationMs,\n },\n });\n }\n\n return response;\n },\n (error: any) => {\n const url: string = stripQuery(error.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) {\n return Promise.reject(error);\n }\n\n const durationMs = error.config?.metadata?.startTime\n ? Date.now() - error.config.metadata.startTime\n : undefined;\n\n // Network errors (no response — timeout, DNS failure, CORS blocked)\n if (!error.response) {\n monitor.error(\"api.request.network_error\", {\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n error_code: error.code,\n error_message: error.message,\n duration_ms: durationMs,\n },\n });\n return Promise.reject(error);\n }\n\n // HTTP errors (when validateStatus is default — throws on non-2xx)\n const statusCode: number = error.response.status ?? 0;\n const requestId: string = error.response.headers?.[\"x-request-id\"] ?? \"\";\n\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: error.response.data?.error,\n error_message: error.response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n }\n\n return Promise.reject(error);\n }\n );\n}\n"],"mappings":";AAOA,IAAM,iBACF;AAMG,SAAS,qBAAqB,IAAqB;AACtD,SAAO,OAAO,MAAM,eAAe,KAAK,EAAE;AAC9C;AAEA,SAAS,YAAY,GAAuB;AACxC,QAAM,MAAM,IAAI,WAAW,CAAC;AAC5B,QAA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ACF,SAAS,MAAM,QAAQ,UAAU,IAAI,YAAY;AAAA,YACjD;AAAA,YACA,aAAa;AAAA,YACb,OAAO,MAAM,SAAS,MAAM;AAAA,YAC5B,eAAe,MAAM,SAAS,MAAM;AAAA,YACpC,aAAa;AAAA,UACjB;AAAA,QACJ,CAAC;AAAA,MACL;AAEA,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC/B;AAAA,EACJ;AACJ;","names":[]}
1
+ {"version":3,"sources":["../src/ids.ts","../src/client.ts","../src/axios.ts"],"sourcesContent":["/**\n * monitor-core's correlation-id rule (structs.correlationIDRegex), verbatim.\n *\n * Ingest validates job_id, request_id and trace_id against it and rejects the\n * WHOLE request when any line fails — so one malformed id, passed through\n * unchecked, loses every event batched with it.\n */\nconst CORRELATION_ID =\n /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|[0-9a-fA-F]{8,64})$/;\n\n/**\n * Whether monitor-core would accept `id` as a job_id, request_id or trace_id.\n * The empty string is valid: the server skips empty ids.\n */\nexport function isValidCorrelationId(id: string): boolean {\n return id === \"\" || CORRELATION_ID.test(id);\n}\n\nfunction randomBytes(n: number): Uint8Array {\n const out = new Uint8Array(n);\n const c = (globalThis as { crypto?: { getRandomValues?: (a: Uint8Array) => Uint8Array } }).crypto;\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(out);\n return out;\n }\n // Node 18 has no global crypto. Correlation ids need uniqueness, not secrecy.\n for (let i = 0; i < n; i++) out[i] = Math.floor(Math.random() * 256);\n return out;\n}\n\nfunction hex(bytes: Uint8Array): string {\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** A request_id monitor-core accepts: 16 hex characters. */\nexport function newRequestId(): string {\n return hex(randomBytes(8));\n}\n\n/** A job_id monitor-core accepts: 16 hex characters. */\nexport function newJobId(): string {\n return hex(randomBytes(8));\n}\n\n/** A trace_id monitor-core accepts: a hyphenated UUID v4. */\nexport function newTraceId(): string {\n const b = randomBytes(16);\n b[6] = (b[6] & 0x0f) | 0x40; // version 4\n b[8] = (b[8] & 0x3f) | 0x80; // RFC 4122 variant\n const h = hex(b);\n return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;\n}\n","import type { MonitorConfig, MonitorEvent, EmitOptions, LogLevel, MonitorStats } from \"./types\";\nimport { isValidCorrelationId, newJobId } from \"./ids\";\n\n// Minimal ambient shape for the Node `process` global — this package has no\n// @types/node dependency and targets the browser too, so `process` may be absent.\n// Guarded with `typeof process !== \"undefined\"` before use.\ndeclare const process:\n | {\n on?(event: string, listener: (...args: unknown[]) => void): void;\n removeListener?(event: string, listener: (...args: unknown[]) => void): void;\n listenerCount?(event: string): number;\n nextTick?(callback: () => void): void;\n exit?(code?: number): void;\n }\n | undefined;\n\nconst DEFAULT_FLUSH_INTERVAL = 2000;\nconst DEFAULT_BATCH_SIZE = 20;\nconst MAX_QUEUE_SIZE = 500;\n\n/**\n * monitor-core scans NDJSON with a 1 MiB line buffer and rejects the WHOLE\n * request when one line overflows it, so an oversized event is shrunk before it\n * is sent rather than discovered by a 400.\n */\nconst MAX_LINE_BYTES = 1_000_000;\n/** Characters kept per grouping field when an oversized event is shrunk. */\nconst MAX_FIELD_CHARS = 4096;\n/**\n * Browsers refuse a keepalive request once the page's in-flight keepalive\n * bodies exceed 64 KiB, and the refusal is a plain TypeError. Asking for\n * keepalive on a bigger body would fail — and be retried — forever.\n */\nconst KEEPALIVE_MAX_BYTES = 60_000;\n/** Backoff bounds after a transient ingest failure. */\nconst BASE_BACKOFF_MS = 1000;\nconst MAX_BACKOFF_MS = 60_000;\n\n/** The data keys monitor-core's issue fingerprint reads; they survive shrinking. */\nconst GROUPING_KEYS = [\"error\", \"error_message\", \"message\", \"path\", \"uri\", \"method\", \"reason\", \"status_code\"];\n\ntype Outcome = \"delivered\" | \"rejected\" | \"misconfigured\" | \"retryable\";\n\n/** How an ingest response should be handled. Mirrors go-monitor's classifyStatus. */\nfunction classify(status: number): Outcome {\n if (status >= 200 && status < 400) return \"delivered\";\n if (status === 408 || status === 429) return \"retryable\";\n if (status === 401 || status === 403 || status === 404 || status === 405) return \"misconfigured\";\n if (status >= 400 && status < 500) return \"rejected\";\n return \"retryable\";\n}\n\n/** Extra requests allowed to isolate malformed events in a batch of n. */\nfunction bisectBudget(n: number): number {\n let depth = 0;\n for (let x = n; x > 1; x = Math.ceil(x / 2)) depth++;\n return 4 * depth + 4;\n}\n\nlet encoder: TextEncoder | undefined;\nfunction byteLength(s: string): number {\n if (typeof TextEncoder === \"undefined\") return s.length * 3;\n encoder ??= new TextEncoder();\n return encoder.encode(s).length;\n}\n\n/**\n * monitor-core stores level verbatim and groups only exact \"error\"/\"fatal\" into\n * issues, so \"ERROR\" or \"warning\" would land and silently never be tracked.\n */\nfunction normalizeLevel(level: string): string {\n const l = (level || \"info\").toLowerCase();\n return l === \"warning\" ? \"warn\" : l;\n}\n\nexport class Monitor {\n private config: Required<\n Pick<MonitorConfig, \"service\" | \"ingestUrl\" | \"apiKey\" | \"env\" | \"flushInterval\" | \"batchSize\" | \"debug\">\n >;\n private ignoreErrors: (string | RegExp)[] = [];\n private onDrop?: (total: number) => void;\n private queue: MonitorEvent[] = [];\n private timer: ReturnType<typeof setInterval> | null = null;\n private userId: string = \"\";\n private jobId: string;\n private active = false;\n private backoffUntil = 0;\n private failures = 0;\n private warnedMisconfigured = false;\n private counters = { enqueued: 0, flushed: 0, dropped: 0, quarantined: 0 };\n\n constructor(config: MonitorConfig) {\n this.config = {\n service: config.service,\n ingestUrl: config.ingestUrl,\n apiKey: config.apiKey,\n env: config.env ?? \"production\",\n flushInterval: config.flushInterval ?? DEFAULT_FLUSH_INTERVAL,\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n debug: config.debug ?? false,\n };\n this.ignoreErrors = config.ignoreErrors ?? [];\n this.onDrop = config.onDrop;\n // One id per page load (or process): every event from this session\n // shares it, so a session's events can be pulled up together.\n this.jobId = newJobId();\n\n this.start();\n\n if (config.captureErrors !== false) {\n this.installErrorHandler();\n }\n if (config.captureUnhandledRejections !== false) {\n this.installRejectionHandler();\n }\n }\n\n /** Set a persistent user ID for all subsequent events */\n setUser(userId: string): void {\n this.userId = userId;\n }\n\n /** Clear the user ID */\n clearUser(): void {\n this.userId = \"\";\n }\n\n /**\n * Set a persistent job ID (session-level identifier). It must be a UUID or\n * 8-64 hex characters — see `isValidCorrelationId`; anything else is\n * cleared from each event and kept in data.invalid_job_id.\n */\n setJobId(jobId: string): void {\n this.jobId = jobId;\n }\n\n /** Emit an event at a specific level */\n emit(name: string, level: LogLevel, opts?: EmitOptions): void {\n if (!this.active) return;\n\n // An id monitor-core would reject is cleared, not sent: one bad id\n // fails the whole request. The original is kept where it is useful.\n let data: Record<string, unknown> = opts?.data ?? {};\n const repair = (field: string, value: string): string => {\n if (isValidCorrelationId(value)) return value;\n data = { ...data, [`invalid_${field}`]: value.slice(0, 128) };\n if (this.config.debug) {\n console.warn(`[monitor] cleared invalid ${field} ${JSON.stringify(value)} (monitor-core accepts a UUID or 8-64 hex characters)`);\n }\n return \"\";\n };\n const jobId = repair(\"job_id\", this.jobId);\n const requestId = repair(\"request_id\", opts?.requestId ?? \"\");\n const traceId = repair(\"trace_id\", opts?.traceId ?? \"\");\n\n const event: MonitorEvent = {\n timestamp: new Date().toISOString(),\n service: this.config.service,\n env: this.config.env,\n job_id: jobId,\n request_id: requestId,\n trace_id: traceId,\n user_id: opts?.userId ?? this.userId,\n name: name || \"event.unnamed\",\n level: normalizeLevel(level),\n data,\n };\n\n if (this.queue.length >= MAX_QUEUE_SIZE) {\n // Drop oldest events to prevent unbounded memory growth\n this.queue.shift();\n this.recordDrop(1);\n }\n\n this.queue.push(event);\n this.counters.enqueued++;\n\n if (this.config.debug) {\n console.debug(`[monitor] ${level} ${name}`, opts?.data);\n }\n\n if (this.queue.length >= this.config.batchSize) {\n this.flush();\n }\n }\n\n /** Emit a debug event */\n debug(name: string, opts?: EmitOptions): void {\n this.emit(name, \"debug\", opts);\n }\n\n /** Emit an info event */\n info(name: string, opts?: EmitOptions): void {\n this.emit(name, \"info\", opts);\n }\n\n /** Emit a warning event */\n warn(name: string, opts?: EmitOptions): void {\n this.emit(name, \"warn\", opts);\n }\n\n /** Emit an error event */\n error(name: string, opts?: EmitOptions): void {\n this.emit(name, \"error\", opts);\n }\n\n /** Emit a fatal event */\n fatal(name: string, opts?: EmitOptions): void {\n this.emit(name, \"fatal\", opts);\n }\n\n /**\n * Lifetime counters. Surface them wherever loss would otherwise go\n * unnoticed: the system that would report dropped telemetry is the one\n * dropping it.\n */\n stats(): MonitorStats {\n return { ...this.counters, queued: this.queue.length };\n }\n\n /** Flush all queued events to the ingest endpoint */\n flush(): void {\n this.flushQueue(false);\n }\n\n /** Stop the monitor and flush remaining events */\n shutdown(): void {\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = null;\n }\n this.flushQueue(true);\n this.removeListeners();\n this.active = false;\n }\n\n /**\n * @param unloading the page (or process) is going away: ignore the backoff,\n * since this is the last chance these events get.\n */\n private flushQueue(unloading: boolean): void {\n if (this.queue.length === 0) return;\n\n // Check for global fetch BEFORE removing events from the queue — otherwise\n // on a runtime without fetch (Node <18) the batch would be dropped and lost.\n if (typeof fetch === \"undefined\") return;\n\n // After a transient failure, wait out the backoff instead of hitting a\n // struggling ingest again on every emit.\n if (!unloading && Date.now() < this.backoffUntil) return;\n\n const batch = this.queue.splice(0);\n this.send(batch, { remaining: bisectBudget(batch.length) });\n }\n\n private send(events: MonitorEvent[], budget: { remaining: number }): void {\n const lines: string[] = [];\n const sent: MonitorEvent[] = [];\n for (const e of events) {\n const line = this.serialize(e);\n if (line === null) {\n this.recordDrop(1);\n continue;\n }\n lines.push(line);\n sent.push(e);\n }\n if (lines.length === 0) return;\n\n const body = lines.join(\"\\n\");\n let request: Promise<{ ok?: boolean; status?: number } | undefined>;\n try {\n request = fetch(this.config.ingestUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-ndjson\",\n \"X-Api-Key\": this.config.apiKey,\n },\n body,\n keepalive: byteLength(body) <= KEEPALIVE_MAX_BYTES,\n });\n } catch (err) {\n request = Promise.reject(err);\n }\n\n request.then(\n (res) => this.handleResponse(res, sent, budget),\n (err) => {\n if (this.config.debug) {\n console.warn(\"[monitor] flush failed:\", err);\n }\n this.retryLater(sent);\n }\n );\n }\n\n private handleResponse(\n res: { ok?: boolean; status?: number } | undefined,\n events: MonitorEvent[],\n budget: { remaining: number }\n ): void {\n const status = typeof res?.status === \"number\" ? res.status : 0;\n const outcome: Outcome = res?.ok ? \"delivered\" : classify(status);\n\n switch (outcome) {\n case \"delivered\":\n this.counters.flushed += events.length;\n this.failures = 0;\n this.backoffUntil = 0;\n return;\n\n case \"rejected\":\n // Ingest refuses a whole request when one event in it is\n // malformed. Split and resend until the bad one stands alone.\n if (events.length > 1 && budget.remaining > 0) {\n budget.remaining--;\n const mid = events.length >> 1;\n this.send(events.slice(0, mid), budget);\n this.send(events.slice(mid), budget);\n return;\n }\n this.counters.quarantined += events.length;\n this.recordDrop(events.length);\n if (this.config.debug) {\n console.warn(`[monitor] ingest rejected ${events.length} event(s) as malformed (status ${status}):`, events.map((e) => e.name));\n }\n return;\n\n case \"misconfigured\":\n // Nothing will be accepted until the key or URL changes.\n this.recordDrop(events.length);\n if (!this.warnedMisconfigured) {\n this.warnedMisconfigured = true;\n console.warn(`[monitor] ingest refused events with status ${status} — check ingestUrl and apiKey. Events are being dropped.`);\n }\n return;\n\n default:\n this.retryLater(events);\n }\n }\n\n /** Put events back at the front of the queue and back off before retrying. */\n private retryLater(events: MonitorEvent[]): void {\n this.failures++;\n const ceiling = Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** Math.min(this.failures - 1, 16));\n // Full jitter: every open tab sees ingest recover at the same moment.\n this.backoffUntil = Date.now() + 50 + Math.random() * ceiling;\n\n const room = MAX_QUEUE_SIZE - this.queue.length;\n const keep = room <= 0 ? [] : events.length > room ? events.slice(events.length - room) : events;\n this.recordDrop(events.length - keep.length);\n if (keep.length > 0) {\n this.queue = keep.concat(this.queue);\n }\n }\n\n /**\n * One NDJSON line for e, or null if it cannot be serialized. Never throws:\n * flush runs inside emit's auto-flush, and emit must never throw into the\n * caller.\n */\n private serialize(e: MonitorEvent): string | null {\n try {\n const line = JSON.stringify(e);\n // Only strings this long can exceed the limit once UTF-8 encoded.\n if (line.length <= MAX_LINE_BYTES / 3) return line;\n const size = byteLength(line);\n if (size <= MAX_LINE_BYTES) return line;\n\n const kept: Record<string, unknown> = { truncated: true, original_size_bytes: size };\n for (const k of GROUPING_KEYS) {\n const v = e.data[k];\n if (typeof v === \"string\") kept[k] = v.slice(0, MAX_FIELD_CHARS);\n else if (typeof v === \"number\" || typeof v === \"boolean\") kept[k] = v;\n }\n const shrunk = JSON.stringify({ ...e, data: kept });\n return byteLength(shrunk) <= MAX_LINE_BYTES ? shrunk : null;\n } catch {\n return null;\n }\n }\n\n private recordDrop(n: number): void {\n if (n <= 0) return;\n this.counters.dropped += n;\n if (this.onDrop) {\n try {\n this.onDrop(this.counters.dropped);\n } catch {\n // A broken callback must not break delivery.\n }\n }\n }\n\n private start(): void {\n if (this.active) return;\n this.active = true;\n\n const t = setInterval(() => this.flush(), this.config.flushInterval);\n // In Node, unref() lets the process exit even while the flush timer is pending.\n // Browser timers have no unref(), so guard on its presence.\n if (typeof (t as any).unref === \"function\") (t as any).unref();\n this.timer = t;\n\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"pagehide\", this.handlePageHide);\n }\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"hidden\") {\n this.flushQueue(true);\n }\n };\n\n private handlePageHide = (): void => {\n this.flushQueue(true);\n };\n\n private shouldIgnoreError(message: string, stack?: string): boolean {\n if (this.ignoreErrors.length === 0) return false;\n for (const pattern of this.ignoreErrors) {\n if (typeof pattern === \"string\") {\n if (message.includes(pattern) || (stack !== undefined && stack.includes(pattern))) {\n return true;\n }\n } else {\n if (pattern.test(message) || (stack !== undefined && pattern.test(stack))) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * The route a browser error happened on.\n *\n * Deliberately `pathname` only — never the search string or hash. Query\n * parameters routinely carry tokens, emails and other personal data, and this\n * value is both stored on the event and folded into the server-side issue\n * fingerprint, so anything included here is retained and grouped on.\n *\n * Returns undefined outside a browser so the Node handlers stay unaffected.\n */\n private currentPath(): string | undefined {\n if (typeof window === \"undefined\" || !window.location) return undefined;\n return window.location.pathname;\n }\n\n private errorHandler = (event: ErrorEvent): void => {\n const stack = event.error?.stack;\n if (this.shouldIgnoreError(event.message ?? \"\", stack)) return;\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n private rejectionHandler = (event: PromiseRejectionEvent): void => {\n const reason = event.reason;\n const message = reason?.message ?? String(reason);\n const stack = reason?.stack;\n if (this.shouldIgnoreError(message, stack)) return;\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n path: this.currentPath(),\n },\n });\n };\n\n // --- Node process handlers ---\n // Adding an uncaughtException or unhandledRejection listener changes what Node\n // does. With no listener, either one prints the error and exits with code 1;\n // with any listener, Node assumes it was handled and keeps running — in\n // whatever state the failure left it. So when this SDK is the only listener,\n // it reports the error and then does what Node would have done. When the app\n // has a listener of its own, the app has already decided; the SDK only reports.\n\n /** Grace for the final batch to leave before a Node-style crash exits. */\n private static readonly NODE_CRASH_GRACE_MS = 1500;\n\n /** Rejections already reported, so the re-raise below is not reported twice. */\n private reportedRejections = new WeakSet<object>();\n\n private nodeExceptionHandler = (err: unknown): void => {\n const alreadyReported =\n typeof err === \"object\" && err !== null && this.reportedRejections.has(err);\n const e = err as { message?: string; stack?: string } | undefined;\n const message = e?.message ?? String(err);\n const stack = e?.stack;\n if (!alreadyReported && !this.shouldIgnoreError(message, stack)) {\n this.emit(\"client.error.uncaught\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n }\n if (this.isSoleListener(\"uncaughtException\")) {\n this.crashLikeNode(err);\n }\n };\n\n private nodeRejectionHandler = (reason: unknown): void => {\n const r = reason as { message?: string; stack?: string } | undefined;\n const message = r?.message ?? String(reason);\n const stack = r?.stack;\n if (!this.shouldIgnoreError(message, stack)) {\n this.emit(\"client.error.unhandled_rejection\", \"error\", {\n data: {\n message,\n stack,\n },\n });\n }\n // Node's default is to raise an unhandled rejection as an uncaught\n // exception. This listener suppressed that, so re-raise it when nothing\n // else listens for rejections: the app's own uncaughtException handling,\n // or Node's crash, then applies exactly as it would without the SDK.\n if (this.isSoleListener(\"unhandledRejection\")) {\n if (typeof reason === \"object\" && reason !== null) {\n this.reportedRejections.add(reason);\n }\n this.reraise(reason);\n }\n };\n\n /** Hand an unhandled rejection back to Node as an uncaught exception. */\n private reraise(reason: unknown): void {\n process?.nextTick?.(() => {\n throw reason;\n });\n }\n\n /** True when this instance's own handler is the only listener for the event. */\n private isSoleListener(event: \"uncaughtException\" | \"unhandledRejection\"): boolean {\n const count = typeof process === \"undefined\" ? undefined : process.listenerCount;\n if (typeof count !== \"function\") {\n return false;\n }\n return count.call(process, event) <= 1;\n }\n\n /** Print the error as Node would, give the batch a moment to leave, exit 1. */\n private crashLikeNode(err: unknown): void {\n console.error(err);\n this.flush();\n setTimeout(() => process?.exit?.(1), Monitor.NODE_CRASH_GRACE_MS);\n }\n\n private installErrorHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"error\", this.errorHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"uncaughtException\", this.nodeExceptionHandler);\n }\n }\n\n private installRejectionHandler(): void {\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"unhandledrejection\", this.rejectionHandler);\n } else if (typeof process !== \"undefined\" && typeof process.on === \"function\") {\n process.on(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n\n private removeListeners(): void {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"error\", this.errorHandler);\n window.removeEventListener(\"unhandledrejection\", this.rejectionHandler);\n window.removeEventListener(\"pagehide\", this.handlePageHide);\n }\n if (typeof document !== \"undefined\") {\n document.removeEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n if (typeof process !== \"undefined\" && typeof process.removeListener === \"function\") {\n process.removeListener(\"uncaughtException\", this.nodeExceptionHandler);\n process.removeListener(\"unhandledRejection\", this.nodeRejectionHandler);\n }\n }\n}\n","import type { Monitor } from \"./client\";\nimport type { LogLevel } from \"./types\";\n\ninterface AxiosInstance {\n interceptors: {\n request: { use: (onFulfilled: (config: any) => any) => void };\n response: {\n use: (onFulfilled: (response: any) => any, onRejected: (error: any) => any) => void;\n };\n };\n}\n\nexport interface AxiosMonitorOptions {\n /** Only report events for responses with these status codes or above (default: 400) */\n minStatus?: number;\n /** Report successful requests too (default: false) */\n reportSuccess?: boolean;\n /** Paths to ignore (e.g. [\"/healthcheck\", \"/api/health\"]) */\n ignorePaths?: string[];\n}\n\n/**\n * The request URL without its query string or fragment. Query strings are where\n * tokens and email addresses travel in URLs, and anything reported is retained\n * for the life of the event store.\n */\nfunction stripQuery(url: string): string {\n const i = url.search(/[?#]/);\n return i === -1 ? url : url.slice(0, i);\n}\n\n/**\n * Attaches Monitor interceptors to an Axios instance.\n * Automatically reports API failures with request_id correlation.\n *\n * Works with both standard axios error handling AND `validateStatus: () => true`\n * (where all HTTP responses go through the fulfilled handler).\n */\nexport function attachAxiosMonitor(\n axiosInstance: AxiosInstance,\n monitor: Monitor,\n opts?: AxiosMonitorOptions\n): void {\n const minStatus = opts?.minStatus ?? 400;\n const reportSuccess = opts?.reportSuccess ?? false;\n const ignorePaths = opts?.ignorePaths ?? [];\n\n // Stamp request start time\n axiosInstance.interceptors.request.use((config: any) => {\n config.metadata = { startTime: Date.now() };\n return config;\n });\n\n axiosInstance.interceptors.response.use(\n (response: any) => {\n const url: string = stripQuery(response.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) return response;\n\n const statusCode: number = response.status ?? 0;\n const requestId: string = response.headers?.[\"x-request-id\"] ?? \"\";\n const durationMs = response.config?.metadata?.startTime\n ? Date.now() - response.config.metadata.startTime\n : undefined;\n\n // Handle error responses that come through fulfilled handler\n // (when validateStatus: () => true is used)\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: response.data?.error,\n error_message: response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n\n return response;\n }\n\n // Report successful requests if enabled\n if (reportSuccess && statusCode > 0) {\n monitor.info(\"api.request.success\", {\n requestId,\n data: {\n method: (response.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n duration_ms: durationMs,\n },\n });\n }\n\n return response;\n },\n (error: any) => {\n const url: string = stripQuery(error.config?.url ?? \"\");\n if (ignorePaths.some((p) => url.includes(p))) {\n return Promise.reject(error);\n }\n\n const durationMs = error.config?.metadata?.startTime\n ? Date.now() - error.config.metadata.startTime\n : undefined;\n\n // Network errors (no response — timeout, DNS failure, CORS blocked)\n if (!error.response) {\n monitor.error(\"api.request.network_error\", {\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n error_code: error.code,\n error_message: error.message,\n duration_ms: durationMs,\n },\n });\n return Promise.reject(error);\n }\n\n // HTTP errors (when validateStatus is default — throws on non-2xx)\n const statusCode: number = error.response.status ?? 0;\n const requestId: string = error.response.headers?.[\"x-request-id\"] ?? \"\";\n\n if (statusCode >= minStatus) {\n const level: LogLevel = statusCode >= 500 ? \"error\" : \"warn\";\n const name =\n statusCode >= 500 ? \"api.request.server_error\" : \"api.request.client_error\";\n\n monitor.emit(name, level, {\n requestId,\n data: {\n method: (error.config?.method ?? \"\").toUpperCase(),\n url,\n status_code: statusCode,\n error: error.response.data?.error,\n error_message: error.response.data?.error_message,\n duration_ms: durationMs,\n },\n });\n }\n\n return Promise.reject(error);\n }\n );\n}\n"],"mappings":";AAOA,IAAM,iBACF;AAMG,SAAS,qBAAqB,IAAqB;AACtD,SAAO,OAAO,MAAM,eAAe,KAAK,EAAE;AAC9C;AAEA,SAAS,YAAY,GAAuB;AACxC,QAAM,MAAM,IAAI,WAAW,CAAC;AAC5B,QAAM,IAAK,WAAgF;AAC3F,MAAI,KAAK,OAAO,EAAE,oBAAoB,YAAY;AAC9C,MAAE,gBAAgB,GAAG;AACrB,WAAO;AAAA,EACX;AAEA,WAAS,IAAI,GAAG,IAAI,GAAG,IAAK,KAAI,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AACnE,SAAO;AACX;AAEA,SAAS,IAAI,OAA2B;AACpC,SAAO,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC5E;AAGO,SAAS,eAAuB;AACnC,SAAO,IAAI,YAAY,CAAC,CAAC;AAC7B;AAGO,SAAS,WAAmB;AAC/B,SAAO,IAAI,YAAY,CAAC,CAAC;AAC7B;AAGO,SAAS,aAAqB;AACjC,QAAM,IAAI,YAAY,EAAE;AACxB,IAAE,CAAC,IAAK,EAAE,CAAC,IAAI,KAAQ;AACvB,IAAE,CAAC,IAAK,EAAE,CAAC,IAAI,KAAQ;AACvB,QAAM,IAAI,IAAI,CAAC;AACf,SAAO,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,EA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AAc,MAAM,6BAA6B;AAErD,gBAAQ,KAAK,MAAM,OAAO;AAAA,UACtB;AAAA,UACA,MAAM;AAAA,YACF,SAAS,MAAM,QAAQ,UAAU,IAAI,YAAY;AAAA,YACjD;AAAA,YACA,aAAa;AAAA,YACb,OAAO,MAAM,SAAS,MAAM;AAAA,YAC5B,eAAe,MAAM,SAAS,MAAM;AAAA,YACpC,aAAa;AAAA,UACjB;AAAA,QACJ,CAAC;AAAA,MACL;AAEA,aAAO,QAAQ,OAAO,KAAK;AAAA,IAC/B;AAAA,EACJ;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidenappleby/monitor-js",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Lightweight JavaScript/TypeScript client for Monitor event ingestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",