@deeptracer/core 0.6.3 → 0.7.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/README.md CHANGED
@@ -74,7 +74,7 @@ const result = await logger.startSpan("fetch-user", async (span) => {
74
74
  })
75
75
 
76
76
  // Flush before shutdown
77
- logger.destroy()
77
+ await logger.destroy()
78
78
  ```
79
79
 
80
80
  ## Configuration
@@ -424,8 +424,8 @@ await logger.flush()
424
424
  Stop the internal batch timer and flush any remaining log entries. Call this during graceful shutdown.
425
425
 
426
426
  ```ts
427
- process.on("SIGTERM", () => {
428
- logger.destroy()
427
+ process.on("SIGTERM", async () => {
428
+ await logger.destroy()
429
429
  process.exit(0)
430
430
  })
431
431
  ```
@@ -580,7 +580,7 @@ In serverless functions, the execution context may freeze immediately after the
580
580
  - **Auto-detected interval**: When `VERCEL` or `AWS_LAMBDA_FUNCTION_NAME` is set, the default `flushIntervalMs` drops to 200ms.
581
581
  - **Explicit flush**: Call `await logger.flush()` before returning a response to guarantee delivery.
582
582
 
583
- For third-party route handlers you can't wrap (e.g. Auth.js, Stripe webhooks), use Vercel's `waitUntil` to extend the function lifetime:
583
+ For **`@deeptracer/nextjs`** users, `withRouteHandler` works with any handler function including third-party ones (Auth.js, Better Auth, Stripe webhooks) — just wrap the exported handler. Only use `waitUntil` if the library doesn't export individual `GET`/`POST` functions:
584
584
 
585
585
  ```ts
586
586
  import { waitUntil } from "@vercel/functions"
@@ -608,7 +608,7 @@ All requests include:
608
608
  - `Content-Type: application/json` header
609
609
  - `service` and `environment` fields in the JSON body
610
610
 
611
- If a request fails, a warning is logged to the console. The SDK does not retry failed requests -- it is designed to be non-blocking and never crash your application.
611
+ If a request fails with a network error or a 5xx response, the SDK retries up to **3 times** with exponential backoff (1s → 2s → 4s, +20% jitter). 4xx errors (bad auth, invalid payload) are not retried. After all retries are exhausted, a single warning is logged to the console subsequent failures for the same endpoint are suppressed to avoid console spam. The SDK never throws on transport errors.
612
612
 
613
613
  ## Monorepo
614
614
 
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "0.6.3";
2
+ var SDK_VERSION = "0.7.0";
3
3
  var SDK_NAME = "core";
4
4
 
5
5
  // src/transport.ts
@@ -99,6 +99,7 @@ var Transport = class {
99
99
  track(promise) {
100
100
  this.inFlightRequests.add(promise);
101
101
  promise.finally(() => this.inFlightRequests.delete(promise));
102
+ this.config.waitUntil?.(promise);
102
103
  }
103
104
  async sendLogs(logs) {
104
105
  const p = this.sendWithRetry(
package/dist/index.cjs CHANGED
@@ -64,7 +64,7 @@ var Batcher = class {
64
64
  };
65
65
 
66
66
  // src/version.ts
67
- var SDK_VERSION = "0.6.3";
67
+ var SDK_VERSION = "0.7.0";
68
68
  var SDK_NAME = "core";
69
69
 
70
70
  // src/transport.ts
@@ -164,6 +164,7 @@ var Transport = class {
164
164
  track(promise) {
165
165
  this.inFlightRequests.add(promise);
166
166
  promise.finally(() => this.inFlightRequests.delete(promise));
167
+ this.config.waitUntil?.(promise);
167
168
  }
168
169
  async sendLogs(logs) {
169
170
  const p = this.sendWithRetry(
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as Logger } from './logger-DyJENLNA.cjs';
2
- export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveSpan, b as LLMUsageReport, c as LogEntry, d as LogLevel, e as LoggerConfig, M as MiddlewareOptions, S as Span, f as SpanData, U as User, g as createLogger } from './logger-DyJENLNA.cjs';
1
+ import { L as Logger } from './logger-DnaUqfFI.cjs';
2
+ export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveSpan, b as LLMUsageReport, c as LogEntry, d as LogLevel, e as LoggerConfig, M as MiddlewareOptions, S as Span, f as SpanData, U as User, g as createLogger } from './logger-DnaUqfFI.cjs';
3
3
 
4
4
  /**
5
5
  * A Logger-compatible object where every method is a silent no-op.
@@ -18,7 +18,7 @@ export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveS
18
18
  declare const noopLogger: Logger;
19
19
 
20
20
  /** SDK version. Update on each release. */
21
- declare const SDK_VERSION = "0.6.3";
21
+ declare const SDK_VERSION = "0.7.0";
22
22
  declare const SDK_NAME = "core";
23
23
 
24
24
  export { Logger, SDK_NAME, SDK_VERSION, noopLogger };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as Logger } from './logger-DyJENLNA.js';
2
- export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveSpan, b as LLMUsageReport, c as LogEntry, d as LogLevel, e as LoggerConfig, M as MiddlewareOptions, S as Span, f as SpanData, U as User, g as createLogger } from './logger-DyJENLNA.js';
1
+ import { L as Logger } from './logger-DnaUqfFI.js';
2
+ export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveSpan, b as LLMUsageReport, c as LogEntry, d as LogLevel, e as LoggerConfig, M as MiddlewareOptions, S as Span, f as SpanData, U as User, g as createLogger } from './logger-DnaUqfFI.js';
3
3
 
4
4
  /**
5
5
  * A Logger-compatible object where every method is a silent no-op.
@@ -18,7 +18,7 @@ export { B as BeforeSendEvent, a as Breadcrumb, E as ErrorReport, I as InactiveS
18
18
  declare const noopLogger: Logger;
19
19
 
20
20
  /** SDK version. Update on each release. */
21
- declare const SDK_VERSION = "0.6.3";
21
+ declare const SDK_VERSION = "0.7.0";
22
22
  declare const SDK_NAME = "core";
23
23
 
24
24
  export { Logger, SDK_NAME, SDK_VERSION, noopLogger };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  SDK_NAME,
4
4
  SDK_VERSION,
5
5
  createLogger
6
- } from "./chunk-W62R346F.js";
6
+ } from "./chunk-POYXPAC5.js";
7
7
 
8
8
  // src/noop-logger.ts
9
9
  var NOOP_INACTIVE_SPAN = {
package/dist/internal.cjs CHANGED
@@ -64,7 +64,7 @@ var Batcher = class {
64
64
  };
65
65
 
66
66
  // src/version.ts
67
- var SDK_VERSION = "0.6.3";
67
+ var SDK_VERSION = "0.7.0";
68
68
  var SDK_NAME = "core";
69
69
 
70
70
  // src/transport.ts
@@ -164,6 +164,7 @@ var Transport = class {
164
164
  track(promise) {
165
165
  this.inFlightRequests.add(promise);
166
166
  promise.finally(() => this.inFlightRequests.delete(promise));
167
+ this.config.waitUntil?.(promise);
167
168
  }
168
169
  async sendLogs(logs) {
169
170
  const p = this.sendWithRetry(
@@ -1,4 +1,4 @@
1
- export { L as Logger, e as LoggerConfig, h as LoggerState, M as MiddlewareOptions, T as Transport, _ as _originalConsole, p as parseTraceparent } from './logger-DyJENLNA.cjs';
1
+ export { L as Logger, e as LoggerConfig, h as LoggerState, M as MiddlewareOptions, T as Transport, _ as _originalConsole, p as parseTraceparent } from './logger-DnaUqfFI.cjs';
2
2
 
3
3
  /**
4
4
  * Parse console.log/info/warn/error arguments into a structured `{ message, metadata }` pair.
@@ -1,4 +1,4 @@
1
- export { L as Logger, e as LoggerConfig, h as LoggerState, M as MiddlewareOptions, T as Transport, _ as _originalConsole, p as parseTraceparent } from './logger-DyJENLNA.js';
1
+ export { L as Logger, e as LoggerConfig, h as LoggerState, M as MiddlewareOptions, T as Transport, _ as _originalConsole, p as parseTraceparent } from './logger-DnaUqfFI.js';
2
2
 
3
3
  /**
4
4
  * Parse console.log/info/warn/error arguments into a structured `{ message, metadata }` pair.
package/dist/internal.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Transport,
4
4
  _originalConsole,
5
5
  parseTraceparent
6
- } from "./chunk-W62R346F.js";
6
+ } from "./chunk-POYXPAC5.js";
7
7
 
8
8
  // src/internal.ts
9
9
  function safeStringify(value) {
@@ -63,6 +63,28 @@ interface LoggerConfig {
63
63
  * ```
64
64
  */
65
65
  beforeSend?: (event: BeforeSendEvent) => BeforeSendEvent | null;
66
+ /**
67
+ * Called with each outgoing HTTP request promise when the transport sends data.
68
+ * Use this to keep a serverless function alive until all in-flight requests
69
+ * complete — even for logs written after the HTTP response has been returned
70
+ * (e.g., from Better Auth background task callbacks or other post-response work).
71
+ *
72
+ * On Vercel this is wired up automatically by `@deeptracer/nextjs`.
73
+ * On Cloudflare Workers, pass `ctx.waitUntil.bind(ctx)` when creating the logger.
74
+ * On persistent servers (Railway, Fly, Docker) you don't need this — the process
75
+ * stays alive and the timer-based flush handles it.
76
+ *
77
+ * @example Cloudflare Workers
78
+ * ```ts
79
+ * export default {
80
+ * async fetch(request, env, ctx) {
81
+ * const logger = createLogger({ waitUntil: ctx.waitUntil.bind(ctx), ... })
82
+ * // logs are now kept alive past the response
83
+ * }
84
+ * }
85
+ * ```
86
+ */
87
+ waitUntil?: (promise: Promise<unknown>) => void;
66
88
  }
67
89
  /** Log severity level */
68
90
  type LogLevel = "debug" | "info" | "warn" | "error";
@@ -254,7 +276,7 @@ declare class Transport {
254
276
  * (e.g., when the ingestion endpoint is unreachable during development).
255
277
  */
256
278
  private warnedLabels;
257
- constructor(config: Pick<LoggerConfig, "endpoint" | "apiKey" | "service" | "environment">);
279
+ constructor(config: Pick<LoggerConfig, "endpoint" | "apiKey" | "service" | "environment" | "waitUntil">);
258
280
  private get authKey();
259
281
  /**
260
282
  * Send a request with automatic retry and exponential backoff.
@@ -63,6 +63,28 @@ interface LoggerConfig {
63
63
  * ```
64
64
  */
65
65
  beforeSend?: (event: BeforeSendEvent) => BeforeSendEvent | null;
66
+ /**
67
+ * Called with each outgoing HTTP request promise when the transport sends data.
68
+ * Use this to keep a serverless function alive until all in-flight requests
69
+ * complete — even for logs written after the HTTP response has been returned
70
+ * (e.g., from Better Auth background task callbacks or other post-response work).
71
+ *
72
+ * On Vercel this is wired up automatically by `@deeptracer/nextjs`.
73
+ * On Cloudflare Workers, pass `ctx.waitUntil.bind(ctx)` when creating the logger.
74
+ * On persistent servers (Railway, Fly, Docker) you don't need this — the process
75
+ * stays alive and the timer-based flush handles it.
76
+ *
77
+ * @example Cloudflare Workers
78
+ * ```ts
79
+ * export default {
80
+ * async fetch(request, env, ctx) {
81
+ * const logger = createLogger({ waitUntil: ctx.waitUntil.bind(ctx), ... })
82
+ * // logs are now kept alive past the response
83
+ * }
84
+ * }
85
+ * ```
86
+ */
87
+ waitUntil?: (promise: Promise<unknown>) => void;
66
88
  }
67
89
  /** Log severity level */
68
90
  type LogLevel = "debug" | "info" | "warn" | "error";
@@ -254,7 +276,7 @@ declare class Transport {
254
276
  * (e.g., when the ingestion endpoint is unreachable during development).
255
277
  */
256
278
  private warnedLabels;
257
- constructor(config: Pick<LoggerConfig, "endpoint" | "apiKey" | "service" | "environment">);
279
+ constructor(config: Pick<LoggerConfig, "endpoint" | "apiKey" | "service" | "environment" | "waitUntil">);
258
280
  private get authKey();
259
281
  /**
260
282
  * Send a request with automatic retry and exponential backoff.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deeptracer/core",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "description": "Core SDK for DeepTracer — Logger class, types, transport, batcher, tracing",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",