vedatrace 0.3.0 → 0.3.1
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 +53 -7
- package/dist/index-BcBZY8as.mjs +231 -0
- package/dist/index-osD28Hs0.cjs +239 -0
- package/dist/index.cjs +95 -96
- package/dist/index.d.cts +72 -20
- package/dist/index.d.mts +72 -20
- package/dist/index.mjs +95 -97
- package/dist/integrations/express.cjs +3 -4
- package/dist/integrations/express.mjs +3 -4
- package/dist/integrations/nextjs.cjs +31 -5
- package/dist/integrations/nextjs.d.cts +6 -14
- package/dist/integrations/nextjs.d.mts +6 -14
- package/dist/integrations/nextjs.mjs +31 -6
- package/dist/integrations/react.cjs +1 -1
- package/dist/integrations/react.mjs +1 -1
- package/dist/transports/index.cjs +5 -153
- package/dist/transports/index.d.cts +15 -5
- package/dist/transports/index.d.mts +15 -5
- package/dist/transports/index.mjs +1 -153
- package/package.json +150 -141
|
@@ -1,157 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
debug: "\x1B[36m",
|
|
5
|
-
// cyan
|
|
6
|
-
info: "\x1B[32m",
|
|
7
|
-
// green
|
|
8
|
-
warn: "\x1B[33m",
|
|
9
|
-
// yellow
|
|
10
|
-
error: "\x1B[31m",
|
|
11
|
-
// red
|
|
12
|
-
fatal: "\x1B[35m"
|
|
13
|
-
// magenta
|
|
14
|
-
};
|
|
15
|
-
const RESET_COLOR = "\x1B[0m";
|
|
16
|
-
const LEVEL_PRIORITY = {
|
|
17
|
-
debug: 0,
|
|
18
|
-
info: 1,
|
|
19
|
-
warn: 2,
|
|
20
|
-
error: 3,
|
|
21
|
-
fatal: 4
|
|
22
|
-
};
|
|
23
|
-
class VedaTraceConsoleTransport {
|
|
24
|
-
name = "console";
|
|
25
|
-
format;
|
|
26
|
-
colors;
|
|
27
|
-
minLevel;
|
|
28
|
-
constructor(config = {}) {
|
|
29
|
-
this.format = config.format ?? "pretty";
|
|
30
|
-
this.colors = config.colors ?? true;
|
|
31
|
-
this.minLevel = config.minLevel ?? "debug";
|
|
32
|
-
}
|
|
33
|
-
/** Send logs to console */
|
|
34
|
-
send(logs) {
|
|
35
|
-
for (const log of logs) {
|
|
36
|
-
if (LEVEL_PRIORITY[log.level] < LEVEL_PRIORITY[this.minLevel]) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
switch (this.format) {
|
|
40
|
-
case "json":
|
|
41
|
-
this.logJson(log);
|
|
42
|
-
break;
|
|
43
|
-
case "simple":
|
|
44
|
-
this.logSimple(log);
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
this.logPretty(log);
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/** Format as JSON */
|
|
53
|
-
logJson(log) {
|
|
54
|
-
console.log(JSON.stringify(log));
|
|
55
|
-
}
|
|
56
|
-
/** Format as simple text */
|
|
57
|
-
logSimple(log) {
|
|
58
|
-
const timestamp = new Date(log.timestamp ?? Date.now()).toISOString();
|
|
59
|
-
const service = log.service ? `[${log.service}] ` : "";
|
|
60
|
-
console.log(
|
|
61
|
-
`${timestamp} ${log.level.toUpperCase()} ${service}${log.message}`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
/** Format as pretty colored output */
|
|
65
|
-
logPretty(log) {
|
|
66
|
-
const timestamp = new Date(log.timestamp ?? Date.now()).toISOString();
|
|
67
|
-
const color = this.colors ? LEVEL_COLORS[log.level] : "";
|
|
68
|
-
const reset = this.colors ? RESET_COLOR : "";
|
|
69
|
-
const service = log.service ? ` ${color}[${log.service}]${reset}` : "";
|
|
70
|
-
let output = `${timestamp} ${color}${log.level.toUpperCase()}${reset}${service} ${log.message}`;
|
|
71
|
-
if (log.metadata && Object.keys(log.metadata).length > 0) {
|
|
72
|
-
output += `
|
|
73
|
-
${color}metadata:${reset} ${JSON.stringify(log.metadata, null, 2).replace(/\n/g, "\n ")}`;
|
|
74
|
-
}
|
|
75
|
-
console.log(output);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
3
|
+
var transports_index = require('../index-osD28Hs0.cjs');
|
|
78
4
|
|
|
79
|
-
class VedaTraceHttpTransport {
|
|
80
|
-
name = "http";
|
|
81
|
-
endpoint;
|
|
82
|
-
apiKey;
|
|
83
|
-
timeout;
|
|
84
|
-
headers;
|
|
85
|
-
keepalive;
|
|
86
|
-
constructor(config) {
|
|
87
|
-
this.apiKey = config.apiKey;
|
|
88
|
-
this.endpoint = config.endpoint ?? "https://ingest.vedatrace.dev/v1/logs";
|
|
89
|
-
this.timeout = config.timeout ?? 3e4;
|
|
90
|
-
this.headers = config.headers ?? {};
|
|
91
|
-
this.keepalive = config.keepalive ?? false;
|
|
92
|
-
}
|
|
93
|
-
/** Send logs via HTTP POST */
|
|
94
|
-
async send(logs) {
|
|
95
|
-
const controller = new AbortController();
|
|
96
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
97
|
-
const payload = logs.map((log) => ({
|
|
98
|
-
level: log.level,
|
|
99
|
-
message: log.message,
|
|
100
|
-
service: log.service,
|
|
101
|
-
timestamp: log.timestamp ? new Date(log.timestamp).toISOString() : void 0,
|
|
102
|
-
metadata: log.metadata
|
|
103
|
-
}));
|
|
104
|
-
try {
|
|
105
|
-
const response = await fetch(this.endpoint, {
|
|
106
|
-
method: "POST",
|
|
107
|
-
headers: {
|
|
108
|
-
"Content-Type": "application/json",
|
|
109
|
-
"X-API-Key": this.apiKey,
|
|
110
|
-
...this.headers
|
|
111
|
-
},
|
|
112
|
-
body: JSON.stringify(payload),
|
|
113
|
-
signal: controller.signal,
|
|
114
|
-
keepalive: this.keepalive
|
|
115
|
-
});
|
|
116
|
-
clearTimeout(timeoutId);
|
|
117
|
-
if (!response.ok) {
|
|
118
|
-
const text = await response.text();
|
|
119
|
-
throw new Error(`HTTP ${response.status}: ${text}`);
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
clearTimeout(timeoutId);
|
|
123
|
-
if (error instanceof Error) {
|
|
124
|
-
if (error.name === "AbortError") {
|
|
125
|
-
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
throw new Error(String(error));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/** Flush pending logs - called on page unload */
|
|
133
|
-
async flush() {
|
|
134
|
-
return Promise.resolve();
|
|
135
|
-
}
|
|
136
|
-
/** Check if keepalive is enabled */
|
|
137
|
-
isKeepaliveEnabled() {
|
|
138
|
-
return this.keepalive;
|
|
139
|
-
}
|
|
140
|
-
/** Enable/disable keepalive */
|
|
141
|
-
setKeepalive(enabled) {
|
|
142
|
-
this.keepalive = enabled;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
|
|
146
|
-
constructor(config) {
|
|
147
|
-
super({ ...config, keepalive: true });
|
|
148
|
-
}
|
|
149
|
-
async flush() {
|
|
150
|
-
this.setKeepalive(true);
|
|
151
|
-
return super.flush();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
5
|
|
|
155
|
-
|
|
156
|
-
exports.
|
|
157
|
-
exports.
|
|
6
|
+
|
|
7
|
+
exports.VedaTraceConsoleTransport = transports_index.VedaTraceConsoleTransport;
|
|
8
|
+
exports.VedaTraceHttpTransport = transports_index.VedaTraceHttpTransport;
|
|
9
|
+
exports.VedaTraceHttpTransportBrowser = transports_index.VedaTraceHttpTransportBrowser;
|
|
@@ -34,8 +34,9 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
|
|
|
34
34
|
*
|
|
35
35
|
* Features:
|
|
36
36
|
* - Timeout support with AbortController
|
|
37
|
-
* -
|
|
38
|
-
* - Keepalive
|
|
37
|
+
* - Status-aware errors so the batcher can tell retryable from permanent
|
|
38
|
+
* - Keepalive for the browser's final flush, with automatic splitting to stay
|
|
39
|
+
* under the 64 KiB body limit the fetch spec puts on keepalive requests
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
42
|
interface HttpTransportConfig {
|
|
@@ -56,7 +57,11 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
56
57
|
constructor(config: HttpTransportConfig);
|
|
57
58
|
/** Send logs via HTTP POST */
|
|
58
59
|
send(logs: InternalLogEntry[]): Promise<void>;
|
|
59
|
-
|
|
60
|
+
private post;
|
|
61
|
+
/**
|
|
62
|
+
* No-op: this transport holds no buffer of its own. The batcher owns the
|
|
63
|
+
* queue and calls send() directly, including on the browser's final flush.
|
|
64
|
+
*/
|
|
60
65
|
flush(): Promise<void>;
|
|
61
66
|
/** Check if keepalive is enabled */
|
|
62
67
|
isKeepaliveEnabled(): boolean;
|
|
@@ -64,11 +69,16 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
64
69
|
setKeepalive(enabled: boolean): void;
|
|
65
70
|
}
|
|
66
71
|
/**
|
|
67
|
-
* Browser
|
|
72
|
+
* Browser HTTP transport: keepalive is always on so the final flush survives
|
|
73
|
+
* the page going away.
|
|
74
|
+
*
|
|
75
|
+
* Note on `navigator.sendBeacon`: it cannot set request headers, and the
|
|
76
|
+
* ingestion endpoint authenticates with `X-API-Key`, so a beacon would arrive
|
|
77
|
+
* unauthenticated. Keepalive fetch is the only mechanism that carries both the
|
|
78
|
+
* credentials and the payload past unload.
|
|
68
79
|
*/
|
|
69
80
|
declare class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
|
|
70
81
|
constructor(config: HttpTransportConfig);
|
|
71
|
-
flush(): Promise<void>;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
|
|
@@ -34,8 +34,9 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
|
|
|
34
34
|
*
|
|
35
35
|
* Features:
|
|
36
36
|
* - Timeout support with AbortController
|
|
37
|
-
* -
|
|
38
|
-
* - Keepalive
|
|
37
|
+
* - Status-aware errors so the batcher can tell retryable from permanent
|
|
38
|
+
* - Keepalive for the browser's final flush, with automatic splitting to stay
|
|
39
|
+
* under the 64 KiB body limit the fetch spec puts on keepalive requests
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
42
|
interface HttpTransportConfig {
|
|
@@ -56,7 +57,11 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
56
57
|
constructor(config: HttpTransportConfig);
|
|
57
58
|
/** Send logs via HTTP POST */
|
|
58
59
|
send(logs: InternalLogEntry[]): Promise<void>;
|
|
59
|
-
|
|
60
|
+
private post;
|
|
61
|
+
/**
|
|
62
|
+
* No-op: this transport holds no buffer of its own. The batcher owns the
|
|
63
|
+
* queue and calls send() directly, including on the browser's final flush.
|
|
64
|
+
*/
|
|
60
65
|
flush(): Promise<void>;
|
|
61
66
|
/** Check if keepalive is enabled */
|
|
62
67
|
isKeepaliveEnabled(): boolean;
|
|
@@ -64,11 +69,16 @@ declare class VedaTraceHttpTransport implements VedaTraceTransport {
|
|
|
64
69
|
setKeepalive(enabled: boolean): void;
|
|
65
70
|
}
|
|
66
71
|
/**
|
|
67
|
-
* Browser
|
|
72
|
+
* Browser HTTP transport: keepalive is always on so the final flush survives
|
|
73
|
+
* the page going away.
|
|
74
|
+
*
|
|
75
|
+
* Note on `navigator.sendBeacon`: it cannot set request headers, and the
|
|
76
|
+
* ingestion endpoint authenticates with `X-API-Key`, so a beacon would arrive
|
|
77
|
+
* unauthenticated. Keepalive fetch is the only mechanism that carries both the
|
|
78
|
+
* credentials and the payload past unload.
|
|
68
79
|
*/
|
|
69
80
|
declare class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
|
|
70
81
|
constructor(config: HttpTransportConfig);
|
|
71
|
-
flush(): Promise<void>;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
|
|
@@ -1,153 +1 @@
|
|
|
1
|
-
|
|
2
|
-
debug: "\x1B[36m",
|
|
3
|
-
// cyan
|
|
4
|
-
info: "\x1B[32m",
|
|
5
|
-
// green
|
|
6
|
-
warn: "\x1B[33m",
|
|
7
|
-
// yellow
|
|
8
|
-
error: "\x1B[31m",
|
|
9
|
-
// red
|
|
10
|
-
fatal: "\x1B[35m"
|
|
11
|
-
// magenta
|
|
12
|
-
};
|
|
13
|
-
const RESET_COLOR = "\x1B[0m";
|
|
14
|
-
const LEVEL_PRIORITY = {
|
|
15
|
-
debug: 0,
|
|
16
|
-
info: 1,
|
|
17
|
-
warn: 2,
|
|
18
|
-
error: 3,
|
|
19
|
-
fatal: 4
|
|
20
|
-
};
|
|
21
|
-
class VedaTraceConsoleTransport {
|
|
22
|
-
name = "console";
|
|
23
|
-
format;
|
|
24
|
-
colors;
|
|
25
|
-
minLevel;
|
|
26
|
-
constructor(config = {}) {
|
|
27
|
-
this.format = config.format ?? "pretty";
|
|
28
|
-
this.colors = config.colors ?? true;
|
|
29
|
-
this.minLevel = config.minLevel ?? "debug";
|
|
30
|
-
}
|
|
31
|
-
/** Send logs to console */
|
|
32
|
-
send(logs) {
|
|
33
|
-
for (const log of logs) {
|
|
34
|
-
if (LEVEL_PRIORITY[log.level] < LEVEL_PRIORITY[this.minLevel]) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
switch (this.format) {
|
|
38
|
-
case "json":
|
|
39
|
-
this.logJson(log);
|
|
40
|
-
break;
|
|
41
|
-
case "simple":
|
|
42
|
-
this.logSimple(log);
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
this.logPretty(log);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/** Format as JSON */
|
|
51
|
-
logJson(log) {
|
|
52
|
-
console.log(JSON.stringify(log));
|
|
53
|
-
}
|
|
54
|
-
/** Format as simple text */
|
|
55
|
-
logSimple(log) {
|
|
56
|
-
const timestamp = new Date(log.timestamp ?? Date.now()).toISOString();
|
|
57
|
-
const service = log.service ? `[${log.service}] ` : "";
|
|
58
|
-
console.log(
|
|
59
|
-
`${timestamp} ${log.level.toUpperCase()} ${service}${log.message}`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
/** Format as pretty colored output */
|
|
63
|
-
logPretty(log) {
|
|
64
|
-
const timestamp = new Date(log.timestamp ?? Date.now()).toISOString();
|
|
65
|
-
const color = this.colors ? LEVEL_COLORS[log.level] : "";
|
|
66
|
-
const reset = this.colors ? RESET_COLOR : "";
|
|
67
|
-
const service = log.service ? ` ${color}[${log.service}]${reset}` : "";
|
|
68
|
-
let output = `${timestamp} ${color}${log.level.toUpperCase()}${reset}${service} ${log.message}`;
|
|
69
|
-
if (log.metadata && Object.keys(log.metadata).length > 0) {
|
|
70
|
-
output += `
|
|
71
|
-
${color}metadata:${reset} ${JSON.stringify(log.metadata, null, 2).replace(/\n/g, "\n ")}`;
|
|
72
|
-
}
|
|
73
|
-
console.log(output);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
class VedaTraceHttpTransport {
|
|
78
|
-
name = "http";
|
|
79
|
-
endpoint;
|
|
80
|
-
apiKey;
|
|
81
|
-
timeout;
|
|
82
|
-
headers;
|
|
83
|
-
keepalive;
|
|
84
|
-
constructor(config) {
|
|
85
|
-
this.apiKey = config.apiKey;
|
|
86
|
-
this.endpoint = config.endpoint ?? "https://ingest.vedatrace.dev/v1/logs";
|
|
87
|
-
this.timeout = config.timeout ?? 3e4;
|
|
88
|
-
this.headers = config.headers ?? {};
|
|
89
|
-
this.keepalive = config.keepalive ?? false;
|
|
90
|
-
}
|
|
91
|
-
/** Send logs via HTTP POST */
|
|
92
|
-
async send(logs) {
|
|
93
|
-
const controller = new AbortController();
|
|
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
|
-
}));
|
|
102
|
-
try {
|
|
103
|
-
const response = await fetch(this.endpoint, {
|
|
104
|
-
method: "POST",
|
|
105
|
-
headers: {
|
|
106
|
-
"Content-Type": "application/json",
|
|
107
|
-
"X-API-Key": this.apiKey,
|
|
108
|
-
...this.headers
|
|
109
|
-
},
|
|
110
|
-
body: JSON.stringify(payload),
|
|
111
|
-
signal: controller.signal,
|
|
112
|
-
keepalive: this.keepalive
|
|
113
|
-
});
|
|
114
|
-
clearTimeout(timeoutId);
|
|
115
|
-
if (!response.ok) {
|
|
116
|
-
const text = await response.text();
|
|
117
|
-
throw new Error(`HTTP ${response.status}: ${text}`);
|
|
118
|
-
}
|
|
119
|
-
} catch (error) {
|
|
120
|
-
clearTimeout(timeoutId);
|
|
121
|
-
if (error instanceof Error) {
|
|
122
|
-
if (error.name === "AbortError") {
|
|
123
|
-
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
124
|
-
}
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
throw new Error(String(error));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/** Flush pending logs - called on page unload */
|
|
131
|
-
async flush() {
|
|
132
|
-
return Promise.resolve();
|
|
133
|
-
}
|
|
134
|
-
/** Check if keepalive is enabled */
|
|
135
|
-
isKeepaliveEnabled() {
|
|
136
|
-
return this.keepalive;
|
|
137
|
-
}
|
|
138
|
-
/** Enable/disable keepalive */
|
|
139
|
-
setKeepalive(enabled) {
|
|
140
|
-
this.keepalive = enabled;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
class VedaTraceHttpTransportBrowser extends VedaTraceHttpTransport {
|
|
144
|
-
constructor(config) {
|
|
145
|
-
super({ ...config, keepalive: true });
|
|
146
|
-
}
|
|
147
|
-
async flush() {
|
|
148
|
-
this.setKeepalive(true);
|
|
149
|
-
return super.flush();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export { VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser };
|
|
1
|
+
export { c as VedaTraceConsoleTransport, b as VedaTraceHttpTransport, V as VedaTraceHttpTransportBrowser } from '../index-BcBZY8as.mjs';
|