@victor-studio/monitor 0.1.0 → 0.4.0
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/errors/index.cjs +93 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +183 -0
- package/dist/errors/index.d.ts +183 -0
- package/dist/errors/index.js +88 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.cjs +277 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -39
- package/dist/index.d.ts +144 -39
- package/dist/index.js +276 -37
- package/dist/index.js.map +1 -1
- package/dist/next/index.cjs +31 -12
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +115 -45
- package/dist/next/index.d.ts +115 -45
- package/dist/next/index.js +31 -12
- package/dist/next/index.js.map +1 -1
- package/dist/react/index.cjs +20 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +104 -38
- package/dist/react/index.d.ts +104 -38
- package/dist/react/index.js +20 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +17 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,72 +1,177 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
timestamp: string;
|
|
1
|
+
interface HeartbeatData {
|
|
2
|
+
status: 'online' | 'offline';
|
|
3
|
+
latencyMs: number;
|
|
5
4
|
}
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
interface RequestData {
|
|
6
|
+
method: string;
|
|
7
|
+
route: string;
|
|
8
|
+
statusCode: number;
|
|
9
|
+
responseTimeMs: number;
|
|
10
|
+
userAgent?: string;
|
|
11
|
+
region?: string;
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
interface VitalData {
|
|
14
|
+
name: 'LCP' | 'INP' | 'CLS' | 'FCP' | 'TTFB';
|
|
15
|
+
value: number;
|
|
16
|
+
rating: 'good' | 'needs-improvement' | 'poor';
|
|
17
|
+
page?: string;
|
|
18
|
+
deviceType?: string;
|
|
19
|
+
browser?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ErrorData {
|
|
22
|
+
type: 'unhandled' | 'caught' | 'promise';
|
|
23
|
+
message: string;
|
|
24
|
+
stack?: string;
|
|
25
|
+
groupingKey: string;
|
|
26
|
+
route?: string;
|
|
27
|
+
method?: string;
|
|
28
|
+
statusCode?: number;
|
|
29
|
+
environment?: string;
|
|
30
|
+
commitHash?: string;
|
|
31
|
+
extra?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
interface DeployData {
|
|
34
|
+
commitHash: string;
|
|
35
|
+
branch?: string;
|
|
36
|
+
author?: string;
|
|
37
|
+
status: 'started' | 'succeeded' | 'failed';
|
|
38
|
+
buildDurationMs?: number;
|
|
39
|
+
url?: string;
|
|
40
|
+
environment?: string;
|
|
41
|
+
provider?: string;
|
|
21
42
|
}
|
|
43
|
+
interface AdapterData {
|
|
44
|
+
adapter: string;
|
|
45
|
+
operation: string;
|
|
46
|
+
durationMs: number;
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
meta?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
type MonitorEvent = {
|
|
52
|
+
type: 'heartbeat';
|
|
53
|
+
data: HeartbeatData;
|
|
54
|
+
timestamp: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'request';
|
|
57
|
+
data: RequestData;
|
|
58
|
+
timestamp: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'vital';
|
|
61
|
+
data: VitalData;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'error';
|
|
65
|
+
data: ErrorData;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'deploy';
|
|
69
|
+
data: DeployData;
|
|
70
|
+
timestamp: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'adapter';
|
|
73
|
+
data: AdapterData;
|
|
74
|
+
timestamp: string;
|
|
75
|
+
};
|
|
76
|
+
type MonitorEventType = MonitorEvent['type'];
|
|
77
|
+
/** Evento sem timestamp — usado pelo collector ao receber do client */
|
|
78
|
+
type MonitorEventInput = Omit<MonitorEvent, 'timestamp'>;
|
|
79
|
+
/** Hook para filtrar/modificar eventos antes do envio */
|
|
80
|
+
type BeforeSendHook = (event: MonitorEvent) => MonitorEvent | null;
|
|
22
81
|
|
|
23
82
|
interface MonitorConfig {
|
|
24
83
|
/** ID do projeto no Nuvio */
|
|
25
84
|
projectId: string;
|
|
26
85
|
/** API key gerada no Nuvio */
|
|
27
86
|
apiKey: string;
|
|
28
|
-
/** URL do endpoint de ingest
|
|
87
|
+
/** URL do endpoint de ingest */
|
|
29
88
|
endpoint: string;
|
|
30
89
|
/** Intervalo do heartbeat em ms (default: 60000) */
|
|
31
90
|
heartbeatInterval?: number;
|
|
32
91
|
/** Intervalo do flush do buffer em ms (default: 30000) */
|
|
33
92
|
flushInterval?: number;
|
|
93
|
+
/** Timeout do fetch em ms (default: 10000) */
|
|
94
|
+
timeout?: number;
|
|
95
|
+
/** Max tentativas de retry (default: 3) */
|
|
96
|
+
maxRetries?: number;
|
|
34
97
|
/** Desabilitar em desenvolvimento (default: true) */
|
|
35
98
|
disableInDev?: boolean;
|
|
99
|
+
/** Taxa de amostragem 0.0-1.0 (default: 1.0). Heartbeats nunca são amostrados */
|
|
100
|
+
sampleRate?: number;
|
|
101
|
+
/** Hook chamado antes de enfileirar cada evento. Retorna null para dropar */
|
|
102
|
+
beforeSend?: BeforeSendHook;
|
|
103
|
+
/** Habilitar logs de debug no console (default: false) */
|
|
104
|
+
debug?: boolean;
|
|
105
|
+
/** Capturar erros globais automaticamente — window.onerror (default: false) */
|
|
106
|
+
captureErrors?: boolean;
|
|
107
|
+
/** Capturar unhandled promise rejections automaticamente (default: false) */
|
|
108
|
+
captureUnhandledRejections?: boolean;
|
|
36
109
|
}
|
|
37
110
|
declare class MonitorClient {
|
|
38
111
|
readonly config: MonitorConfig;
|
|
39
|
-
readonly collector
|
|
112
|
+
private readonly collector;
|
|
113
|
+
private readonly logger;
|
|
40
114
|
private heartbeatTimer;
|
|
115
|
+
private globalHandlersCleanup;
|
|
41
116
|
private active;
|
|
42
117
|
constructor(config: MonitorConfig);
|
|
43
118
|
/** Inicia o monitoring (heartbeat + collector) */
|
|
44
119
|
start(): void;
|
|
45
120
|
/** Para o monitoring */
|
|
46
121
|
stop(): void;
|
|
122
|
+
/** Força um flush imediato do buffer */
|
|
123
|
+
flush(): void;
|
|
124
|
+
/** Verifica se o monitoring está ativo */
|
|
125
|
+
get isActive(): boolean;
|
|
47
126
|
/** Registra um evento de request HTTP (usado pelo middleware) */
|
|
48
|
-
trackRequest(data:
|
|
49
|
-
method: string;
|
|
50
|
-
route: string;
|
|
51
|
-
statusCode: number;
|
|
52
|
-
responseTimeMs: number;
|
|
53
|
-
userAgent?: string;
|
|
54
|
-
region?: string;
|
|
55
|
-
}): void;
|
|
127
|
+
trackRequest(data: RequestData): void;
|
|
56
128
|
/** Registra um Web Vital (usado pelo MonitorScript) */
|
|
57
|
-
trackVital(data:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}): void;
|
|
129
|
+
trackVital(data: VitalData): void;
|
|
130
|
+
/** Registra um evento de adapter (DB, cache, AI, queue, email) */
|
|
131
|
+
trackAdapter(data: AdapterData): void;
|
|
132
|
+
/** Registra um erro capturado */
|
|
133
|
+
captureError(data: ErrorData): void;
|
|
134
|
+
/** Registra um evento de deploy */
|
|
135
|
+
trackDeploy(data: DeployData): void;
|
|
65
136
|
private startHeartbeat;
|
|
66
137
|
private sendHeartbeat;
|
|
67
|
-
private isDev;
|
|
68
138
|
}
|
|
69
139
|
|
|
140
|
+
interface CaptureContext {
|
|
141
|
+
route?: string;
|
|
142
|
+
method?: string;
|
|
143
|
+
statusCode?: number;
|
|
144
|
+
extra?: Record<string, string>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Captura um erro e envia pro monitor.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* try {
|
|
152
|
+
* await riskyOperation()
|
|
153
|
+
* } catch (err) {
|
|
154
|
+
* captureError(monitor, err, { route: '/api/users' })
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
declare function captureError(monitor: MonitorClient, error: unknown, context?: CaptureContext): void;
|
|
159
|
+
/**
|
|
160
|
+
* Registra handlers globais para erros não capturados.
|
|
161
|
+
* Só funciona no browser — no servidor, NÃO interceptamos uncaughtException
|
|
162
|
+
* (perigoso para um SDK de monitoring).
|
|
163
|
+
*
|
|
164
|
+
* @returns Função de cleanup que remove os handlers
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const cleanup = setupGlobalHandlers(monitor)
|
|
169
|
+
* // Quando quiser parar:
|
|
170
|
+
* cleanup()
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function setupGlobalHandlers(monitor: MonitorClient): () => void;
|
|
174
|
+
|
|
70
175
|
/**
|
|
71
176
|
* Cria e inicia uma instância do monitor.
|
|
72
177
|
*
|
|
@@ -77,10 +182,10 @@ declare class MonitorClient {
|
|
|
77
182
|
* export const monitor = createMonitor({
|
|
78
183
|
* projectId: 'uuid-do-projeto',
|
|
79
184
|
* apiKey: 'nuvio_mon_xxxxxxxx',
|
|
80
|
-
* endpoint: 'https://
|
|
185
|
+
* endpoint: 'https://nuvio.app/api/monitor/ingest',
|
|
81
186
|
* })
|
|
82
187
|
* ```
|
|
83
188
|
*/
|
|
84
189
|
declare function createMonitor(config: MonitorConfig): MonitorClient;
|
|
85
190
|
|
|
86
|
-
export { MonitorClient, type MonitorConfig, createMonitor };
|
|
191
|
+
export { type AdapterData, type BeforeSendHook, type DeployData, type ErrorData, type HeartbeatData, MonitorClient, type MonitorConfig, type MonitorEvent, type MonitorEventInput, type MonitorEventType, type RequestData, type VitalData, captureError, createMonitor, setupGlobalHandlers };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,177 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
timestamp: string;
|
|
1
|
+
interface HeartbeatData {
|
|
2
|
+
status: 'online' | 'offline';
|
|
3
|
+
latencyMs: number;
|
|
5
4
|
}
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
interface RequestData {
|
|
6
|
+
method: string;
|
|
7
|
+
route: string;
|
|
8
|
+
statusCode: number;
|
|
9
|
+
responseTimeMs: number;
|
|
10
|
+
userAgent?: string;
|
|
11
|
+
region?: string;
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
interface VitalData {
|
|
14
|
+
name: 'LCP' | 'INP' | 'CLS' | 'FCP' | 'TTFB';
|
|
15
|
+
value: number;
|
|
16
|
+
rating: 'good' | 'needs-improvement' | 'poor';
|
|
17
|
+
page?: string;
|
|
18
|
+
deviceType?: string;
|
|
19
|
+
browser?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ErrorData {
|
|
22
|
+
type: 'unhandled' | 'caught' | 'promise';
|
|
23
|
+
message: string;
|
|
24
|
+
stack?: string;
|
|
25
|
+
groupingKey: string;
|
|
26
|
+
route?: string;
|
|
27
|
+
method?: string;
|
|
28
|
+
statusCode?: number;
|
|
29
|
+
environment?: string;
|
|
30
|
+
commitHash?: string;
|
|
31
|
+
extra?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
interface DeployData {
|
|
34
|
+
commitHash: string;
|
|
35
|
+
branch?: string;
|
|
36
|
+
author?: string;
|
|
37
|
+
status: 'started' | 'succeeded' | 'failed';
|
|
38
|
+
buildDurationMs?: number;
|
|
39
|
+
url?: string;
|
|
40
|
+
environment?: string;
|
|
41
|
+
provider?: string;
|
|
21
42
|
}
|
|
43
|
+
interface AdapterData {
|
|
44
|
+
adapter: string;
|
|
45
|
+
operation: string;
|
|
46
|
+
durationMs: number;
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
meta?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
type MonitorEvent = {
|
|
52
|
+
type: 'heartbeat';
|
|
53
|
+
data: HeartbeatData;
|
|
54
|
+
timestamp: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'request';
|
|
57
|
+
data: RequestData;
|
|
58
|
+
timestamp: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'vital';
|
|
61
|
+
data: VitalData;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'error';
|
|
65
|
+
data: ErrorData;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'deploy';
|
|
69
|
+
data: DeployData;
|
|
70
|
+
timestamp: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'adapter';
|
|
73
|
+
data: AdapterData;
|
|
74
|
+
timestamp: string;
|
|
75
|
+
};
|
|
76
|
+
type MonitorEventType = MonitorEvent['type'];
|
|
77
|
+
/** Evento sem timestamp — usado pelo collector ao receber do client */
|
|
78
|
+
type MonitorEventInput = Omit<MonitorEvent, 'timestamp'>;
|
|
79
|
+
/** Hook para filtrar/modificar eventos antes do envio */
|
|
80
|
+
type BeforeSendHook = (event: MonitorEvent) => MonitorEvent | null;
|
|
22
81
|
|
|
23
82
|
interface MonitorConfig {
|
|
24
83
|
/** ID do projeto no Nuvio */
|
|
25
84
|
projectId: string;
|
|
26
85
|
/** API key gerada no Nuvio */
|
|
27
86
|
apiKey: string;
|
|
28
|
-
/** URL do endpoint de ingest
|
|
87
|
+
/** URL do endpoint de ingest */
|
|
29
88
|
endpoint: string;
|
|
30
89
|
/** Intervalo do heartbeat em ms (default: 60000) */
|
|
31
90
|
heartbeatInterval?: number;
|
|
32
91
|
/** Intervalo do flush do buffer em ms (default: 30000) */
|
|
33
92
|
flushInterval?: number;
|
|
93
|
+
/** Timeout do fetch em ms (default: 10000) */
|
|
94
|
+
timeout?: number;
|
|
95
|
+
/** Max tentativas de retry (default: 3) */
|
|
96
|
+
maxRetries?: number;
|
|
34
97
|
/** Desabilitar em desenvolvimento (default: true) */
|
|
35
98
|
disableInDev?: boolean;
|
|
99
|
+
/** Taxa de amostragem 0.0-1.0 (default: 1.0). Heartbeats nunca são amostrados */
|
|
100
|
+
sampleRate?: number;
|
|
101
|
+
/** Hook chamado antes de enfileirar cada evento. Retorna null para dropar */
|
|
102
|
+
beforeSend?: BeforeSendHook;
|
|
103
|
+
/** Habilitar logs de debug no console (default: false) */
|
|
104
|
+
debug?: boolean;
|
|
105
|
+
/** Capturar erros globais automaticamente — window.onerror (default: false) */
|
|
106
|
+
captureErrors?: boolean;
|
|
107
|
+
/** Capturar unhandled promise rejections automaticamente (default: false) */
|
|
108
|
+
captureUnhandledRejections?: boolean;
|
|
36
109
|
}
|
|
37
110
|
declare class MonitorClient {
|
|
38
111
|
readonly config: MonitorConfig;
|
|
39
|
-
readonly collector
|
|
112
|
+
private readonly collector;
|
|
113
|
+
private readonly logger;
|
|
40
114
|
private heartbeatTimer;
|
|
115
|
+
private globalHandlersCleanup;
|
|
41
116
|
private active;
|
|
42
117
|
constructor(config: MonitorConfig);
|
|
43
118
|
/** Inicia o monitoring (heartbeat + collector) */
|
|
44
119
|
start(): void;
|
|
45
120
|
/** Para o monitoring */
|
|
46
121
|
stop(): void;
|
|
122
|
+
/** Força um flush imediato do buffer */
|
|
123
|
+
flush(): void;
|
|
124
|
+
/** Verifica se o monitoring está ativo */
|
|
125
|
+
get isActive(): boolean;
|
|
47
126
|
/** Registra um evento de request HTTP (usado pelo middleware) */
|
|
48
|
-
trackRequest(data:
|
|
49
|
-
method: string;
|
|
50
|
-
route: string;
|
|
51
|
-
statusCode: number;
|
|
52
|
-
responseTimeMs: number;
|
|
53
|
-
userAgent?: string;
|
|
54
|
-
region?: string;
|
|
55
|
-
}): void;
|
|
127
|
+
trackRequest(data: RequestData): void;
|
|
56
128
|
/** Registra um Web Vital (usado pelo MonitorScript) */
|
|
57
|
-
trackVital(data:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}): void;
|
|
129
|
+
trackVital(data: VitalData): void;
|
|
130
|
+
/** Registra um evento de adapter (DB, cache, AI, queue, email) */
|
|
131
|
+
trackAdapter(data: AdapterData): void;
|
|
132
|
+
/** Registra um erro capturado */
|
|
133
|
+
captureError(data: ErrorData): void;
|
|
134
|
+
/** Registra um evento de deploy */
|
|
135
|
+
trackDeploy(data: DeployData): void;
|
|
65
136
|
private startHeartbeat;
|
|
66
137
|
private sendHeartbeat;
|
|
67
|
-
private isDev;
|
|
68
138
|
}
|
|
69
139
|
|
|
140
|
+
interface CaptureContext {
|
|
141
|
+
route?: string;
|
|
142
|
+
method?: string;
|
|
143
|
+
statusCode?: number;
|
|
144
|
+
extra?: Record<string, string>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Captura um erro e envia pro monitor.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* try {
|
|
152
|
+
* await riskyOperation()
|
|
153
|
+
* } catch (err) {
|
|
154
|
+
* captureError(monitor, err, { route: '/api/users' })
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
declare function captureError(monitor: MonitorClient, error: unknown, context?: CaptureContext): void;
|
|
159
|
+
/**
|
|
160
|
+
* Registra handlers globais para erros não capturados.
|
|
161
|
+
* Só funciona no browser — no servidor, NÃO interceptamos uncaughtException
|
|
162
|
+
* (perigoso para um SDK de monitoring).
|
|
163
|
+
*
|
|
164
|
+
* @returns Função de cleanup que remove os handlers
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const cleanup = setupGlobalHandlers(monitor)
|
|
169
|
+
* // Quando quiser parar:
|
|
170
|
+
* cleanup()
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function setupGlobalHandlers(monitor: MonitorClient): () => void;
|
|
174
|
+
|
|
70
175
|
/**
|
|
71
176
|
* Cria e inicia uma instância do monitor.
|
|
72
177
|
*
|
|
@@ -77,10 +182,10 @@ declare class MonitorClient {
|
|
|
77
182
|
* export const monitor = createMonitor({
|
|
78
183
|
* projectId: 'uuid-do-projeto',
|
|
79
184
|
* apiKey: 'nuvio_mon_xxxxxxxx',
|
|
80
|
-
* endpoint: 'https://
|
|
185
|
+
* endpoint: 'https://nuvio.app/api/monitor/ingest',
|
|
81
186
|
* })
|
|
82
187
|
* ```
|
|
83
188
|
*/
|
|
84
189
|
declare function createMonitor(config: MonitorConfig): MonitorClient;
|
|
85
190
|
|
|
86
|
-
export { MonitorClient, type MonitorConfig, createMonitor };
|
|
191
|
+
export { type AdapterData, type BeforeSendHook, type DeployData, type ErrorData, type HeartbeatData, MonitorClient, type MonitorConfig, type MonitorEvent, type MonitorEventInput, type MonitorEventType, type RequestData, type VitalData, captureError, createMonitor, setupGlobalHandlers };
|