@djangocfg/monitor 2.1.230 → 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 +26 -12
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -1
- package/dist/client.d.ts +3 -1
- package/dist/client.mjs +26 -12
- package/dist/client.mjs.map +1 -1
- package/package.json +2 -2
- package/src/client/hooks/useDebugMode.ts +21 -7
- package/src/client/index.ts +1 -1
- package/src/client/store/index.ts +2 -0
- package/src/client/utils/env.ts +3 -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,6 +266,7 @@ __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,
|
|
@@ -1356,6 +1357,11 @@ async function sendBatch(batch, useBeacon = false) {
|
|
|
1356
1357
|
}
|
|
1357
1358
|
__name(sendBatch, "sendBatch");
|
|
1358
1359
|
|
|
1360
|
+
// src/client/utils/env.ts
|
|
1361
|
+
var isDevelopment = true;
|
|
1362
|
+
var isProduction = false;
|
|
1363
|
+
var MONITOR_VERSION = "2.1.231";
|
|
1364
|
+
|
|
1359
1365
|
// src/client/store/index.ts
|
|
1360
1366
|
var CIRCUIT_BREAKER_THRESHOLD = 3;
|
|
1361
1367
|
var CIRCUIT_BREAKER_COOLDOWN_MS = 6e4;
|
|
@@ -1369,6 +1375,7 @@ var monitorStore = (0, import_vanilla.createStore)((set, get) => ({
|
|
|
1369
1375
|
const { config, buffer } = get();
|
|
1370
1376
|
const maxSize = config.maxBufferSize ?? 20;
|
|
1371
1377
|
const sanitized = {
|
|
1378
|
+
build_id: event.build_id ?? config.buildId ?? `sdk:${MONITOR_VERSION}`,
|
|
1372
1379
|
...event,
|
|
1373
1380
|
// Enforce field size limits before buffering (last-resort backstop)
|
|
1374
1381
|
message: event.message && event.message.length > 4997 ? event.message.slice(0, 4997) + "..." : event.message,
|
|
@@ -1730,6 +1737,8 @@ function initWindowMonitor() {
|
|
|
1730
1737
|
status() {
|
|
1731
1738
|
const state = monitorStore.getState();
|
|
1732
1739
|
console.group("[monitor] status");
|
|
1740
|
+
console.log("sdk version:", MONITOR_VERSION);
|
|
1741
|
+
console.log("build_id:", state.config.buildId ?? `sdk:${MONITOR_VERSION}`);
|
|
1733
1742
|
console.log("config:", state.config);
|
|
1734
1743
|
console.log("buffer size:", state.buffer.length);
|
|
1735
1744
|
console.log("initialized:", state.initialized);
|
|
@@ -1754,12 +1763,6 @@ __name(MonitorProvider, "MonitorProvider");
|
|
|
1754
1763
|
|
|
1755
1764
|
// src/client/hooks/useDebugMode.ts
|
|
1756
1765
|
var import_react2 = require("react");
|
|
1757
|
-
|
|
1758
|
-
// src/client/utils/env.ts
|
|
1759
|
-
var isDevelopment = true;
|
|
1760
|
-
var isProduction = false;
|
|
1761
|
-
|
|
1762
|
-
// src/client/hooks/useDebugMode.ts
|
|
1763
1766
|
var LS_KEY = "__debug_mode__";
|
|
1764
1767
|
function readFromStorage() {
|
|
1765
1768
|
try {
|
|
@@ -1776,16 +1779,27 @@ function persistToStorage() {
|
|
|
1776
1779
|
}
|
|
1777
1780
|
}
|
|
1778
1781
|
__name(persistToStorage, "persistToStorage");
|
|
1782
|
+
function clearFromStorage() {
|
|
1783
|
+
try {
|
|
1784
|
+
localStorage.removeItem(LS_KEY);
|
|
1785
|
+
} catch {
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
__name(clearFromStorage, "clearFromStorage");
|
|
1779
1789
|
function consumeDebugParam() {
|
|
1780
|
-
if (typeof window === "undefined") return
|
|
1790
|
+
if (typeof window === "undefined") return null;
|
|
1781
1791
|
const params = new URLSearchParams(window.location.search);
|
|
1782
1792
|
const value = params.get("debug");
|
|
1783
|
-
if (
|
|
1784
|
-
|
|
1793
|
+
if (value === null) return null;
|
|
1794
|
+
if (value === "1") {
|
|
1795
|
+
persistToStorage();
|
|
1796
|
+
} else {
|
|
1797
|
+
clearFromStorage();
|
|
1798
|
+
}
|
|
1785
1799
|
params.delete("debug");
|
|
1786
1800
|
const newUrl = `${window.location.pathname}${params.toString() ? `?${params.toString()}` : ""}${window.location.hash}`;
|
|
1787
1801
|
window.history.replaceState(null, "", newUrl);
|
|
1788
|
-
return
|
|
1802
|
+
return value === "1";
|
|
1789
1803
|
}
|
|
1790
1804
|
__name(consumeDebugParam, "consumeDebugParam");
|
|
1791
1805
|
function useDebugMode() {
|
|
@@ -1793,8 +1807,8 @@ function useDebugMode() {
|
|
|
1793
1807
|
const [isDebug, setIsDebug] = (0, import_react2.useState)(false);
|
|
1794
1808
|
(0, import_react2.useEffect)(() => {
|
|
1795
1809
|
const fromUrl = consumeDebugParam();
|
|
1796
|
-
if (fromUrl) {
|
|
1797
|
-
setIsDebug(
|
|
1810
|
+
if (fromUrl !== null) {
|
|
1811
|
+
setIsDebug(fromUrl);
|
|
1798
1812
|
return;
|
|
1799
1813
|
}
|
|
1800
1814
|
setIsDebug(readFromStorage());
|