@deeptracer/core 0.3.1 → 0.4.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/dist/{chunk-XVDM75HZ.js → chunk-YBQXVNNR.js} +154 -80
- package/dist/index.cjs +118 -46
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal.cjs +186 -48
- package/dist/internal.d.cts +66 -1
- package/dist/internal.d.ts +66 -1
- package/dist/internal.js +68 -3
- package/dist/{internal-DdKQRgCs.d.cts → logger-BDTEt7Gi.d.cts} +60 -23
- package/dist/{internal-DdKQRgCs.d.ts → logger-BDTEt7Gi.d.ts} +60 -23
- package/package.json +11 -3
|
@@ -1,32 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration for creating a DeepTracer logger instance.
|
|
3
3
|
*
|
|
4
|
+
* All fields are optional when environment variables are set.
|
|
5
|
+
* Server packages read `DEEPTRACER_SECRET_KEY`, `DEEPTRACER_ENDPOINT`, etc.
|
|
6
|
+
* Client packages read `NEXT_PUBLIC_DEEPTRACER_KEY`, `NEXT_PUBLIC_DEEPTRACER_ENDPOINT`, etc.
|
|
7
|
+
*
|
|
4
8
|
* @example
|
|
9
|
+
* Server (Node.js / Next.js instrumentation):
|
|
5
10
|
* ```ts
|
|
6
11
|
* const config: LoggerConfig = {
|
|
7
|
-
*
|
|
8
|
-
*
|
|
12
|
+
* secretKey: "dt_secret_xxx",
|
|
13
|
+
* endpoint: "https://deeptracer.example.com",
|
|
14
|
+
* service: "api",
|
|
9
15
|
* environment: "production",
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* Client (browser / React):
|
|
21
|
+
* ```ts
|
|
22
|
+
* const config: LoggerConfig = {
|
|
23
|
+
* publicKey: "dt_public_xxx",
|
|
10
24
|
* endpoint: "https://deeptracer.example.com",
|
|
11
|
-
* apiKey: "dt_live_xxx",
|
|
12
25
|
* }
|
|
13
26
|
* ```
|
|
14
27
|
*/
|
|
15
28
|
interface LoggerConfig {
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
29
|
+
/** Server-side API key (prefix: `dt_secret_`). Never expose in client bundles. */
|
|
30
|
+
secretKey?: string;
|
|
31
|
+
/** Client-side API key (prefix: `dt_public_`). Safe for browser bundles. */
|
|
32
|
+
publicKey?: string;
|
|
33
|
+
/** Service name (e.g., "api", "worker", "web"). Default varies by package. */
|
|
34
|
+
service?: string;
|
|
35
|
+
/** Deployment environment (any string). Default: `NODE_ENV` or `"production"` */
|
|
36
|
+
environment?: string;
|
|
22
37
|
/** DeepTracer ingestion endpoint URL */
|
|
23
|
-
endpoint
|
|
24
|
-
/** DeepTracer API key for authentication */
|
|
25
|
-
apiKey: string;
|
|
38
|
+
endpoint?: string;
|
|
26
39
|
/** Number of log entries to batch before sending. Default: 50 */
|
|
27
40
|
batchSize?: number;
|
|
28
41
|
/** Milliseconds between automatic batch flushes. Default: 5000 */
|
|
29
42
|
flushIntervalMs?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Minimum log level to send to DeepTracer.
|
|
45
|
+
*
|
|
46
|
+
* Logs below this level are silently filtered — they won't be batched or
|
|
47
|
+
* sent to the backend. Breadcrumbs are still recorded for filtered logs
|
|
48
|
+
* (so error reports retain full context).
|
|
49
|
+
*
|
|
50
|
+
* Default: `"info"` when `environment` is `"production"`, `"debug"` otherwise.
|
|
51
|
+
* Override via `DEEPTRACER_LOG_LEVEL` (server) or `NEXT_PUBLIC_DEEPTRACER_LOG_LEVEL` (client).
|
|
52
|
+
*/
|
|
53
|
+
level?: LogLevel;
|
|
30
54
|
/** Enable console output for all log calls (useful for local development) */
|
|
31
55
|
debug?: boolean;
|
|
32
56
|
/** Maximum breadcrumbs to retain for error reports. Default: 20 */
|
|
@@ -198,10 +222,10 @@ type BeforeSendEvent = {
|
|
|
198
222
|
};
|
|
199
223
|
|
|
200
224
|
/**
|
|
201
|
-
*
|
|
202
|
-
* The root Logger creates this; `withContext()` and `forRequest()`
|
|
203
|
-
*
|
|
204
|
-
*
|
|
225
|
+
* Mutable state for a Logger instance.
|
|
226
|
+
* The root Logger creates this; `withContext()` and `forRequest()` clone it
|
|
227
|
+
* so each child logger gets an independent snapshot. Mutations on a child
|
|
228
|
+
* (setUser, setTags, addBreadcrumb, etc.) do not affect the parent or siblings.
|
|
205
229
|
*/
|
|
206
230
|
interface LoggerState {
|
|
207
231
|
/** Current user context, set via setUser() */
|
|
@@ -216,6 +240,18 @@ interface LoggerState {
|
|
|
216
240
|
maxBreadcrumbs: number;
|
|
217
241
|
}
|
|
218
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Parse a W3C traceparent header.
|
|
245
|
+
* Format: `{version}-{trace-id}-{parent-id}-{trace-flags}`
|
|
246
|
+
* Example: `00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01`
|
|
247
|
+
*
|
|
248
|
+
* @returns Parsed components or `null` if the header is invalid.
|
|
249
|
+
*/
|
|
250
|
+
declare function parseTraceparent(header: string): {
|
|
251
|
+
traceId: string;
|
|
252
|
+
parentId: string;
|
|
253
|
+
flags: string;
|
|
254
|
+
} | null;
|
|
219
255
|
/**
|
|
220
256
|
* Original console methods, preserved before any interception.
|
|
221
257
|
* Used internally by the Logger's debug output to avoid infinite loops
|
|
@@ -238,11 +274,10 @@ declare const _originalConsole: {
|
|
|
238
274
|
* import { createLogger } from "@deeptracer/core"
|
|
239
275
|
*
|
|
240
276
|
* const logger = createLogger({
|
|
241
|
-
*
|
|
277
|
+
* secretKey: "dt_secret_xxx",
|
|
278
|
+
* endpoint: "https://deeptracer.example.com",
|
|
242
279
|
* service: "api",
|
|
243
280
|
* environment: "production",
|
|
244
|
-
* endpoint: "https://deeptracer.example.com",
|
|
245
|
-
* apiKey: "dt_live_xxx",
|
|
246
281
|
* })
|
|
247
282
|
*
|
|
248
283
|
* logger.setUser({ id: "u_123", email: "user@example.com" })
|
|
@@ -253,6 +288,7 @@ declare const _originalConsole: {
|
|
|
253
288
|
declare class Logger {
|
|
254
289
|
private batcher;
|
|
255
290
|
private transport;
|
|
291
|
+
private effectiveLevel;
|
|
256
292
|
protected contextName?: string;
|
|
257
293
|
protected config: LoggerConfig;
|
|
258
294
|
protected state: LoggerState;
|
|
@@ -270,7 +306,8 @@ declare class Logger {
|
|
|
270
306
|
}, state?: LoggerState);
|
|
271
307
|
/**
|
|
272
308
|
* Set the current user context. Attached to all subsequent logs, errors, spans, and LLM reports.
|
|
273
|
-
*
|
|
309
|
+
* Only affects this logger instance — child loggers created via `withContext()` or `forRequest()`
|
|
310
|
+
* have their own independent state.
|
|
274
311
|
*
|
|
275
312
|
* @example
|
|
276
313
|
* ```ts
|
|
@@ -331,9 +368,9 @@ declare class Logger {
|
|
|
331
368
|
warn(message: string, dataOrError?: Record<string, unknown> | unknown, error?: unknown): void;
|
|
332
369
|
/** Log an error. */
|
|
333
370
|
error(message: string, dataOrError?: Record<string, unknown> | unknown, error?: unknown): void;
|
|
334
|
-
/** Create a context-scoped logger. All logs include the context name.
|
|
371
|
+
/** Create a context-scoped logger. All logs include the context name. Gets an independent copy of state. */
|
|
335
372
|
withContext(name: string): Logger;
|
|
336
|
-
/** Create a request-scoped logger that extracts trace context from headers.
|
|
373
|
+
/** Create a request-scoped logger that extracts trace context from headers. Gets an independent copy of state. */
|
|
337
374
|
forRequest(request: Request): Logger;
|
|
338
375
|
/**
|
|
339
376
|
* Capture and report an error immediately (not batched).
|
|
@@ -372,4 +409,4 @@ declare class Logger {
|
|
|
372
409
|
/** Create a new DeepTracer logger instance. */
|
|
373
410
|
declare function createLogger(config: LoggerConfig): Logger;
|
|
374
411
|
|
|
375
|
-
export { type BeforeSendEvent as B, type ErrorReport as E, type InactiveSpan as I, type LLMUsageReport as L, type MiddlewareOptions as M, type Span as S, type User as U, _originalConsole as _, type Breadcrumb as a, type LogEntry as b, type LogLevel as c, Logger as d, type LoggerConfig as e, type SpanData as f, createLogger as g, type LoggerState as h };
|
|
412
|
+
export { type BeforeSendEvent as B, type ErrorReport as E, type InactiveSpan as I, type LLMUsageReport as L, type MiddlewareOptions as M, type Span as S, type User as U, _originalConsole as _, type Breadcrumb as a, type LogEntry as b, type LogLevel as c, Logger as d, type LoggerConfig as e, type SpanData as f, createLogger as g, type LoggerState as h, parseTraceparent as p };
|
|
@@ -1,32 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration for creating a DeepTracer logger instance.
|
|
3
3
|
*
|
|
4
|
+
* All fields are optional when environment variables are set.
|
|
5
|
+
* Server packages read `DEEPTRACER_SECRET_KEY`, `DEEPTRACER_ENDPOINT`, etc.
|
|
6
|
+
* Client packages read `NEXT_PUBLIC_DEEPTRACER_KEY`, `NEXT_PUBLIC_DEEPTRACER_ENDPOINT`, etc.
|
|
7
|
+
*
|
|
4
8
|
* @example
|
|
9
|
+
* Server (Node.js / Next.js instrumentation):
|
|
5
10
|
* ```ts
|
|
6
11
|
* const config: LoggerConfig = {
|
|
7
|
-
*
|
|
8
|
-
*
|
|
12
|
+
* secretKey: "dt_secret_xxx",
|
|
13
|
+
* endpoint: "https://deeptracer.example.com",
|
|
14
|
+
* service: "api",
|
|
9
15
|
* environment: "production",
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* Client (browser / React):
|
|
21
|
+
* ```ts
|
|
22
|
+
* const config: LoggerConfig = {
|
|
23
|
+
* publicKey: "dt_public_xxx",
|
|
10
24
|
* endpoint: "https://deeptracer.example.com",
|
|
11
|
-
* apiKey: "dt_live_xxx",
|
|
12
25
|
* }
|
|
13
26
|
* ```
|
|
14
27
|
*/
|
|
15
28
|
interface LoggerConfig {
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
29
|
+
/** Server-side API key (prefix: `dt_secret_`). Never expose in client bundles. */
|
|
30
|
+
secretKey?: string;
|
|
31
|
+
/** Client-side API key (prefix: `dt_public_`). Safe for browser bundles. */
|
|
32
|
+
publicKey?: string;
|
|
33
|
+
/** Service name (e.g., "api", "worker", "web"). Default varies by package. */
|
|
34
|
+
service?: string;
|
|
35
|
+
/** Deployment environment (any string). Default: `NODE_ENV` or `"production"` */
|
|
36
|
+
environment?: string;
|
|
22
37
|
/** DeepTracer ingestion endpoint URL */
|
|
23
|
-
endpoint
|
|
24
|
-
/** DeepTracer API key for authentication */
|
|
25
|
-
apiKey: string;
|
|
38
|
+
endpoint?: string;
|
|
26
39
|
/** Number of log entries to batch before sending. Default: 50 */
|
|
27
40
|
batchSize?: number;
|
|
28
41
|
/** Milliseconds between automatic batch flushes. Default: 5000 */
|
|
29
42
|
flushIntervalMs?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Minimum log level to send to DeepTracer.
|
|
45
|
+
*
|
|
46
|
+
* Logs below this level are silently filtered — they won't be batched or
|
|
47
|
+
* sent to the backend. Breadcrumbs are still recorded for filtered logs
|
|
48
|
+
* (so error reports retain full context).
|
|
49
|
+
*
|
|
50
|
+
* Default: `"info"` when `environment` is `"production"`, `"debug"` otherwise.
|
|
51
|
+
* Override via `DEEPTRACER_LOG_LEVEL` (server) or `NEXT_PUBLIC_DEEPTRACER_LOG_LEVEL` (client).
|
|
52
|
+
*/
|
|
53
|
+
level?: LogLevel;
|
|
30
54
|
/** Enable console output for all log calls (useful for local development) */
|
|
31
55
|
debug?: boolean;
|
|
32
56
|
/** Maximum breadcrumbs to retain for error reports. Default: 20 */
|
|
@@ -198,10 +222,10 @@ type BeforeSendEvent = {
|
|
|
198
222
|
};
|
|
199
223
|
|
|
200
224
|
/**
|
|
201
|
-
*
|
|
202
|
-
* The root Logger creates this; `withContext()` and `forRequest()`
|
|
203
|
-
*
|
|
204
|
-
*
|
|
225
|
+
* Mutable state for a Logger instance.
|
|
226
|
+
* The root Logger creates this; `withContext()` and `forRequest()` clone it
|
|
227
|
+
* so each child logger gets an independent snapshot. Mutations on a child
|
|
228
|
+
* (setUser, setTags, addBreadcrumb, etc.) do not affect the parent or siblings.
|
|
205
229
|
*/
|
|
206
230
|
interface LoggerState {
|
|
207
231
|
/** Current user context, set via setUser() */
|
|
@@ -216,6 +240,18 @@ interface LoggerState {
|
|
|
216
240
|
maxBreadcrumbs: number;
|
|
217
241
|
}
|
|
218
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Parse a W3C traceparent header.
|
|
245
|
+
* Format: `{version}-{trace-id}-{parent-id}-{trace-flags}`
|
|
246
|
+
* Example: `00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01`
|
|
247
|
+
*
|
|
248
|
+
* @returns Parsed components or `null` if the header is invalid.
|
|
249
|
+
*/
|
|
250
|
+
declare function parseTraceparent(header: string): {
|
|
251
|
+
traceId: string;
|
|
252
|
+
parentId: string;
|
|
253
|
+
flags: string;
|
|
254
|
+
} | null;
|
|
219
255
|
/**
|
|
220
256
|
* Original console methods, preserved before any interception.
|
|
221
257
|
* Used internally by the Logger's debug output to avoid infinite loops
|
|
@@ -238,11 +274,10 @@ declare const _originalConsole: {
|
|
|
238
274
|
* import { createLogger } from "@deeptracer/core"
|
|
239
275
|
*
|
|
240
276
|
* const logger = createLogger({
|
|
241
|
-
*
|
|
277
|
+
* secretKey: "dt_secret_xxx",
|
|
278
|
+
* endpoint: "https://deeptracer.example.com",
|
|
242
279
|
* service: "api",
|
|
243
280
|
* environment: "production",
|
|
244
|
-
* endpoint: "https://deeptracer.example.com",
|
|
245
|
-
* apiKey: "dt_live_xxx",
|
|
246
281
|
* })
|
|
247
282
|
*
|
|
248
283
|
* logger.setUser({ id: "u_123", email: "user@example.com" })
|
|
@@ -253,6 +288,7 @@ declare const _originalConsole: {
|
|
|
253
288
|
declare class Logger {
|
|
254
289
|
private batcher;
|
|
255
290
|
private transport;
|
|
291
|
+
private effectiveLevel;
|
|
256
292
|
protected contextName?: string;
|
|
257
293
|
protected config: LoggerConfig;
|
|
258
294
|
protected state: LoggerState;
|
|
@@ -270,7 +306,8 @@ declare class Logger {
|
|
|
270
306
|
}, state?: LoggerState);
|
|
271
307
|
/**
|
|
272
308
|
* Set the current user context. Attached to all subsequent logs, errors, spans, and LLM reports.
|
|
273
|
-
*
|
|
309
|
+
* Only affects this logger instance — child loggers created via `withContext()` or `forRequest()`
|
|
310
|
+
* have their own independent state.
|
|
274
311
|
*
|
|
275
312
|
* @example
|
|
276
313
|
* ```ts
|
|
@@ -331,9 +368,9 @@ declare class Logger {
|
|
|
331
368
|
warn(message: string, dataOrError?: Record<string, unknown> | unknown, error?: unknown): void;
|
|
332
369
|
/** Log an error. */
|
|
333
370
|
error(message: string, dataOrError?: Record<string, unknown> | unknown, error?: unknown): void;
|
|
334
|
-
/** Create a context-scoped logger. All logs include the context name.
|
|
371
|
+
/** Create a context-scoped logger. All logs include the context name. Gets an independent copy of state. */
|
|
335
372
|
withContext(name: string): Logger;
|
|
336
|
-
/** Create a request-scoped logger that extracts trace context from headers.
|
|
373
|
+
/** Create a request-scoped logger that extracts trace context from headers. Gets an independent copy of state. */
|
|
337
374
|
forRequest(request: Request): Logger;
|
|
338
375
|
/**
|
|
339
376
|
* Capture and report an error immediately (not batched).
|
|
@@ -372,4 +409,4 @@ declare class Logger {
|
|
|
372
409
|
/** Create a new DeepTracer logger instance. */
|
|
373
410
|
declare function createLogger(config: LoggerConfig): Logger;
|
|
374
411
|
|
|
375
|
-
export { type BeforeSendEvent as B, type ErrorReport as E, type InactiveSpan as I, type LLMUsageReport as L, type MiddlewareOptions as M, type Span as S, type User as U, _originalConsole as _, type Breadcrumb as a, type LogEntry as b, type LogLevel as c, Logger as d, type LoggerConfig as e, type SpanData as f, createLogger as g, type LoggerState as h };
|
|
412
|
+
export { type BeforeSendEvent as B, type ErrorReport as E, type InactiveSpan as I, type LLMUsageReport as L, type MiddlewareOptions as M, type Span as S, type User as U, _originalConsole as _, type Breadcrumb as a, type LogEntry as b, type LogLevel as c, Logger as d, type LoggerConfig as e, type SpanData as f, createLogger as g, type LoggerState as h, parseTraceparent as p };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deeptracer/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Core SDK for DeepTracer — Logger class, types, transport, batcher, tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -18,9 +18,17 @@
|
|
|
18
18
|
"require": "./dist/internal.cjs"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
"files": [
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
22
25
|
"sideEffects": false,
|
|
23
|
-
"keywords": [
|
|
26
|
+
"keywords": [
|
|
27
|
+
"logging",
|
|
28
|
+
"observability",
|
|
29
|
+
"tracing",
|
|
30
|
+
"deeptracer"
|
|
31
|
+
],
|
|
24
32
|
"repository": {
|
|
25
33
|
"type": "git",
|
|
26
34
|
"url": "https://github.com/getdeeptracer/deeptracer-js.git",
|