vedatrace 0.1.0 → 0.1.5
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 +20 -0
- package/dist/index.cjs +26 -5
- package/dist/index.d.cts +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +26 -5
- package/dist/integrations/express.d.cts +1 -1
- package/dist/integrations/express.d.mts +1 -1
- package/dist/integrations/nextjs.d.cts +1 -1
- package/dist/integrations/nextjs.d.mts +1 -1
- package/dist/integrations/react.d.cts +1 -1
- package/dist/integrations/react.d.mts +1 -1
- package/dist/transports/index.cjs +8 -1
- package/dist/transports/index.d.cts +3 -3
- package/dist/transports/index.d.mts +3 -3
- package/dist/transports/index.mjs +8 -1
- package/dist/{types-wnAhugbp.d.cts → types-CGtcllp9.d.cts} +5 -1
- package/dist/{types-wnAhugbp.d.mts → types-CGtcllp9.d.mts} +5 -1
- package/package.json +13 -5
package/README.md
CHANGED
|
@@ -223,6 +223,22 @@ app.post('/webhook', async (req, res) => {
|
|
|
223
223
|
})
|
|
224
224
|
```
|
|
225
225
|
|
|
226
|
+
### Graceful Shutdown
|
|
227
|
+
|
|
228
|
+
The SDK uses background batching that doesn't block your app. For short-lived scripts or when you need explicit cleanup:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const logger = vedatrace({ apiKey: '...' })
|
|
232
|
+
|
|
233
|
+
logger.info('Processing...')
|
|
234
|
+
|
|
235
|
+
// For short-lived scripts
|
|
236
|
+
await logger.flush()
|
|
237
|
+
logger.stop() // Stop background timer
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The SDK timer uses `unref()` so the process will exit automatically when there's nothing else to do. Call `stop()` if you need explicit cleanup.
|
|
241
|
+
|
|
226
242
|
### Error Handling
|
|
227
243
|
|
|
228
244
|
```typescript
|
|
@@ -288,6 +304,10 @@ Create a child logger with default metadata.
|
|
|
288
304
|
|
|
289
305
|
Manually flush pending logs. Returns a Promise.
|
|
290
306
|
|
|
307
|
+
### `logger.stop()`
|
|
308
|
+
|
|
309
|
+
Stop the background flush timer. Call this for explicit cleanup in long-running processes or before shutdown.
|
|
310
|
+
|
|
291
311
|
## License
|
|
292
312
|
|
|
293
313
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -5,11 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var transports_index = require('./transports/index.cjs');
|
|
6
6
|
|
|
7
7
|
class VedaTraceBatcher {
|
|
8
|
-
constructor(transports, config, onError, onSuccess) {
|
|
8
|
+
constructor(transports, config, onError, onSuccess, immediateFlush = false) {
|
|
9
9
|
this.transports = transports;
|
|
10
10
|
this.config = config;
|
|
11
11
|
this.onError = onError;
|
|
12
12
|
this.onSuccess = onSuccess;
|
|
13
|
+
this.immediateFlush = immediateFlush;
|
|
13
14
|
this.startFlushTimer();
|
|
14
15
|
}
|
|
15
16
|
queue = [];
|
|
@@ -19,7 +20,7 @@ class VedaTraceBatcher {
|
|
|
19
20
|
/** Add log to queue */
|
|
20
21
|
add(log) {
|
|
21
22
|
this.queue.push(log);
|
|
22
|
-
if (this.queue.length >= this.config.batchSize) {
|
|
23
|
+
if (this.immediateFlush || this.queue.length >= this.config.batchSize) {
|
|
23
24
|
this.flush();
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -73,6 +74,9 @@ class VedaTraceBatcher {
|
|
|
73
74
|
this.flush();
|
|
74
75
|
}
|
|
75
76
|
}, this.config.flushInterval);
|
|
77
|
+
if (this.config.unrefTimer !== false) {
|
|
78
|
+
this.flushTimer.unref();
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
/** Stop the flush timer */
|
|
78
82
|
stop() {
|
|
@@ -109,7 +113,8 @@ class VedaTraceLogger {
|
|
|
109
113
|
retryDelay: config.retryDelay ?? 1e3,
|
|
110
114
|
onError: config.onError,
|
|
111
115
|
onSuccess: config.onSuccess,
|
|
112
|
-
debug: config.debug ?? false
|
|
116
|
+
debug: config.debug ?? false,
|
|
117
|
+
immediateFlush: config.immediateFlush ?? false
|
|
113
118
|
};
|
|
114
119
|
if (!config.disabled) {
|
|
115
120
|
this.initializeBatcher(config);
|
|
@@ -129,7 +134,8 @@ class VedaTraceLogger {
|
|
|
129
134
|
retryDelay: this.config.retryDelay
|
|
130
135
|
},
|
|
131
136
|
this.config.onError,
|
|
132
|
-
this.config.onSuccess
|
|
137
|
+
this.config.onSuccess,
|
|
138
|
+
this.config.immediateFlush
|
|
133
139
|
);
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -209,6 +215,12 @@ class VedaTraceLogger {
|
|
|
209
215
|
await this.batcher.flush();
|
|
210
216
|
}
|
|
211
217
|
}
|
|
218
|
+
/** Stop the batcher and flush timer */
|
|
219
|
+
stop() {
|
|
220
|
+
if (this.batcher) {
|
|
221
|
+
this.batcher.stop();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
212
224
|
/** Detect runtime environment */
|
|
213
225
|
detectEnvironment() {
|
|
214
226
|
if (typeof globalThis !== "undefined" && "navigator" in globalThis) {
|
|
@@ -305,7 +317,7 @@ function vedatrace(config = {}) {
|
|
|
305
317
|
[httpTransport],
|
|
306
318
|
{
|
|
307
319
|
batchSize: config.batchSize ?? 100,
|
|
308
|
-
flushInterval: config.flushInterval ??
|
|
320
|
+
flushInterval: config.flushInterval ?? 1e3,
|
|
309
321
|
maxRetries: config.maxRetries ?? 3,
|
|
310
322
|
retryDelay: config.retryDelay ?? 1e3
|
|
311
323
|
},
|
|
@@ -313,12 +325,21 @@ function vedatrace(config = {}) {
|
|
|
313
325
|
config.onSuccess
|
|
314
326
|
);
|
|
315
327
|
logger.setBatcher(batcher);
|
|
328
|
+
if (typeof process !== "undefined") {
|
|
329
|
+
const flushLogs = async () => {
|
|
330
|
+
await batcher.flush();
|
|
331
|
+
};
|
|
332
|
+
process.on("beforeExit", flushLogs);
|
|
333
|
+
process.on("SIGTERM", flushLogs);
|
|
334
|
+
process.on("SIGINT", flushLogs);
|
|
335
|
+
}
|
|
316
336
|
}
|
|
317
337
|
return logger;
|
|
318
338
|
}
|
|
319
339
|
function devVedatrace(config = {}) {
|
|
320
340
|
return vedatrace({
|
|
321
341
|
...config,
|
|
342
|
+
immediateFlush: true,
|
|
322
343
|
transports: [
|
|
323
344
|
new transports_index.VedaTraceConsoleTransport({
|
|
324
345
|
format: "pretty",
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as VedaTraceTransport, B as BatcherConfig, I as InternalLogEntry, V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata, R as RedactionConfig } from './types-
|
|
2
|
-
export { c as VedaTraceLevel, d as VedaTraceLog } from './types-
|
|
1
|
+
import { b as VedaTraceTransport, B as BatcherConfig, I as InternalLogEntry, V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata, R as RedactionConfig } from './types-CGtcllp9.cjs';
|
|
2
|
+
export { c as VedaTraceLevel, d as VedaTraceLog } from './types-CGtcllp9.cjs';
|
|
3
3
|
export { ConsoleFormat, ConsoleTransportConfig, HttpTransportConfig, VedaTraceConsoleTransport, VedaTraceHttpTransport } from './transports/index.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,11 +12,12 @@ declare class VedaTraceBatcher {
|
|
|
12
12
|
private config;
|
|
13
13
|
private onError?;
|
|
14
14
|
private onSuccess?;
|
|
15
|
+
private immediateFlush;
|
|
15
16
|
private queue;
|
|
16
17
|
private flushTimer;
|
|
17
18
|
private isFlushing;
|
|
18
19
|
private pendingFlush;
|
|
19
|
-
constructor(transports: VedaTraceTransport[], config: BatcherConfig, onError?: ((error: Error) => void) | undefined, onSuccess?: (() => void) | undefined);
|
|
20
|
+
constructor(transports: VedaTraceTransport[], config: BatcherConfig, onError?: ((error: Error) => void) | undefined, onSuccess?: (() => void) | undefined, immediateFlush?: boolean);
|
|
20
21
|
/** Add log to queue */
|
|
21
22
|
add(log: InternalLogEntry): void;
|
|
22
23
|
/** Flush logs to all transports */
|
|
@@ -62,6 +63,8 @@ declare class VedaTraceLogger implements VedaTraceLoggerInterface {
|
|
|
62
63
|
child(defaults: LogMetadata): VedaTraceLoggerInterface;
|
|
63
64
|
/** Flush pending logs */
|
|
64
65
|
flush(): Promise<void>;
|
|
66
|
+
/** Stop the batcher and flush timer */
|
|
67
|
+
stop(): void;
|
|
65
68
|
/** Detect runtime environment */
|
|
66
69
|
private detectEnvironment;
|
|
67
70
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as VedaTraceTransport, B as BatcherConfig, I as InternalLogEntry, V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata, R as RedactionConfig } from './types-
|
|
2
|
-
export { c as VedaTraceLevel, d as VedaTraceLog } from './types-
|
|
1
|
+
import { b as VedaTraceTransport, B as BatcherConfig, I as InternalLogEntry, V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata, R as RedactionConfig } from './types-CGtcllp9.mjs';
|
|
2
|
+
export { c as VedaTraceLevel, d as VedaTraceLog } from './types-CGtcllp9.mjs';
|
|
3
3
|
export { ConsoleFormat, ConsoleTransportConfig, HttpTransportConfig, VedaTraceConsoleTransport, VedaTraceHttpTransport } from './transports/index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,11 +12,12 @@ declare class VedaTraceBatcher {
|
|
|
12
12
|
private config;
|
|
13
13
|
private onError?;
|
|
14
14
|
private onSuccess?;
|
|
15
|
+
private immediateFlush;
|
|
15
16
|
private queue;
|
|
16
17
|
private flushTimer;
|
|
17
18
|
private isFlushing;
|
|
18
19
|
private pendingFlush;
|
|
19
|
-
constructor(transports: VedaTraceTransport[], config: BatcherConfig, onError?: ((error: Error) => void) | undefined, onSuccess?: (() => void) | undefined);
|
|
20
|
+
constructor(transports: VedaTraceTransport[], config: BatcherConfig, onError?: ((error: Error) => void) | undefined, onSuccess?: (() => void) | undefined, immediateFlush?: boolean);
|
|
20
21
|
/** Add log to queue */
|
|
21
22
|
add(log: InternalLogEntry): void;
|
|
22
23
|
/** Flush logs to all transports */
|
|
@@ -62,6 +63,8 @@ declare class VedaTraceLogger implements VedaTraceLoggerInterface {
|
|
|
62
63
|
child(defaults: LogMetadata): VedaTraceLoggerInterface;
|
|
63
64
|
/** Flush pending logs */
|
|
64
65
|
flush(): Promise<void>;
|
|
66
|
+
/** Stop the batcher and flush timer */
|
|
67
|
+
stop(): void;
|
|
65
68
|
/** Detect runtime environment */
|
|
66
69
|
private detectEnvironment;
|
|
67
70
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { VedaTraceHttpTransport, VedaTraceConsoleTransport } from './transports/index.mjs';
|
|
2
2
|
|
|
3
3
|
class VedaTraceBatcher {
|
|
4
|
-
constructor(transports, config, onError, onSuccess) {
|
|
4
|
+
constructor(transports, config, onError, onSuccess, immediateFlush = false) {
|
|
5
5
|
this.transports = transports;
|
|
6
6
|
this.config = config;
|
|
7
7
|
this.onError = onError;
|
|
8
8
|
this.onSuccess = onSuccess;
|
|
9
|
+
this.immediateFlush = immediateFlush;
|
|
9
10
|
this.startFlushTimer();
|
|
10
11
|
}
|
|
11
12
|
queue = [];
|
|
@@ -15,7 +16,7 @@ class VedaTraceBatcher {
|
|
|
15
16
|
/** Add log to queue */
|
|
16
17
|
add(log) {
|
|
17
18
|
this.queue.push(log);
|
|
18
|
-
if (this.queue.length >= this.config.batchSize) {
|
|
19
|
+
if (this.immediateFlush || this.queue.length >= this.config.batchSize) {
|
|
19
20
|
this.flush();
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -69,6 +70,9 @@ class VedaTraceBatcher {
|
|
|
69
70
|
this.flush();
|
|
70
71
|
}
|
|
71
72
|
}, this.config.flushInterval);
|
|
73
|
+
if (this.config.unrefTimer !== false) {
|
|
74
|
+
this.flushTimer.unref();
|
|
75
|
+
}
|
|
72
76
|
}
|
|
73
77
|
/** Stop the flush timer */
|
|
74
78
|
stop() {
|
|
@@ -105,7 +109,8 @@ class VedaTraceLogger {
|
|
|
105
109
|
retryDelay: config.retryDelay ?? 1e3,
|
|
106
110
|
onError: config.onError,
|
|
107
111
|
onSuccess: config.onSuccess,
|
|
108
|
-
debug: config.debug ?? false
|
|
112
|
+
debug: config.debug ?? false,
|
|
113
|
+
immediateFlush: config.immediateFlush ?? false
|
|
109
114
|
};
|
|
110
115
|
if (!config.disabled) {
|
|
111
116
|
this.initializeBatcher(config);
|
|
@@ -125,7 +130,8 @@ class VedaTraceLogger {
|
|
|
125
130
|
retryDelay: this.config.retryDelay
|
|
126
131
|
},
|
|
127
132
|
this.config.onError,
|
|
128
|
-
this.config.onSuccess
|
|
133
|
+
this.config.onSuccess,
|
|
134
|
+
this.config.immediateFlush
|
|
129
135
|
);
|
|
130
136
|
}
|
|
131
137
|
}
|
|
@@ -205,6 +211,12 @@ class VedaTraceLogger {
|
|
|
205
211
|
await this.batcher.flush();
|
|
206
212
|
}
|
|
207
213
|
}
|
|
214
|
+
/** Stop the batcher and flush timer */
|
|
215
|
+
stop() {
|
|
216
|
+
if (this.batcher) {
|
|
217
|
+
this.batcher.stop();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
208
220
|
/** Detect runtime environment */
|
|
209
221
|
detectEnvironment() {
|
|
210
222
|
if (typeof globalThis !== "undefined" && "navigator" in globalThis) {
|
|
@@ -301,7 +313,7 @@ function vedatrace(config = {}) {
|
|
|
301
313
|
[httpTransport],
|
|
302
314
|
{
|
|
303
315
|
batchSize: config.batchSize ?? 100,
|
|
304
|
-
flushInterval: config.flushInterval ??
|
|
316
|
+
flushInterval: config.flushInterval ?? 1e3,
|
|
305
317
|
maxRetries: config.maxRetries ?? 3,
|
|
306
318
|
retryDelay: config.retryDelay ?? 1e3
|
|
307
319
|
},
|
|
@@ -309,12 +321,21 @@ function vedatrace(config = {}) {
|
|
|
309
321
|
config.onSuccess
|
|
310
322
|
);
|
|
311
323
|
logger.setBatcher(batcher);
|
|
324
|
+
if (typeof process !== "undefined") {
|
|
325
|
+
const flushLogs = async () => {
|
|
326
|
+
await batcher.flush();
|
|
327
|
+
};
|
|
328
|
+
process.on("beforeExit", flushLogs);
|
|
329
|
+
process.on("SIGTERM", flushLogs);
|
|
330
|
+
process.on("SIGINT", flushLogs);
|
|
331
|
+
}
|
|
312
332
|
}
|
|
313
333
|
return logger;
|
|
314
334
|
}
|
|
315
335
|
function devVedatrace(config = {}) {
|
|
316
336
|
return vedatrace({
|
|
317
337
|
...config,
|
|
338
|
+
immediateFlush: true,
|
|
318
339
|
transports: [
|
|
319
340
|
new VedaTraceConsoleTransport({
|
|
320
341
|
format: "pretty",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import { V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata } from '../types-
|
|
2
|
+
import { V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata } from '../types-CGtcllp9.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Express.js middleware integration for VedaTrace
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import { V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata } from '../types-
|
|
2
|
+
import { V as VedaTraceLoggerInterface, a as VedaTraceConfig, L as LogMetadata } from '../types-CGtcllp9.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Express.js middleware integration for VedaTrace
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-
|
|
2
|
+
import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-CGtcllp9.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React integration for VedaTrace
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-
|
|
2
|
+
import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-CGtcllp9.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React integration for VedaTrace
|
|
@@ -92,6 +92,13 @@ class VedaTraceHttpTransport {
|
|
|
92
92
|
async send(logs) {
|
|
93
93
|
const controller = new AbortController();
|
|
94
94
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
95
|
+
const payload = logs.map((log) => ({
|
|
96
|
+
level: log.level,
|
|
97
|
+
message: log.message,
|
|
98
|
+
service: log.service,
|
|
99
|
+
timestamp: log.timestamp ? new Date(log.timestamp).toISOString() : void 0,
|
|
100
|
+
metadata: log.metadata
|
|
101
|
+
}));
|
|
95
102
|
try {
|
|
96
103
|
const response = await fetch(this.endpoint, {
|
|
97
104
|
method: "POST",
|
|
@@ -100,7 +107,7 @@ class VedaTraceHttpTransport {
|
|
|
100
107
|
"X-API-Key": this.apiKey,
|
|
101
108
|
...this.headers
|
|
102
109
|
},
|
|
103
|
-
body: JSON.stringify(
|
|
110
|
+
body: JSON.stringify(payload),
|
|
104
111
|
signal: controller.signal
|
|
105
112
|
});
|
|
106
113
|
clearTimeout(timeoutId);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as VedaTraceLevel, b as VedaTraceTransport,
|
|
1
|
+
import { c as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CGtcllp9.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Console transport for development/debugging
|
|
@@ -20,7 +20,7 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
|
|
|
20
20
|
private minLevel;
|
|
21
21
|
constructor(config?: ConsoleTransportConfig);
|
|
22
22
|
/** Send logs to console */
|
|
23
|
-
send(logs:
|
|
23
|
+
send(logs: InternalLogEntry[]): void;
|
|
24
24
|
/** Format as JSON */
|
|
25
25
|
private logJson;
|
|
26
26
|
/** Format as simple text */
|
|
@@ -51,7 +51,7 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
51
51
|
private headers;
|
|
52
52
|
constructor(config: HttpTransportConfig);
|
|
53
53
|
/** Send logs via HTTP POST */
|
|
54
|
-
send(logs:
|
|
54
|
+
send(logs: InternalLogEntry[]): Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export { VedaTraceConsoleTransport, VedaTraceHttpTransport };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as VedaTraceLevel, b as VedaTraceTransport,
|
|
1
|
+
import { c as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CGtcllp9.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Console transport for development/debugging
|
|
@@ -20,7 +20,7 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
|
|
|
20
20
|
private minLevel;
|
|
21
21
|
constructor(config?: ConsoleTransportConfig);
|
|
22
22
|
/** Send logs to console */
|
|
23
|
-
send(logs:
|
|
23
|
+
send(logs: InternalLogEntry[]): void;
|
|
24
24
|
/** Format as JSON */
|
|
25
25
|
private logJson;
|
|
26
26
|
/** Format as simple text */
|
|
@@ -51,7 +51,7 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
51
51
|
private headers;
|
|
52
52
|
constructor(config: HttpTransportConfig);
|
|
53
53
|
/** Send logs via HTTP POST */
|
|
54
|
-
send(logs:
|
|
54
|
+
send(logs: InternalLogEntry[]): Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export { VedaTraceConsoleTransport, VedaTraceHttpTransport };
|
|
@@ -90,6 +90,13 @@ class VedaTraceHttpTransport {
|
|
|
90
90
|
async send(logs) {
|
|
91
91
|
const controller = new AbortController();
|
|
92
92
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
93
|
+
const payload = logs.map((log) => ({
|
|
94
|
+
level: log.level,
|
|
95
|
+
message: log.message,
|
|
96
|
+
service: log.service,
|
|
97
|
+
timestamp: log.timestamp ? new Date(log.timestamp).toISOString() : void 0,
|
|
98
|
+
metadata: log.metadata
|
|
99
|
+
}));
|
|
93
100
|
try {
|
|
94
101
|
const response = await fetch(this.endpoint, {
|
|
95
102
|
method: "POST",
|
|
@@ -98,7 +105,7 @@ class VedaTraceHttpTransport {
|
|
|
98
105
|
"X-API-Key": this.apiKey,
|
|
99
106
|
...this.headers
|
|
100
107
|
},
|
|
101
|
-
body: JSON.stringify(
|
|
108
|
+
body: JSON.stringify(payload),
|
|
102
109
|
signal: controller.signal
|
|
103
110
|
});
|
|
104
111
|
clearTimeout(timeoutId);
|
|
@@ -47,6 +47,8 @@ interface VedaTraceConfig {
|
|
|
47
47
|
disabled?: boolean;
|
|
48
48
|
/** Enable debug mode (verbose console output) */
|
|
49
49
|
debug?: boolean;
|
|
50
|
+
/** Flush immediately after each log (for console/dev mode) */
|
|
51
|
+
immediateFlush?: boolean;
|
|
50
52
|
}
|
|
51
53
|
/** Redaction configuration */
|
|
52
54
|
interface RedactionConfig {
|
|
@@ -62,7 +64,7 @@ interface VedaTraceTransport {
|
|
|
62
64
|
/** Transport name */
|
|
63
65
|
name: string;
|
|
64
66
|
/** Send logs to destination */
|
|
65
|
-
send(logs:
|
|
67
|
+
send(logs: InternalLogEntry[]): Promise<void> | void;
|
|
66
68
|
/** Flush any pending logs */
|
|
67
69
|
flush?(): Promise<void>;
|
|
68
70
|
}
|
|
@@ -96,6 +98,7 @@ interface BatcherConfig {
|
|
|
96
98
|
flushInterval: number;
|
|
97
99
|
maxRetries: number;
|
|
98
100
|
retryDelay: number;
|
|
101
|
+
unrefTimer?: boolean;
|
|
99
102
|
}
|
|
100
103
|
/** Logger interface */
|
|
101
104
|
interface VedaTraceLoggerInterface {
|
|
@@ -106,6 +109,7 @@ interface VedaTraceLoggerInterface {
|
|
|
106
109
|
fatal(message: string | Error, metadata?: LogMetadata): void;
|
|
107
110
|
child(defaults: LogMetadata): VedaTraceLoggerInterface;
|
|
108
111
|
flush(): Promise<void>;
|
|
112
|
+
stop(): void;
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RedactionConfig as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceLevel as c, VedaTraceLog as d };
|
|
@@ -47,6 +47,8 @@ interface VedaTraceConfig {
|
|
|
47
47
|
disabled?: boolean;
|
|
48
48
|
/** Enable debug mode (verbose console output) */
|
|
49
49
|
debug?: boolean;
|
|
50
|
+
/** Flush immediately after each log (for console/dev mode) */
|
|
51
|
+
immediateFlush?: boolean;
|
|
50
52
|
}
|
|
51
53
|
/** Redaction configuration */
|
|
52
54
|
interface RedactionConfig {
|
|
@@ -62,7 +64,7 @@ interface VedaTraceTransport {
|
|
|
62
64
|
/** Transport name */
|
|
63
65
|
name: string;
|
|
64
66
|
/** Send logs to destination */
|
|
65
|
-
send(logs:
|
|
67
|
+
send(logs: InternalLogEntry[]): Promise<void> | void;
|
|
66
68
|
/** Flush any pending logs */
|
|
67
69
|
flush?(): Promise<void>;
|
|
68
70
|
}
|
|
@@ -96,6 +98,7 @@ interface BatcherConfig {
|
|
|
96
98
|
flushInterval: number;
|
|
97
99
|
maxRetries: number;
|
|
98
100
|
retryDelay: number;
|
|
101
|
+
unrefTimer?: boolean;
|
|
99
102
|
}
|
|
100
103
|
/** Logger interface */
|
|
101
104
|
interface VedaTraceLoggerInterface {
|
|
@@ -106,6 +109,7 @@ interface VedaTraceLoggerInterface {
|
|
|
106
109
|
fatal(message: string | Error, metadata?: LogMetadata): void;
|
|
107
110
|
child(defaults: LogMetadata): VedaTraceLoggerInterface;
|
|
108
111
|
flush(): Promise<void>;
|
|
112
|
+
stop(): void;
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
export type { BatcherConfig as B, InternalLogEntry as I, LogMetadata as L, RedactionConfig as R, VedaTraceLoggerInterface as V, VedaTraceConfig as a, VedaTraceTransport as b, VedaTraceLevel as c, VedaTraceLog as d };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vedatrace",
|
|
3
3
|
"description": "Universal JavaScript logging SDK for VedaTrace - type-safe, lightweight, and developer-friendly",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"setup": "rm -rf node_modules && npm i && git init && husky",
|
|
7
7
|
"prepublishOnly": "npm run build",
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
"version": "changeset version",
|
|
13
13
|
"release": "bun run build && changeset publish",
|
|
14
14
|
"ci:version": "changeset version",
|
|
15
|
-
"ci:publish": "bun run build && changeset publish"
|
|
15
|
+
"ci:publish": "bun run build && changeset publish --provenance"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"provenance": true,
|
|
19
|
+
"access": "public"
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
|
18
22
|
"dist"
|
|
@@ -125,11 +129,15 @@
|
|
|
125
129
|
},
|
|
126
130
|
"repository": {
|
|
127
131
|
"type": "git",
|
|
128
|
-
"url": "git+https://github.com/
|
|
132
|
+
"url": "git+https://github.com/kurtiz/vedatrace-npm.git"
|
|
129
133
|
},
|
|
130
134
|
"bugs": {
|
|
131
|
-
"url": "https://github.com/
|
|
135
|
+
"url": "https://github.com/kurtiz/vedatrace-npm/issues"
|
|
136
|
+
},
|
|
137
|
+
"author": {
|
|
138
|
+
"name": "Aaron Will Djaba",
|
|
139
|
+
"email": "aaronwilldjaba@outlook.com",
|
|
140
|
+
"url": "https://iamaaronwilldjaba.me"
|
|
132
141
|
},
|
|
133
|
-
"author": "VedaTrace",
|
|
134
142
|
"license": "MIT"
|
|
135
143
|
}
|