@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/README.md +16 -1
- package/dist/client.cjs +69 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +17 -1
- package/dist/client.d.ts +17 -1
- package/dist/client.mjs +69 -1
- package/dist/client.mjs.map +1 -1
- package/package.json +2 -2
- package/src/client/hooks/useDebugMode.ts +84 -0
- package/src/client/index.ts +2 -0
- package/src/client/store/index.ts +2 -0
- package/src/client/utils/env.ts +16 -0
- package/src/client/window.ts +3 -0
package/README.md
CHANGED
|
@@ -76,6 +76,7 @@ const res = await monitoredFetch('/api/orders', { method: 'POST', body: JSON.str
|
|
|
76
76
|
|--------|------|---------|-------------|
|
|
77
77
|
| `project` | `string` | `''` | Project name sent with every event |
|
|
78
78
|
| `environment` | `string` | `''` | `production` / `staging` / `development` |
|
|
79
|
+
| `buildId` | `string` | `sdk:<version>` | Build identifier (e.g. Next.js `BUILD_ID` or git SHA). Stamped on every event as `build_id`. Auto-filled with SDK version if not set |
|
|
79
80
|
| `baseUrl` | `string` | same origin | Base URL of the django-cfg backend |
|
|
80
81
|
| `flushInterval` | `number` | `5000` | Buffer flush interval (ms) |
|
|
81
82
|
| `maxBufferSize` | `number` | `20` | Max events before immediate flush |
|
|
@@ -137,7 +138,21 @@ window.monitor.flush()
|
|
|
137
138
|
|
|
138
139
|
// Inspect current state
|
|
139
140
|
window.monitor.status()
|
|
140
|
-
// → logs config, buffer size, session_id
|
|
141
|
+
// → logs sdk version, build_id, config, buffer size, session_id
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Debug Mode
|
|
145
|
+
|
|
146
|
+
`useDebugMode` hook controls whether the debug panel is unlocked:
|
|
147
|
+
|
|
148
|
+
- **development** — always `true`, no localStorage needed
|
|
149
|
+
- **production** — `?debug=1` in URL → persists to `localStorage.__debug_mode__`, panel unlocks
|
|
150
|
+
- **production** — `?debug=0` in URL → clears `localStorage.__debug_mode__`, panel locks
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { useDebugMode } from '@djangocfg/monitor/client'
|
|
154
|
+
|
|
155
|
+
const isDebug = useDebugMode()
|
|
141
156
|
```
|
|
142
157
|
|
|
143
158
|
## Debug Panel Integration
|
package/dist/client.cjs
CHANGED
|
@@ -266,11 +266,15 @@ __export(client_exports, {
|
|
|
266
266
|
EventLevel: () => FrontendEventIngestRequestLevel,
|
|
267
267
|
EventType: () => FrontendEventIngestRequestEventType,
|
|
268
268
|
FrontendMonitor: () => FrontendMonitor,
|
|
269
|
+
MONITOR_VERSION: () => MONITOR_VERSION,
|
|
269
270
|
MonitorProvider: () => MonitorProvider,
|
|
270
271
|
getSessionId: () => getSessionId,
|
|
271
272
|
initWindowMonitor: () => initWindowMonitor,
|
|
273
|
+
isDevelopment: () => isDevelopment,
|
|
274
|
+
isProduction: () => isProduction,
|
|
272
275
|
monitorStore: () => monitorStore,
|
|
273
|
-
monitoredFetch: () => monitoredFetch
|
|
276
|
+
monitoredFetch: () => monitoredFetch,
|
|
277
|
+
useDebugMode: () => useDebugMode
|
|
274
278
|
});
|
|
275
279
|
module.exports = __toCommonJS(client_exports);
|
|
276
280
|
|
|
@@ -1353,6 +1357,11 @@ async function sendBatch(batch, useBeacon = false) {
|
|
|
1353
1357
|
}
|
|
1354
1358
|
__name(sendBatch, "sendBatch");
|
|
1355
1359
|
|
|
1360
|
+
// src/client/utils/env.ts
|
|
1361
|
+
var isDevelopment = true;
|
|
1362
|
+
var isProduction = false;
|
|
1363
|
+
var MONITOR_VERSION = "2.1.231";
|
|
1364
|
+
|
|
1356
1365
|
// src/client/store/index.ts
|
|
1357
1366
|
var CIRCUIT_BREAKER_THRESHOLD = 3;
|
|
1358
1367
|
var CIRCUIT_BREAKER_COOLDOWN_MS = 6e4;
|
|
@@ -1366,6 +1375,7 @@ var monitorStore = (0, import_vanilla.createStore)((set, get) => ({
|
|
|
1366
1375
|
const { config, buffer } = get();
|
|
1367
1376
|
const maxSize = config.maxBufferSize ?? 20;
|
|
1368
1377
|
const sanitized = {
|
|
1378
|
+
build_id: event.build_id ?? config.buildId ?? `sdk:${MONITOR_VERSION}`,
|
|
1369
1379
|
...event,
|
|
1370
1380
|
// Enforce field size limits before buffering (last-resort backstop)
|
|
1371
1381
|
message: event.message && event.message.length > 4997 ? event.message.slice(0, 4997) + "..." : event.message,
|
|
@@ -1727,6 +1737,8 @@ function initWindowMonitor() {
|
|
|
1727
1737
|
status() {
|
|
1728
1738
|
const state = monitorStore.getState();
|
|
1729
1739
|
console.group("[monitor] status");
|
|
1740
|
+
console.log("sdk version:", MONITOR_VERSION);
|
|
1741
|
+
console.log("build_id:", state.config.buildId ?? `sdk:${MONITOR_VERSION}`);
|
|
1730
1742
|
console.log("config:", state.config);
|
|
1731
1743
|
console.log("buffer size:", state.buffer.length);
|
|
1732
1744
|
console.log("initialized:", state.initialized);
|
|
@@ -1749,6 +1761,62 @@ function MonitorProvider({ children, ...config }) {
|
|
|
1749
1761
|
}
|
|
1750
1762
|
__name(MonitorProvider, "MonitorProvider");
|
|
1751
1763
|
|
|
1764
|
+
// src/client/hooks/useDebugMode.ts
|
|
1765
|
+
var import_react2 = require("react");
|
|
1766
|
+
var LS_KEY = "__debug_mode__";
|
|
1767
|
+
function readFromStorage() {
|
|
1768
|
+
try {
|
|
1769
|
+
return localStorage.getItem(LS_KEY) === "1";
|
|
1770
|
+
} catch {
|
|
1771
|
+
return false;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
__name(readFromStorage, "readFromStorage");
|
|
1775
|
+
function persistToStorage() {
|
|
1776
|
+
try {
|
|
1777
|
+
localStorage.setItem(LS_KEY, "1");
|
|
1778
|
+
} catch {
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
__name(persistToStorage, "persistToStorage");
|
|
1782
|
+
function clearFromStorage() {
|
|
1783
|
+
try {
|
|
1784
|
+
localStorage.removeItem(LS_KEY);
|
|
1785
|
+
} catch {
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
__name(clearFromStorage, "clearFromStorage");
|
|
1789
|
+
function consumeDebugParam() {
|
|
1790
|
+
if (typeof window === "undefined") return null;
|
|
1791
|
+
const params = new URLSearchParams(window.location.search);
|
|
1792
|
+
const value = params.get("debug");
|
|
1793
|
+
if (value === null) return null;
|
|
1794
|
+
if (value === "1") {
|
|
1795
|
+
persistToStorage();
|
|
1796
|
+
} else {
|
|
1797
|
+
clearFromStorage();
|
|
1798
|
+
}
|
|
1799
|
+
params.delete("debug");
|
|
1800
|
+
const newUrl = `${window.location.pathname}${params.toString() ? `?${params.toString()}` : ""}${window.location.hash}`;
|
|
1801
|
+
window.history.replaceState(null, "", newUrl);
|
|
1802
|
+
return value === "1";
|
|
1803
|
+
}
|
|
1804
|
+
__name(consumeDebugParam, "consumeDebugParam");
|
|
1805
|
+
function useDebugMode() {
|
|
1806
|
+
if (isDevelopment) return true;
|
|
1807
|
+
const [isDebug, setIsDebug] = (0, import_react2.useState)(false);
|
|
1808
|
+
(0, import_react2.useEffect)(() => {
|
|
1809
|
+
const fromUrl = consumeDebugParam();
|
|
1810
|
+
if (fromUrl !== null) {
|
|
1811
|
+
setIsDebug(fromUrl);
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
setIsDebug(readFromStorage());
|
|
1815
|
+
}, []);
|
|
1816
|
+
return isDebug;
|
|
1817
|
+
}
|
|
1818
|
+
__name(useDebugMode, "useDebugMode");
|
|
1819
|
+
|
|
1752
1820
|
// src/client/index.ts
|
|
1753
1821
|
var flushInterval = null;
|
|
1754
1822
|
var cleanupFns = [];
|