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
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VedaTraceHttpTransportBrowser, VedaTraceHttpTransport, VedaTraceConsoleTransport } from './
|
|
1
|
+
import { i as isFatal, a as isRetryable, r as retryAfterMs, V as VedaTraceHttpTransportBrowser, b as VedaTraceHttpTransport, c as VedaTraceConsoleTransport } from './index-BcBZY8as.mjs';
|
|
2
|
+
export { d as VedaTraceTransportError } from './index-BcBZY8as.mjs';
|
|
2
3
|
|
|
3
4
|
class VedaTraceBatcher {
|
|
4
5
|
constructor(transports, config, immediateFlush = false) {
|
|
@@ -15,6 +16,12 @@ class VedaTraceBatcher {
|
|
|
15
16
|
pendingFlush = null;
|
|
16
17
|
context;
|
|
17
18
|
waitUntilFn;
|
|
19
|
+
/**
|
|
20
|
+
* Set when the ingestion endpoint rejects our credentials. Every subsequent
|
|
21
|
+
* batch would fail identically, so we stop rather than spend a request (and a
|
|
22
|
+
* retry storm) per flush for the life of the process. start() clears it.
|
|
23
|
+
*/
|
|
24
|
+
halted = false;
|
|
18
25
|
setContext(ctx) {
|
|
19
26
|
this.context = ctx;
|
|
20
27
|
}
|
|
@@ -22,6 +29,7 @@ class VedaTraceBatcher {
|
|
|
22
29
|
return this.context;
|
|
23
30
|
}
|
|
24
31
|
add(log) {
|
|
32
|
+
if (this.halted) return;
|
|
25
33
|
this.queue.push(log);
|
|
26
34
|
if (this.context || this.waitUntilFn) {
|
|
27
35
|
this.debouncedFlush();
|
|
@@ -43,23 +51,12 @@ class VedaTraceBatcher {
|
|
|
43
51
|
this.flushQueued = true;
|
|
44
52
|
queueMicrotask(() => {
|
|
45
53
|
this.flushQueued = false;
|
|
46
|
-
this.flush().catch((error) =>
|
|
47
|
-
if (this.config.onError) {
|
|
48
|
-
this.config.onError(
|
|
49
|
-
error instanceof Error ? error : new Error(String(error))
|
|
50
|
-
);
|
|
51
|
-
} else {
|
|
52
|
-
console.error(
|
|
53
|
-
"[VedaTrace] Debounced flush error:",
|
|
54
|
-
error instanceof Error ? error.message : String(error)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
54
|
+
this.flush().catch((error) => this.reportError(error));
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
57
|
async flush() {
|
|
61
58
|
if (this.isFlushing) {
|
|
62
|
-
return this.pendingFlush ??
|
|
59
|
+
return this.pendingFlush ?? Promise.resolve();
|
|
63
60
|
}
|
|
64
61
|
if (this.queue.length === 0) {
|
|
65
62
|
return Promise.resolve();
|
|
@@ -70,6 +67,10 @@ class VedaTraceBatcher {
|
|
|
70
67
|
const flushPromise = this.sendWithRetry(logsToSend).finally(() => {
|
|
71
68
|
this.isFlushing = false;
|
|
72
69
|
this.pendingFlush = null;
|
|
70
|
+
}).then(() => {
|
|
71
|
+
if (this.queue.length > 0 && !this.halted) {
|
|
72
|
+
return this.flush();
|
|
73
|
+
}
|
|
73
74
|
});
|
|
74
75
|
this.pendingFlush = flushPromise;
|
|
75
76
|
if (this.context && typeof this.context.waitUntil === "function") {
|
|
@@ -85,26 +86,47 @@ class VedaTraceBatcher {
|
|
|
85
86
|
try {
|
|
86
87
|
await transport.send(logs);
|
|
87
88
|
} catch (error) {
|
|
88
|
-
errors.push(error
|
|
89
|
+
errors.push(error);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
if (errors.length
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
);
|
|
99
|
-
if (this.config.onError) {
|
|
100
|
-
this.config.onError(combinedError);
|
|
101
|
-
} else {
|
|
102
|
-
console.error("[VedaTrace]", combinedError.message);
|
|
103
|
-
}
|
|
92
|
+
if (errors.length === 0 || errors.length < this.transports.length) {
|
|
93
|
+
this.config.onSuccess?.();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const fatalError = errors.find(isFatal);
|
|
97
|
+
if (fatalError) {
|
|
98
|
+
this.halt(fatalError);
|
|
104
99
|
return;
|
|
105
100
|
}
|
|
106
|
-
if (this.config.
|
|
107
|
-
this.config.
|
|
101
|
+
if (errors.some(isRetryable) && attempt < this.config.maxRetries) {
|
|
102
|
+
const backoff = this.config.retryDelay * (attempt + 1);
|
|
103
|
+
await this.delay(retryAfterMs(errors) ?? backoff);
|
|
104
|
+
return this.sendWithRetry(logs, attempt + 1);
|
|
105
|
+
}
|
|
106
|
+
const detail = errors.map(describeError).join(", ");
|
|
107
|
+
this.reportError(
|
|
108
|
+
new Error(
|
|
109
|
+
errors.some(isRetryable) ? `Failed to send ${logs.length} logs after ${this.config.maxRetries} retries: ${detail}` : `Failed to send ${logs.length} logs: ${detail}`
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
/** Stop accepting logs after an unrecoverable authentication failure. */
|
|
114
|
+
halt(error) {
|
|
115
|
+
this.halted = true;
|
|
116
|
+
this.queue = [];
|
|
117
|
+
this.stop();
|
|
118
|
+
this.reportError(
|
|
119
|
+
new Error(
|
|
120
|
+
`VedaTrace disabled: ${describeError(error)}. Check your API key and the key's allowed origins, then call logger.start() to resume.`
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
reportError(error) {
|
|
125
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
126
|
+
if (this.config.onError) {
|
|
127
|
+
this.config.onError(normalized);
|
|
128
|
+
} else {
|
|
129
|
+
console.error("[VedaTrace]", normalized.message);
|
|
108
130
|
}
|
|
109
131
|
}
|
|
110
132
|
startFlushTimer() {
|
|
@@ -113,22 +135,11 @@ class VedaTraceBatcher {
|
|
|
113
135
|
}
|
|
114
136
|
this.flushTimer = setInterval(() => {
|
|
115
137
|
if (this.queue.length > 0) {
|
|
116
|
-
this.flush().catch((error) =>
|
|
117
|
-
if (this.config.onError) {
|
|
118
|
-
this.config.onError(
|
|
119
|
-
error instanceof Error ? error : new Error(String(error))
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
console.error(
|
|
123
|
-
"[VedaTrace] Flush error:",
|
|
124
|
-
error instanceof Error ? error.message : String(error)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
138
|
+
this.flush().catch((error) => this.reportError(error));
|
|
128
139
|
}
|
|
129
140
|
}, this.config.flushInterval);
|
|
130
141
|
if (this.config.unrefTimer === true) {
|
|
131
|
-
this.flushTimer.unref();
|
|
142
|
+
this.flushTimer.unref?.();
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
145
|
stop() {
|
|
@@ -139,6 +150,7 @@ class VedaTraceBatcher {
|
|
|
139
150
|
this.flushQueued = false;
|
|
140
151
|
}
|
|
141
152
|
start() {
|
|
153
|
+
this.halted = false;
|
|
142
154
|
if (!this.flushTimer && !this.immediateFlush) {
|
|
143
155
|
this.startFlushTimer();
|
|
144
156
|
}
|
|
@@ -149,10 +161,17 @@ class VedaTraceBatcher {
|
|
|
149
161
|
getQueueSize() {
|
|
150
162
|
return this.queue.length;
|
|
151
163
|
}
|
|
164
|
+
/** True once an auth failure has shut the batcher down. */
|
|
165
|
+
isHalted() {
|
|
166
|
+
return this.halted;
|
|
167
|
+
}
|
|
152
168
|
setExecutionContext(ctx) {
|
|
153
169
|
this.context = ctx;
|
|
154
170
|
}
|
|
155
171
|
}
|
|
172
|
+
function describeError(error) {
|
|
173
|
+
return error instanceof Error ? error.message : String(error);
|
|
174
|
+
}
|
|
156
175
|
|
|
157
176
|
function detectRuntime() {
|
|
158
177
|
if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") {
|
|
@@ -195,7 +214,8 @@ function isBrowser() {
|
|
|
195
214
|
return detectRuntime() === "browser";
|
|
196
215
|
}
|
|
197
216
|
|
|
198
|
-
const SDK_VERSION =
|
|
217
|
+
const SDK_VERSION = "0.3.1";
|
|
218
|
+
|
|
199
219
|
class VedaTraceLogger {
|
|
200
220
|
batcher = null;
|
|
201
221
|
runtime;
|
|
@@ -348,24 +368,17 @@ class BrowserLifecycle {
|
|
|
348
368
|
this.config = config;
|
|
349
369
|
this.boundVisibilityHandler = this.handleVisibilityChange.bind(this);
|
|
350
370
|
this.boundPageHideHandler = this.handlePageHide.bind(this);
|
|
351
|
-
this.boundBeforeUnloadHandler = this.handleBeforeUnload.bind(this);
|
|
352
|
-
this.boundUnloadHandler = this.handleUnload.bind(this);
|
|
353
371
|
}
|
|
354
372
|
boundVisibilityHandler;
|
|
355
373
|
boundPageHideHandler;
|
|
356
|
-
boundBeforeUnloadHandler;
|
|
357
|
-
boundUnloadHandler;
|
|
358
374
|
isAttached = false;
|
|
359
375
|
pendingFlush = null;
|
|
360
376
|
/** Start listening for browser lifecycle events */
|
|
361
377
|
attach() {
|
|
362
378
|
if (this.isAttached) return;
|
|
363
|
-
if (typeof document
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
window.addEventListener("beforeunload", this.boundBeforeUnloadHandler);
|
|
367
|
-
window.addEventListener("unload", this.boundUnloadHandler);
|
|
368
|
-
}
|
|
379
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
380
|
+
document.addEventListener("visibilitychange", this.boundVisibilityHandler);
|
|
381
|
+
window.addEventListener("pagehide", this.boundPageHideHandler);
|
|
369
382
|
this.isAttached = true;
|
|
370
383
|
if (this.config.debug) {
|
|
371
384
|
console.log("[VedaTrace] Browser lifecycle handlers attached");
|
|
@@ -374,21 +387,25 @@ class BrowserLifecycle {
|
|
|
374
387
|
/** Stop listening for browser lifecycle events */
|
|
375
388
|
detach() {
|
|
376
389
|
if (!this.isAttached) return;
|
|
377
|
-
if (typeof document !== "undefined") {
|
|
390
|
+
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
378
391
|
document.removeEventListener(
|
|
379
392
|
"visibilitychange",
|
|
380
393
|
this.boundVisibilityHandler
|
|
381
394
|
);
|
|
382
395
|
window.removeEventListener("pagehide", this.boundPageHideHandler);
|
|
383
|
-
window.removeEventListener("beforeunload", this.boundBeforeUnloadHandler);
|
|
384
|
-
window.removeEventListener("unload", this.boundUnloadHandler);
|
|
385
396
|
}
|
|
386
397
|
this.isAttached = false;
|
|
387
398
|
if (this.config.debug) {
|
|
388
399
|
console.log("[VedaTrace] Browser lifecycle handlers detached");
|
|
389
400
|
}
|
|
390
401
|
}
|
|
391
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Flush when the page becomes hidden.
|
|
404
|
+
*
|
|
405
|
+
* This is the one that actually matters: on mobile, a backgrounded tab is
|
|
406
|
+
* often discarded without ever firing pagehide, so "hidden" is the last
|
|
407
|
+
* reliable moment to ship what we have.
|
|
408
|
+
*/
|
|
392
409
|
handleVisibilityChange() {
|
|
393
410
|
if (document.visibilityState === "hidden") {
|
|
394
411
|
if (this.config.debug) {
|
|
@@ -397,7 +414,7 @@ class BrowserLifecycle {
|
|
|
397
414
|
this.scheduleFlush();
|
|
398
415
|
}
|
|
399
416
|
}
|
|
400
|
-
/**
|
|
417
|
+
/** Final flush as the page is torn down or frozen into the bfcache. */
|
|
401
418
|
handlePageHide(event) {
|
|
402
419
|
if (this.config.debug) {
|
|
403
420
|
console.log(
|
|
@@ -405,46 +422,16 @@ class BrowserLifecycle {
|
|
|
405
422
|
event.persisted ? "(cached)" : "(navigation)"
|
|
406
423
|
);
|
|
407
424
|
}
|
|
408
|
-
|
|
409
|
-
this.scheduleFlush();
|
|
410
|
-
} else {
|
|
411
|
-
this.finalFlush();
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/** Handle beforeunload - backup flush mechanism */
|
|
415
|
-
handleBeforeUnload(event) {
|
|
416
|
-
if (this.config.debug) {
|
|
417
|
-
console.log("[VedaTrace] Before unload event");
|
|
418
|
-
}
|
|
419
|
-
this.finalFlush();
|
|
420
|
-
}
|
|
421
|
-
/** Handle unload - fallback for older browsers */
|
|
422
|
-
handleUnload() {
|
|
423
|
-
if (this.config.debug) {
|
|
424
|
-
console.log("[VedaTrace] Unload event");
|
|
425
|
-
}
|
|
426
|
-
this.finalFlush();
|
|
425
|
+
this.scheduleFlush();
|
|
427
426
|
}
|
|
428
|
-
/**
|
|
427
|
+
/** Flush at most once at a time; keepalive carries it past the document. */
|
|
429
428
|
scheduleFlush() {
|
|
430
429
|
if (this.pendingFlush) return;
|
|
431
|
-
this.pendingFlush = this.config.flush().
|
|
430
|
+
this.pendingFlush = this.config.flush().catch(() => {
|
|
431
|
+
}).finally(() => {
|
|
432
432
|
this.pendingFlush = null;
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Final flush using keepalive fetch
|
|
437
|
-
* For sending logs after the page context is destroyed
|
|
438
|
-
*/
|
|
439
|
-
finalFlush() {
|
|
440
|
-
for (const transport of this.config.transports) {
|
|
441
|
-
if (transport.name === "http" && "flush" in transport) {
|
|
442
|
-
transport.flush?.();
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
this.config.flush().catch(() => {
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
435
|
/** Check if handlers are attached */
|
|
449
436
|
isActive() {
|
|
450
437
|
return this.isAttached;
|
|
@@ -525,6 +512,16 @@ function redactPii(value, mask) {
|
|
|
525
512
|
return result;
|
|
526
513
|
}
|
|
527
514
|
|
|
515
|
+
function resolveApiKey(config) {
|
|
516
|
+
if (config.apiKey) return config.apiKey;
|
|
517
|
+
try {
|
|
518
|
+
if (typeof process !== "undefined" && process.env) {
|
|
519
|
+
return process.env.VEDATRACE_API_KEY || void 0;
|
|
520
|
+
}
|
|
521
|
+
} catch {
|
|
522
|
+
}
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
528
525
|
const RUNTIME_FLUSH_INTERVALS = {
|
|
529
526
|
node: 3e3,
|
|
530
527
|
bun: 3e3,
|
|
@@ -535,14 +532,15 @@ const RUNTIME_FLUSH_INTERVALS = {
|
|
|
535
532
|
};
|
|
536
533
|
function vedatrace(config = {}) {
|
|
537
534
|
const runtime = detectRuntime();
|
|
538
|
-
const
|
|
539
|
-
|
|
535
|
+
const apiKey = resolveApiKey(config);
|
|
536
|
+
const logger = new VedaTraceLogger(apiKey ? { ...config, apiKey } : config);
|
|
537
|
+
if (apiKey && (!config.transports || config.transports.length === 0)) {
|
|
540
538
|
const isBrowserEnv = isBrowser();
|
|
541
539
|
const isServerlessEnv = isServerless();
|
|
542
540
|
const isLongRunningEnv = isLongRunning();
|
|
543
541
|
const HttpTransport = isBrowserEnv ? VedaTraceHttpTransportBrowser : VedaTraceHttpTransport;
|
|
544
542
|
const httpConfig = {
|
|
545
|
-
apiKey
|
|
543
|
+
apiKey,
|
|
546
544
|
keepalive: isBrowserEnv || isServerlessEnv
|
|
547
545
|
};
|
|
548
546
|
if (config.endpoint) httpConfig.endpoint = config.endpoint;
|
|
@@ -609,4 +607,4 @@ function devVedatrace(config = {}) {
|
|
|
609
607
|
});
|
|
610
608
|
}
|
|
611
609
|
|
|
612
|
-
export { BrowserLifecycle, VedaTraceBatcher, VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser, VedaTraceLogger, vedatrace as default, detectRuntime, devVedatrace, isBrowser, isEdgeRuntime, isLongRunning, isServerless, redact, vedatrace };
|
|
610
|
+
export { BrowserLifecycle, SDK_VERSION, VedaTraceBatcher, VedaTraceConsoleTransport, VedaTraceHttpTransport, VedaTraceHttpTransportBrowser, VedaTraceLogger, vedatrace as default, detectRuntime, devVedatrace, isBrowser, isEdgeRuntime, isLongRunning, isServerless, redact, vedatrace };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('../index.cjs');
|
|
4
|
-
require('../
|
|
4
|
+
require('../index-osD28Hs0.cjs');
|
|
5
5
|
|
|
6
6
|
function vedaTraceMiddleware(config = {}) {
|
|
7
7
|
const {
|
|
@@ -11,10 +11,11 @@ function vedaTraceMiddleware(config = {}) {
|
|
|
11
11
|
logBody = false,
|
|
12
12
|
...vedaConfig
|
|
13
13
|
} = config;
|
|
14
|
+
const baseLogger = index.default(vedaConfig);
|
|
14
15
|
return (req, res, next) => {
|
|
15
16
|
const requestId = generateRequestId(req);
|
|
16
17
|
req.requestId = requestId;
|
|
17
|
-
const logger =
|
|
18
|
+
const logger = baseLogger.child({
|
|
18
19
|
requestId,
|
|
19
20
|
...requestMetadata(req)
|
|
20
21
|
});
|
|
@@ -38,8 +39,6 @@ function vedaTraceMiddleware(config = {}) {
|
|
|
38
39
|
statusCode: res.statusCode,
|
|
39
40
|
durationMs: duration
|
|
40
41
|
});
|
|
41
|
-
logger.flush().catch(() => {
|
|
42
|
-
});
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
44
|
next();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import vedatrace from '../index.mjs';
|
|
2
|
-
import '../
|
|
2
|
+
import '../index-BcBZY8as.mjs';
|
|
3
3
|
|
|
4
4
|
function vedaTraceMiddleware(config = {}) {
|
|
5
5
|
const {
|
|
@@ -9,10 +9,11 @@ function vedaTraceMiddleware(config = {}) {
|
|
|
9
9
|
logBody = false,
|
|
10
10
|
...vedaConfig
|
|
11
11
|
} = config;
|
|
12
|
+
const baseLogger = vedatrace(vedaConfig);
|
|
12
13
|
return (req, res, next) => {
|
|
13
14
|
const requestId = generateRequestId(req);
|
|
14
15
|
req.requestId = requestId;
|
|
15
|
-
const logger =
|
|
16
|
+
const logger = baseLogger.child({
|
|
16
17
|
requestId,
|
|
17
18
|
...requestMetadata(req)
|
|
18
19
|
});
|
|
@@ -36,8 +37,6 @@ function vedaTraceMiddleware(config = {}) {
|
|
|
36
37
|
statusCode: res.statusCode,
|
|
37
38
|
durationMs: duration
|
|
38
39
|
});
|
|
39
|
-
logger.flush().catch(() => {
|
|
40
|
-
});
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
next();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('../index.cjs');
|
|
4
|
-
require('../
|
|
4
|
+
require('../index-osD28Hs0.cjs');
|
|
5
5
|
|
|
6
6
|
function withVedaTrace(handler, config = {}) {
|
|
7
7
|
const {
|
|
@@ -9,9 +9,10 @@ function withVedaTrace(handler, config = {}) {
|
|
|
9
9
|
requestMetadata = () => ({}),
|
|
10
10
|
...vedaConfig
|
|
11
11
|
} = config;
|
|
12
|
+
const baseLogger = index.default(vedaConfig);
|
|
12
13
|
return async (req) => {
|
|
13
14
|
const requestId = generateRequestId();
|
|
14
|
-
const logger =
|
|
15
|
+
const logger = baseLogger.child({
|
|
15
16
|
requestId,
|
|
16
17
|
...requestMetadata()
|
|
17
18
|
});
|
|
@@ -42,10 +43,35 @@ function withVedaTrace(handler, config = {}) {
|
|
|
42
43
|
function createVedaTraceLogger(config = {}) {
|
|
43
44
|
return index.default(config);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let serverLoggerInstance = null;
|
|
47
|
+
function getServerLogger(config = {}) {
|
|
48
|
+
if (!serverLoggerInstance) {
|
|
49
|
+
serverLoggerInstance = index.default({ service: "nextjs-server", ...config });
|
|
50
|
+
}
|
|
51
|
+
return serverLoggerInstance;
|
|
52
|
+
}
|
|
53
|
+
const serverLogger = {
|
|
54
|
+
debug: (message, metadata) => getServerLogger().debug(message, metadata),
|
|
55
|
+
info: (message, metadata) => getServerLogger().info(message, metadata),
|
|
56
|
+
warn: (message, metadata) => getServerLogger().warn(message, metadata),
|
|
57
|
+
error: (message, metadata) => getServerLogger().error(message, metadata),
|
|
58
|
+
fatal: (message, metadata) => getServerLogger().fatal(message, metadata),
|
|
59
|
+
child: (defaults) => getServerLogger().child(defaults),
|
|
60
|
+
flush: () => getServerLogger().flush(),
|
|
61
|
+
stop: () => getServerLogger().stop(),
|
|
62
|
+
start: () => getServerLogger().start(),
|
|
63
|
+
withContext(ctx) {
|
|
64
|
+
getServerLogger().withContext(ctx);
|
|
65
|
+
return this;
|
|
66
|
+
},
|
|
67
|
+
hasContext: () => getServerLogger().hasContext(),
|
|
68
|
+
getContext: () => getServerLogger().getContext(),
|
|
69
|
+
get runtime() {
|
|
70
|
+
return getServerLogger().runtime;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
48
73
|
|
|
49
74
|
exports.createVedaTraceLogger = createVedaTraceLogger;
|
|
75
|
+
exports.getServerLogger = getServerLogger;
|
|
50
76
|
exports.serverLogger = serverLogger;
|
|
51
77
|
exports.withVedaTrace = withVedaTrace;
|
|
@@ -47,22 +47,14 @@ declare function withVedaTrace<T extends (req: Request, ctx: NextJsContext) => P
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
declare function createVedaTraceLogger(config?: VedaTraceConfig): VedaTraceLoggerInterface;
|
|
50
|
+
/** Get (and lazily create) the shared Next.js server logger. */
|
|
51
|
+
declare function getServerLogger(config?: VedaTraceConfig): VedaTraceLoggerInterface;
|
|
50
52
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // app/page.tsx (Server Component)
|
|
57
|
-
* import { serverLogger } from 'vedatrace/next'
|
|
58
|
-
*
|
|
59
|
-
* export default async function Page() {
|
|
60
|
-
* serverLogger.info('Rendering page')
|
|
61
|
-
* return <div>Hello</div>
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
53
|
+
* Convenience wrapper around {@link getServerLogger} that keeps the original
|
|
54
|
+
* `serverLogger.info(...)` call shape while deferring construction to the first
|
|
55
|
+
* call.
|
|
64
56
|
*/
|
|
65
57
|
declare const serverLogger: VedaTraceLoggerInterface;
|
|
66
58
|
|
|
67
|
-
export { createVedaTraceLogger, serverLogger, withVedaTrace };
|
|
59
|
+
export { createVedaTraceLogger, getServerLogger, serverLogger, withVedaTrace };
|
|
68
60
|
export type { NextJsConfig, NextJsContext };
|
|
@@ -47,22 +47,14 @@ declare function withVedaTrace<T extends (req: Request, ctx: NextJsContext) => P
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
declare function createVedaTraceLogger(config?: VedaTraceConfig): VedaTraceLoggerInterface;
|
|
50
|
+
/** Get (and lazily create) the shared Next.js server logger. */
|
|
51
|
+
declare function getServerLogger(config?: VedaTraceConfig): VedaTraceLoggerInterface;
|
|
50
52
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // app/page.tsx (Server Component)
|
|
57
|
-
* import { serverLogger } from 'vedatrace/next'
|
|
58
|
-
*
|
|
59
|
-
* export default async function Page() {
|
|
60
|
-
* serverLogger.info('Rendering page')
|
|
61
|
-
* return <div>Hello</div>
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
53
|
+
* Convenience wrapper around {@link getServerLogger} that keeps the original
|
|
54
|
+
* `serverLogger.info(...)` call shape while deferring construction to the first
|
|
55
|
+
* call.
|
|
64
56
|
*/
|
|
65
57
|
declare const serverLogger: VedaTraceLoggerInterface;
|
|
66
58
|
|
|
67
|
-
export { createVedaTraceLogger, serverLogger, withVedaTrace };
|
|
59
|
+
export { createVedaTraceLogger, getServerLogger, serverLogger, withVedaTrace };
|
|
68
60
|
export type { NextJsConfig, NextJsContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import vedatrace from '../index.mjs';
|
|
2
|
-
import '../
|
|
2
|
+
import '../index-BcBZY8as.mjs';
|
|
3
3
|
|
|
4
4
|
function withVedaTrace(handler, config = {}) {
|
|
5
5
|
const {
|
|
@@ -7,9 +7,10 @@ function withVedaTrace(handler, config = {}) {
|
|
|
7
7
|
requestMetadata = () => ({}),
|
|
8
8
|
...vedaConfig
|
|
9
9
|
} = config;
|
|
10
|
+
const baseLogger = vedatrace(vedaConfig);
|
|
10
11
|
return async (req) => {
|
|
11
12
|
const requestId = generateRequestId();
|
|
12
|
-
const logger =
|
|
13
|
+
const logger = baseLogger.child({
|
|
13
14
|
requestId,
|
|
14
15
|
...requestMetadata()
|
|
15
16
|
});
|
|
@@ -40,8 +41,32 @@ function withVedaTrace(handler, config = {}) {
|
|
|
40
41
|
function createVedaTraceLogger(config = {}) {
|
|
41
42
|
return vedatrace(config);
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let serverLoggerInstance = null;
|
|
45
|
+
function getServerLogger(config = {}) {
|
|
46
|
+
if (!serverLoggerInstance) {
|
|
47
|
+
serverLoggerInstance = vedatrace({ service: "nextjs-server", ...config });
|
|
48
|
+
}
|
|
49
|
+
return serverLoggerInstance;
|
|
50
|
+
}
|
|
51
|
+
const serverLogger = {
|
|
52
|
+
debug: (message, metadata) => getServerLogger().debug(message, metadata),
|
|
53
|
+
info: (message, metadata) => getServerLogger().info(message, metadata),
|
|
54
|
+
warn: (message, metadata) => getServerLogger().warn(message, metadata),
|
|
55
|
+
error: (message, metadata) => getServerLogger().error(message, metadata),
|
|
56
|
+
fatal: (message, metadata) => getServerLogger().fatal(message, metadata),
|
|
57
|
+
child: (defaults) => getServerLogger().child(defaults),
|
|
58
|
+
flush: () => getServerLogger().flush(),
|
|
59
|
+
stop: () => getServerLogger().stop(),
|
|
60
|
+
start: () => getServerLogger().start(),
|
|
61
|
+
withContext(ctx) {
|
|
62
|
+
getServerLogger().withContext(ctx);
|
|
63
|
+
return this;
|
|
64
|
+
},
|
|
65
|
+
hasContext: () => getServerLogger().hasContext(),
|
|
66
|
+
getContext: () => getServerLogger().getContext(),
|
|
67
|
+
get runtime() {
|
|
68
|
+
return getServerLogger().runtime;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
46
71
|
|
|
47
|
-
export { createVedaTraceLogger, serverLogger, withVedaTrace };
|
|
72
|
+
export { createVedaTraceLogger, getServerLogger, serverLogger, withVedaTrace };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var index = require('../index.cjs');
|
|
6
|
-
require('../
|
|
6
|
+
require('../index-osD28Hs0.cjs');
|
|
7
7
|
|
|
8
8
|
const VedaTraceContext = react.createContext(null);
|
|
9
9
|
function VedaTraceProvider({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { createContext, useRef, useMemo, useEffect, useContext, useCallback } from 'react';
|
|
3
3
|
import vedatrace from '../index.mjs';
|
|
4
|
-
import '../
|
|
4
|
+
import '../index-BcBZY8as.mjs';
|
|
5
5
|
|
|
6
6
|
const VedaTraceContext = createContext(null);
|
|
7
7
|
function VedaTraceProvider({
|