vedatrace 0.2.1 → 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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('../index.cjs');
4
- require('../transports/index.cjs');
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 = index.default(vedaConfig).child({
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
- const serverLogger = index.default({
46
- service: "nextjs-server"
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;
@@ -1,4 +1,4 @@
1
- import { a as VedaTraceConfig, L as LogMetadata, V as VedaTraceLoggerInterface } from '../types-BU0UESs9.cjs';
1
+ import { a as VedaTraceConfig, L as LogMetadata, V as VedaTraceLoggerInterface } from '../types-CSBzeGyK.cjs';
2
2
 
3
3
  /**
4
4
  * Next.js integration for VedaTrace
@@ -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
- * Server-side logger for Next.js
52
- * Use in Server Components or API routes
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,4 +1,4 @@
1
- import { a as VedaTraceConfig, L as LogMetadata, V as VedaTraceLoggerInterface } from '../types-BU0UESs9.mjs';
1
+ import { a as VedaTraceConfig, L as LogMetadata, V as VedaTraceLoggerInterface } from '../types-CSBzeGyK.mjs';
2
2
 
3
3
  /**
4
4
  * Next.js integration for VedaTrace
@@ -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
- * Server-side logger for Next.js
52
- * Use in Server Components or API routes
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 '../transports/index.mjs';
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 = vedatrace(vedaConfig).child({
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
- const serverLogger = vedatrace({
44
- service: "nextjs-server"
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('../transports/index.cjs');
6
+ require('../index-osD28Hs0.cjs');
7
7
 
8
8
  const VedaTraceContext = react.createContext(null);
9
9
  function VedaTraceProvider({
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-BU0UESs9.cjs';
2
+ import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-CSBzeGyK.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-BU0UESs9.mjs';
2
+ import { a as VedaTraceConfig, V as VedaTraceLoggerInterface, L as LogMetadata } from '../types-CSBzeGyK.mjs';
3
3
 
4
4
  /**
5
5
  * React integration for VedaTrace
@@ -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 '../transports/index.mjs';
4
+ import '../index-BcBZY8as.mjs';
5
5
 
6
6
  const VedaTraceContext = createContext(null);
7
7
  function VedaTraceProvider({
@@ -1,157 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const LEVEL_COLORS = {
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
- exports.VedaTraceConsoleTransport = VedaTraceConsoleTransport;
156
- exports.VedaTraceHttpTransport = VedaTraceHttpTransport;
157
- exports.VedaTraceHttpTransportBrowser = VedaTraceHttpTransportBrowser;
6
+
7
+ exports.VedaTraceConsoleTransport = transports_index.VedaTraceConsoleTransport;
8
+ exports.VedaTraceHttpTransport = transports_index.VedaTraceHttpTransport;
9
+ exports.VedaTraceHttpTransportBrowser = transports_index.VedaTraceHttpTransportBrowser;
@@ -1,4 +1,4 @@
1
- import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-BU0UESs9.cjs';
1
+ import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CSBzeGyK.cjs';
2
2
 
3
3
  /**
4
4
  * Console transport for development/debugging
@@ -34,8 +34,9 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
34
34
  *
35
35
  * Features:
36
36
  * - Timeout support with AbortController
37
- * - Retry on network failure
38
- * - Keepalive support for browser final flush
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
- /** Flush pending logs - called on page unload */
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-safe HTTP transport that uses keepalive for final flush
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,4 +1,4 @@
1
- import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-BU0UESs9.mjs';
1
+ import { e as VedaTraceLevel, b as VedaTraceTransport, I as InternalLogEntry } from '../types-CSBzeGyK.mjs';
2
2
 
3
3
  /**
4
4
  * Console transport for development/debugging
@@ -34,8 +34,9 @@ declare class VedaTraceConsoleTransport implements VedaTraceTransport {
34
34
  *
35
35
  * Features:
36
36
  * - Timeout support with AbortController
37
- * - Retry on network failure
38
- * - Keepalive support for browser final flush
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
- /** Flush pending logs - called on page unload */
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-safe HTTP transport that uses keepalive for final flush
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
- const LEVEL_COLORS = {
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';
@@ -42,6 +42,12 @@ interface VedaTraceConfig {
42
42
  runtime?: RuntimeType;
43
43
  /** Cloudflare Workers ExecutionContext - enables waitUntil support */
44
44
  executionContext?: VedaTraceEdgeContext;
45
+ /**
46
+ * Global waitUntil function (e.g. from "cloudflare:workers").
47
+ * When provided, the SDK uses the reliable debounced-flush+waitUntil path
48
+ * instead of fire-and-forget, ensuring logs complete before worker termination.
49
+ */
50
+ waitUntil?: (promise: Promise<unknown>) => void;
45
51
  }
46
52
  interface RedactionConfig {
47
53
  paths?: string[];
@@ -78,6 +84,8 @@ interface BatcherConfig {
78
84
  executionContext?: VedaTraceEdgeContext;
79
85
  onError?: (error: Error) => void;
80
86
  onSuccess?: () => void;
87
+ debug?: boolean;
88
+ waitUntil?: (promise: Promise<unknown>) => void;
81
89
  }
82
90
  interface VedaTraceLoggerInterface {
83
91
  debug(message: string, metadata?: LogMetadata): void;
@@ -42,6 +42,12 @@ interface VedaTraceConfig {
42
42
  runtime?: RuntimeType;
43
43
  /** Cloudflare Workers ExecutionContext - enables waitUntil support */
44
44
  executionContext?: VedaTraceEdgeContext;
45
+ /**
46
+ * Global waitUntil function (e.g. from "cloudflare:workers").
47
+ * When provided, the SDK uses the reliable debounced-flush+waitUntil path
48
+ * instead of fire-and-forget, ensuring logs complete before worker termination.
49
+ */
50
+ waitUntil?: (promise: Promise<unknown>) => void;
45
51
  }
46
52
  interface RedactionConfig {
47
53
  paths?: string[];
@@ -78,6 +84,8 @@ interface BatcherConfig {
78
84
  executionContext?: VedaTraceEdgeContext;
79
85
  onError?: (error: Error) => void;
80
86
  onSuccess?: () => void;
87
+ debug?: boolean;
88
+ waitUntil?: (promise: Promise<unknown>) => void;
81
89
  }
82
90
  interface VedaTraceLoggerInterface {
83
91
  debug(message: string, metadata?: LogMetadata): void;