@djangocfg/monitor 2.1.229 → 2.1.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.cts CHANGED
@@ -150,6 +150,22 @@ interface MonitorState {
150
150
  }
151
151
  declare const monitorStore: zustand_vanilla.StoreApi<MonitorState>;
152
152
 
153
+ declare function useDebugMode(): boolean;
154
+
155
+ /**
156
+ * Environment utilities.
157
+ *
158
+ * Use these constants instead of inline process.env.NODE_ENV checks.
159
+ * Webpack/esbuild replaces process.env.NODE_ENV statically at build time,
160
+ * so these are zero-cost — they tree-shake correctly in both client and server bundles.
161
+ */
162
+ /** True only in `next dev` / jest / vitest */
163
+ declare const isDevelopment: boolean;
164
+ /** True in production builds and test environments */
165
+ declare const isProduction: boolean;
166
+ /** Package version — injected at build time via tsup define, falls back to package.json value */
167
+ declare const MONITOR_VERSION: string;
168
+
153
169
  /**
154
170
  * @djangocfg/monitor/client
155
171
  *
@@ -178,4 +194,4 @@ declare const FrontendMonitor: {
178
194
  destroy(): void;
179
195
  };
180
196
 
181
- export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, monitorStore, monitoredFetch };
197
+ export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, MONITOR_VERSION, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
package/dist/client.d.ts CHANGED
@@ -150,6 +150,22 @@ interface MonitorState {
150
150
  }
151
151
  declare const monitorStore: zustand_vanilla.StoreApi<MonitorState>;
152
152
 
153
+ declare function useDebugMode(): boolean;
154
+
155
+ /**
156
+ * Environment utilities.
157
+ *
158
+ * Use these constants instead of inline process.env.NODE_ENV checks.
159
+ * Webpack/esbuild replaces process.env.NODE_ENV statically at build time,
160
+ * so these are zero-cost — they tree-shake correctly in both client and server bundles.
161
+ */
162
+ /** True only in `next dev` / jest / vitest */
163
+ declare const isDevelopment: boolean;
164
+ /** True in production builds and test environments */
165
+ declare const isProduction: boolean;
166
+ /** Package version — injected at build time via tsup define, falls back to package.json value */
167
+ declare const MONITOR_VERSION: string;
168
+
153
169
  /**
154
170
  * @djangocfg/monitor/client
155
171
  *
@@ -178,4 +194,4 @@ declare const FrontendMonitor: {
178
194
  destroy(): void;
179
195
  };
180
196
 
181
- export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, monitorStore, monitoredFetch };
197
+ export { FrontendEventIngestRequestLevel as EventLevel, FrontendEventIngestRequestEventType as EventType, FrontendMonitor, MONITOR_VERSION, type MonitorConfig, type FrontendEventIngestRequest as MonitorEvent, MonitorProvider, type MonitorProviderProps, type WindowMonitorAPI, getSessionId, initWindowMonitor, isDevelopment, isProduction, monitorStore, monitoredFetch, useDebugMode };
package/dist/client.mjs CHANGED
@@ -1334,6 +1334,11 @@ async function sendBatch(batch, useBeacon = false) {
1334
1334
  }
1335
1335
  __name(sendBatch, "sendBatch");
1336
1336
 
1337
+ // src/client/utils/env.ts
1338
+ var isDevelopment = true;
1339
+ var isProduction = false;
1340
+ var MONITOR_VERSION = "2.1.231";
1341
+
1337
1342
  // src/client/store/index.ts
1338
1343
  var CIRCUIT_BREAKER_THRESHOLD = 3;
1339
1344
  var CIRCUIT_BREAKER_COOLDOWN_MS = 6e4;
@@ -1347,6 +1352,7 @@ var monitorStore = createStore((set, get) => ({
1347
1352
  const { config, buffer } = get();
1348
1353
  const maxSize = config.maxBufferSize ?? 20;
1349
1354
  const sanitized = {
1355
+ build_id: event.build_id ?? config.buildId ?? `sdk:${MONITOR_VERSION}`,
1350
1356
  ...event,
1351
1357
  // Enforce field size limits before buffering (last-resort backstop)
1352
1358
  message: event.message && event.message.length > 4997 ? event.message.slice(0, 4997) + "..." : event.message,
@@ -1708,6 +1714,8 @@ function initWindowMonitor() {
1708
1714
  status() {
1709
1715
  const state = monitorStore.getState();
1710
1716
  console.group("[monitor] status");
1717
+ console.log("sdk version:", MONITOR_VERSION);
1718
+ console.log("build_id:", state.config.buildId ?? `sdk:${MONITOR_VERSION}`);
1711
1719
  console.log("config:", state.config);
1712
1720
  console.log("buffer size:", state.buffer.length);
1713
1721
  console.log("initialized:", state.initialized);
@@ -1730,6 +1738,62 @@ function MonitorProvider({ children, ...config }) {
1730
1738
  }
1731
1739
  __name(MonitorProvider, "MonitorProvider");
1732
1740
 
1741
+ // src/client/hooks/useDebugMode.ts
1742
+ import { useEffect as useEffect2, useState } from "react";
1743
+ var LS_KEY = "__debug_mode__";
1744
+ function readFromStorage() {
1745
+ try {
1746
+ return localStorage.getItem(LS_KEY) === "1";
1747
+ } catch {
1748
+ return false;
1749
+ }
1750
+ }
1751
+ __name(readFromStorage, "readFromStorage");
1752
+ function persistToStorage() {
1753
+ try {
1754
+ localStorage.setItem(LS_KEY, "1");
1755
+ } catch {
1756
+ }
1757
+ }
1758
+ __name(persistToStorage, "persistToStorage");
1759
+ function clearFromStorage() {
1760
+ try {
1761
+ localStorage.removeItem(LS_KEY);
1762
+ } catch {
1763
+ }
1764
+ }
1765
+ __name(clearFromStorage, "clearFromStorage");
1766
+ function consumeDebugParam() {
1767
+ if (typeof window === "undefined") return null;
1768
+ const params = new URLSearchParams(window.location.search);
1769
+ const value = params.get("debug");
1770
+ if (value === null) return null;
1771
+ if (value === "1") {
1772
+ persistToStorage();
1773
+ } else {
1774
+ clearFromStorage();
1775
+ }
1776
+ params.delete("debug");
1777
+ const newUrl = `${window.location.pathname}${params.toString() ? `?${params.toString()}` : ""}${window.location.hash}`;
1778
+ window.history.replaceState(null, "", newUrl);
1779
+ return value === "1";
1780
+ }
1781
+ __name(consumeDebugParam, "consumeDebugParam");
1782
+ function useDebugMode() {
1783
+ if (isDevelopment) return true;
1784
+ const [isDebug, setIsDebug] = useState(false);
1785
+ useEffect2(() => {
1786
+ const fromUrl = consumeDebugParam();
1787
+ if (fromUrl !== null) {
1788
+ setIsDebug(fromUrl);
1789
+ return;
1790
+ }
1791
+ setIsDebug(readFromStorage());
1792
+ }, []);
1793
+ return isDebug;
1794
+ }
1795
+ __name(useDebugMode, "useDebugMode");
1796
+
1733
1797
  // src/client/index.ts
1734
1798
  var flushInterval = null;
1735
1799
  var cleanupFns = [];
@@ -1771,10 +1835,14 @@ export {
1771
1835
  FrontendEventIngestRequestLevel as EventLevel,
1772
1836
  FrontendEventIngestRequestEventType as EventType,
1773
1837
  FrontendMonitor,
1838
+ MONITOR_VERSION,
1774
1839
  MonitorProvider,
1775
1840
  getSessionId,
1776
1841
  initWindowMonitor,
1842
+ isDevelopment,
1843
+ isProduction,
1777
1844
  monitorStore,
1778
- monitoredFetch
1845
+ monitoredFetch,
1846
+ useDebugMode
1779
1847
  };
1780
1848
  //# sourceMappingURL=client.mjs.map