evlog 1.6.0 → 1.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.
Files changed (104) hide show
  1. package/README.md +95 -0
  2. package/dist/_utils-DZA9nou3.mjs +23 -0
  3. package/dist/_utils-DZA9nou3.mjs.map +1 -0
  4. package/dist/adapters/axiom.d.mts +16 -15
  5. package/dist/adapters/axiom.d.mts.map +1 -0
  6. package/dist/adapters/axiom.mjs +95 -50
  7. package/dist/adapters/axiom.mjs.map +1 -0
  8. package/dist/adapters/better-stack.d.mts +62 -0
  9. package/dist/adapters/better-stack.d.mts.map +1 -0
  10. package/dist/adapters/better-stack.mjs +109 -0
  11. package/dist/adapters/better-stack.mjs.map +1 -0
  12. package/dist/adapters/otlp.d.mts +31 -30
  13. package/dist/adapters/otlp.d.mts.map +1 -0
  14. package/dist/adapters/otlp.mjs +197 -177
  15. package/dist/adapters/otlp.mjs.map +1 -0
  16. package/dist/adapters/posthog.d.mts +20 -19
  17. package/dist/adapters/posthog.d.mts.map +1 -0
  18. package/dist/adapters/posthog.mjs +109 -62
  19. package/dist/adapters/posthog.mjs.map +1 -0
  20. package/dist/adapters/sentry.d.mts +24 -23
  21. package/dist/adapters/sentry.d.mts.map +1 -0
  22. package/dist/adapters/sentry.mjs +208 -151
  23. package/dist/adapters/sentry.mjs.map +1 -0
  24. package/dist/enrichers.d.mts +74 -0
  25. package/dist/enrichers.d.mts.map +1 -0
  26. package/dist/enrichers.mjs +172 -0
  27. package/dist/enrichers.mjs.map +1 -0
  28. package/dist/error.d.mts +24 -22
  29. package/dist/error.d.mts.map +1 -0
  30. package/dist/error.mjs +107 -76
  31. package/dist/error.mjs.map +1 -0
  32. package/dist/index.d.mts +6 -5
  33. package/dist/index.mjs +6 -5
  34. package/dist/logger.d.mts +5 -3
  35. package/dist/logger.d.mts.map +1 -0
  36. package/dist/logger.mjs +200 -184
  37. package/dist/logger.mjs.map +1 -0
  38. package/dist/nitro/errorHandler.d.mts +4 -2
  39. package/dist/nitro/errorHandler.d.mts.map +1 -0
  40. package/dist/nitro/errorHandler.mjs +49 -38
  41. package/dist/nitro/errorHandler.mjs.map +1 -0
  42. package/dist/nitro/plugin.d.mts +4 -2
  43. package/dist/nitro/plugin.d.mts.map +1 -0
  44. package/dist/nitro/plugin.mjs +155 -136
  45. package/dist/nitro/plugin.mjs.map +1 -0
  46. package/dist/nuxt/module.d.mts +149 -168
  47. package/dist/nuxt/module.d.mts.map +1 -0
  48. package/dist/nuxt/module.mjs +66 -65
  49. package/dist/nuxt/module.mjs.map +1 -0
  50. package/dist/pipeline.d.mts +46 -0
  51. package/dist/pipeline.d.mts.map +1 -0
  52. package/dist/pipeline.mjs +122 -0
  53. package/dist/pipeline.mjs.map +1 -0
  54. package/dist/runtime/client/log.d.mts +7 -5
  55. package/dist/runtime/client/log.d.mts.map +1 -0
  56. package/dist/runtime/client/log.mjs +57 -62
  57. package/dist/runtime/client/log.mjs.map +1 -0
  58. package/dist/runtime/client/plugin.d.mts +3 -1
  59. package/dist/runtime/client/plugin.d.mts.map +1 -0
  60. package/dist/runtime/client/plugin.mjs +13 -12
  61. package/dist/runtime/client/plugin.mjs.map +1 -0
  62. package/dist/runtime/server/routes/_evlog/ingest.post.d.mts +4 -2
  63. package/dist/runtime/server/routes/_evlog/ingest.post.d.mts.map +1 -0
  64. package/dist/runtime/server/routes/_evlog/ingest.post.mjs +113 -76
  65. package/dist/runtime/server/routes/_evlog/ingest.post.mjs.map +1 -0
  66. package/dist/runtime/server/useLogger.d.mts +14 -3
  67. package/dist/runtime/server/useLogger.d.mts.map +1 -0
  68. package/dist/runtime/server/useLogger.mjs +39 -10
  69. package/dist/runtime/server/useLogger.mjs.map +1 -0
  70. package/dist/runtime/utils/parseError.d.mts +5 -3
  71. package/dist/runtime/utils/parseError.d.mts.map +1 -0
  72. package/dist/runtime/utils/parseError.mjs +25 -26
  73. package/dist/runtime/utils/parseError.mjs.map +1 -0
  74. package/dist/types.d.mts +348 -246
  75. package/dist/types.d.mts.map +1 -0
  76. package/dist/types.mjs +1 -1
  77. package/dist/utils.d.mts +19 -14
  78. package/dist/utils.d.mts.map +1 -0
  79. package/dist/utils.mjs +59 -50
  80. package/dist/utils.mjs.map +1 -0
  81. package/dist/workers.d.mts +10 -9
  82. package/dist/workers.d.mts.map +1 -0
  83. package/dist/workers.mjs +68 -39
  84. package/dist/workers.mjs.map +1 -0
  85. package/package.json +26 -5
  86. package/dist/adapters/axiom.d.ts +0 -62
  87. package/dist/adapters/otlp.d.ts +0 -83
  88. package/dist/adapters/posthog.d.ts +0 -72
  89. package/dist/adapters/sentry.d.ts +0 -78
  90. package/dist/error.d.ts +0 -63
  91. package/dist/index.d.ts +0 -5
  92. package/dist/logger.d.ts +0 -40
  93. package/dist/nitro/errorHandler.d.ts +0 -13
  94. package/dist/nitro/plugin.d.ts +0 -5
  95. package/dist/nuxt/module.d.ts +0 -171
  96. package/dist/runtime/client/log.d.ts +0 -10
  97. package/dist/runtime/client/plugin.d.ts +0 -3
  98. package/dist/runtime/server/routes/_evlog/ingest.post.d.ts +0 -5
  99. package/dist/runtime/server/useLogger.d.ts +0 -28
  100. package/dist/runtime/utils/parseError.d.ts +0 -5
  101. package/dist/shared/evlog.Bc35pxiY.mjs +0 -10
  102. package/dist/types.d.ts +0 -364
  103. package/dist/utils.d.ts +0 -29
  104. package/dist/workers.d.ts +0 -45
@@ -1,78 +0,0 @@
1
- import { DrainContext, WideEvent } from '../types.js';
2
-
3
- interface SentryConfig {
4
- /** Sentry DSN */
5
- dsn: string;
6
- /** Environment override (defaults to event.environment) */
7
- environment?: string;
8
- /** Release version override (defaults to event.version) */
9
- release?: string;
10
- /** Additional tags to attach as attributes */
11
- tags?: Record<string, string>;
12
- /** Request timeout in milliseconds. Default: 5000 */
13
- timeout?: number;
14
- }
15
- /** Sentry Log attribute value with type annotation */
16
- interface SentryAttributeValue {
17
- value: string | number | boolean;
18
- type: 'string' | 'integer' | 'double' | 'boolean';
19
- }
20
- /** Sentry Structured Log payload */
21
- interface SentryLog {
22
- timestamp: number;
23
- trace_id: string;
24
- level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
25
- body: string;
26
- severity_number: number;
27
- attributes?: Record<string, SentryAttributeValue>;
28
- }
29
- declare function toSentryLog(event: WideEvent, config: SentryConfig): SentryLog;
30
- /**
31
- * Create a drain function for sending logs to Sentry.
32
- *
33
- * Sends wide events as Sentry Structured Logs, visible in Explore > Logs
34
- * in the Sentry dashboard.
35
- *
36
- * Configuration priority (highest to lowest):
37
- * 1. Overrides passed to createSentryDrain()
38
- * 2. runtimeConfig.evlog.sentry
39
- * 3. runtimeConfig.sentry
40
- * 4. Environment variables: NUXT_SENTRY_*, SENTRY_*
41
- *
42
- * @example
43
- * ```ts
44
- * // Zero config - just set NUXT_SENTRY_DSN env var
45
- * nitroApp.hooks.hook('evlog:drain', createSentryDrain())
46
- *
47
- * // With overrides
48
- * nitroApp.hooks.hook('evlog:drain', createSentryDrain({
49
- * dsn: 'https://public@o0.ingest.sentry.io/123',
50
- * }))
51
- * ```
52
- */
53
- declare function createSentryDrain(overrides?: Partial<SentryConfig>): (ctx: DrainContext) => Promise<void>;
54
- /**
55
- * Send a single event to Sentry as a structured log.
56
- *
57
- * @example
58
- * ```ts
59
- * await sendToSentry(event, {
60
- * dsn: process.env.SENTRY_DSN!,
61
- * })
62
- * ```
63
- */
64
- declare function sendToSentry(event: WideEvent, config: SentryConfig): Promise<void>;
65
- /**
66
- * Send a batch of events to Sentry as structured logs via the Envelope endpoint.
67
- *
68
- * @example
69
- * ```ts
70
- * await sendBatchToSentry(events, {
71
- * dsn: process.env.SENTRY_DSN!,
72
- * })
73
- * ```
74
- */
75
- declare function sendBatchToSentry(events: WideEvent[], config: SentryConfig): Promise<void>;
76
-
77
- export { createSentryDrain, sendBatchToSentry, sendToSentry, toSentryLog };
78
- export type { SentryAttributeValue, SentryConfig, SentryLog };
package/dist/error.d.ts DELETED
@@ -1,63 +0,0 @@
1
- import { ErrorOptions } from './types.js';
2
-
3
- /**
4
- * Structured error with context for better debugging
5
- *
6
- * @example
7
- * ```ts
8
- * throw new EvlogError({
9
- * message: 'Failed to sync repository',
10
- * status: 503,
11
- * why: 'GitHub API rate limit exceeded',
12
- * fix: 'Wait 1 hour or use a different token',
13
- * link: 'https://docs.github.com/en/rest/rate-limit',
14
- * cause: originalError,
15
- * })
16
- * ```
17
- */
18
- declare class EvlogError extends Error {
19
- /** HTTP status code */
20
- readonly status: number;
21
- readonly why?: string;
22
- readonly fix?: string;
23
- readonly link?: string;
24
- constructor(options: ErrorOptions | string);
25
- /** HTTP status text (alias for message) */
26
- get statusText(): string;
27
- /** HTTP status code (alias for compatibility) */
28
- get statusCode(): number;
29
- /** HTTP status message (alias for compatibility) */
30
- get statusMessage(): string;
31
- /** Structured data for serialization */
32
- get data(): {
33
- why?: string;
34
- fix?: string;
35
- link?: string;
36
- } | undefined;
37
- toString(): string;
38
- toJSON(): Record<string, unknown>;
39
- }
40
- /**
41
- * Create a structured error with context for debugging and user-facing messages.
42
- *
43
- * @param options - Error message string or full options object
44
- * @returns EvlogError with HTTP metadata (`status`, `statusText`) and `data`; also includes `statusCode` and `statusMessage` for legacy compatibility
45
- *
46
- * @example
47
- * ```ts
48
- * // Simple error
49
- * throw createError('Something went wrong')
50
- *
51
- * // Structured error with context
52
- * throw createError({
53
- * message: 'Payment failed',
54
- * status: 402,
55
- * why: 'Card declined by issuer',
56
- * fix: 'Try a different payment method',
57
- * link: 'https://docs.example.com/payments',
58
- * })
59
- * ```
60
- */
61
- declare function createError(options: ErrorOptions | string): EvlogError;
62
-
63
- export { EvlogError, createError, createError as createEvlogError };
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { EvlogError, createError, createError as createEvlogError } from './error.js';
2
- export { createRequestLogger, getEnvironment, initLogger, log, shouldKeep } from './logger.js';
3
- export { useLogger } from './runtime/server/useLogger.js';
4
- export { parseError } from './runtime/utils/parseError.js';
5
- export { BaseWideEvent, DrainContext, EnvironmentContext, ErrorOptions, H3EventContext, IngestPayload, Log, LogLevel, LoggerConfig, ParsedError, RequestLogger, RequestLoggerOptions, SamplingConfig, SamplingRates, ServerEvent, TailSamplingCondition, TailSamplingContext, TransportConfig, WideEvent } from './types.js';
package/dist/logger.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { RequestLoggerOptions, RequestLogger, EnvironmentContext, LoggerConfig, Log, TailSamplingContext } from './types.js';
2
-
3
- /**
4
- * Initialize the logger with configuration.
5
- * Call this once at application startup.
6
- */
7
- declare function initLogger(config?: LoggerConfig): void;
8
- /**
9
- * Evaluate tail sampling conditions to determine if a log should be force-kept.
10
- * Returns true if ANY condition matches (OR logic).
11
- */
12
- declare function shouldKeep(ctx: TailSamplingContext): boolean;
13
- /**
14
- * Simple logging API - as easy as console.log
15
- *
16
- * @example
17
- * ```ts
18
- * log.info('auth', 'User logged in')
19
- * log.error({ action: 'payment', error: 'failed' })
20
- * ```
21
- */
22
- declare const log: Log;
23
- /**
24
- * Create a request-scoped logger for building wide events.
25
- *
26
- * @example
27
- * ```ts
28
- * const log = createRequestLogger({ method: 'POST', path: '/checkout' })
29
- * log.set({ user: { id: '123' } })
30
- * log.set({ cart: { items: 3 } })
31
- * log.emit()
32
- * ```
33
- */
34
- declare function createRequestLogger(options?: RequestLoggerOptions): RequestLogger;
35
- /**
36
- * Get the current environment context.
37
- */
38
- declare function getEnvironment(): EnvironmentContext;
39
-
40
- export { createRequestLogger, getEnvironment, initLogger, log, shouldKeep };
@@ -1,13 +0,0 @@
1
- import * as nitropack from 'nitropack';
2
-
3
- /**
4
- * Custom Nitro error handler that properly serializes EvlogError.
5
- * This ensures that 'data' (containing 'why', 'fix', 'link') is preserved
6
- * in the JSON response regardless of the underlying HTTP framework.
7
- *
8
- * For non-EvlogError, it preserves Nitro's default response shape while
9
- * sanitizing internal error details in production for 5xx errors.
10
- */
11
- declare const _default: nitropack.NitroErrorHandler;
12
-
13
- export { _default as default };
@@ -1,5 +0,0 @@
1
- import * as nitropack from 'nitropack';
2
-
3
- declare const _default: nitropack.NitroAppPlugin;
4
-
5
- export { _default as default };
@@ -1,171 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
- import { EnvironmentContext, RouteConfig, SamplingConfig, TransportConfig } from '../types.js';
3
-
4
- interface ModuleOptions {
5
- /**
6
- * Environment context overrides.
7
- */
8
- env?: Partial<EnvironmentContext>;
9
- /**
10
- * Enable pretty printing.
11
- * @default true in development, false in production
12
- */
13
- pretty?: boolean;
14
- /**
15
- * Route patterns to include in logging.
16
- * Supports glob patterns like '/api/**'.
17
- * If not set, all routes are logged.
18
- * @example ['/api/**', '/auth/**']
19
- */
20
- include?: string[];
21
- /**
22
- * Route patterns to exclude from logging.
23
- * Supports glob patterns like '/api/_nuxt_icon/**'.
24
- * Exclusions take precedence over inclusions.
25
- * @example ['/api/_nuxt_icon/**', '/health']
26
- */
27
- exclude?: string[];
28
- /**
29
- * Route-specific service configuration.
30
- * Allows setting different service names for different routes.
31
- * Patterns are matched using glob syntax.
32
- *
33
- * @example
34
- * ```ts
35
- * routes: {
36
- * '/api/foo/**': { service: 'service1' },
37
- * '/api/bar/**': { service: 'service2' }
38
- * }
39
- * ```
40
- */
41
- routes?: Record<string, RouteConfig>;
42
- /**
43
- * Sampling configuration for filtering logs.
44
- * Allows configuring what percentage of logs to keep per level.
45
- *
46
- * @example
47
- * ```ts
48
- * sampling: {
49
- * rates: {
50
- * info: 10, // Keep 10% of info logs
51
- * warn: 50, // Keep 50% of warning logs
52
- * debug: 5, // Keep 5% of debug logs
53
- * error: 100, // Always keep errors (default)
54
- * }
55
- * }
56
- * ```
57
- */
58
- sampling?: SamplingConfig;
59
- /**
60
- * Transport configuration for sending client logs to the server.
61
- *
62
- * @example
63
- * ```ts
64
- * transport: {
65
- * enabled: true, // Send logs to server API
66
- * endpoint: '/api/_evlog/ingest' // Custom endpoint
67
- * }
68
- * ```
69
- */
70
- transport?: TransportConfig;
71
- /**
72
- * Axiom adapter configuration.
73
- * When configured, use `createAxiomDrain()` from `evlog/axiom` to send logs.
74
- *
75
- * @example
76
- * ```ts
77
- * axiom: {
78
- * dataset: 'my-app-logs',
79
- * token: process.env.AXIOM_TOKEN,
80
- * }
81
- * ```
82
- */
83
- axiom?: {
84
- /** Axiom dataset name */
85
- dataset: string;
86
- /** Axiom API token */
87
- token: string;
88
- /** Organization ID (required for Personal Access Tokens) */
89
- orgId?: string;
90
- /** Base URL for Axiom API. Default: https://api.axiom.co */
91
- baseUrl?: string;
92
- /** Request timeout in milliseconds. Default: 5000 */
93
- timeout?: number;
94
- };
95
- /**
96
- * OTLP adapter configuration.
97
- * When configured, use `createOTLPDrain()` from `evlog/otlp` to send logs.
98
- *
99
- * @example
100
- * ```ts
101
- * otlp: {
102
- * endpoint: 'http://localhost:4318',
103
- * headers: {
104
- * 'Authorization': `Basic ${process.env.GRAFANA_TOKEN}`,
105
- * },
106
- * }
107
- * ```
108
- */
109
- otlp?: {
110
- /** OTLP HTTP endpoint (e.g., http://localhost:4318) */
111
- endpoint: string;
112
- /** Override service name (defaults to event.service) */
113
- serviceName?: string;
114
- /** Additional resource attributes */
115
- resourceAttributes?: Record<string, string | number | boolean>;
116
- /** Custom headers (e.g., for authentication) */
117
- headers?: Record<string, string>;
118
- /** Request timeout in milliseconds. Default: 5000 */
119
- timeout?: number;
120
- };
121
- /**
122
- * PostHog adapter configuration.
123
- * When configured, use `createPostHogDrain()` from `evlog/posthog` to send logs.
124
- *
125
- * @example
126
- * ```ts
127
- * posthog: {
128
- * apiKey: process.env.POSTHOG_API_KEY,
129
- * }
130
- * ```
131
- */
132
- posthog?: {
133
- /** PostHog project API key */
134
- apiKey: string;
135
- /** PostHog host URL. Default: https://us.i.posthog.com */
136
- host?: string;
137
- /** PostHog event name. Default: evlog_wide_event */
138
- eventName?: string;
139
- /** Override distinct_id (defaults to event.service) */
140
- distinctId?: string;
141
- /** Request timeout in milliseconds. Default: 5000 */
142
- timeout?: number;
143
- };
144
- /**
145
- * Sentry adapter configuration.
146
- * When configured, use `createSentryDrain()` from `evlog/sentry` to send logs.
147
- *
148
- * @example
149
- * ```ts
150
- * sentry: {
151
- * dsn: process.env.SENTRY_DSN,
152
- * }
153
- * ```
154
- */
155
- sentry?: {
156
- /** Sentry DSN */
157
- dsn: string;
158
- /** Environment override (defaults to event.environment) */
159
- environment?: string;
160
- /** Release version override (defaults to event.version) */
161
- release?: string;
162
- /** Additional tags to attach as attributes */
163
- tags?: Record<string, string>;
164
- /** Request timeout in milliseconds. Default: 5000 */
165
- timeout?: number;
166
- };
167
- }
168
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
169
-
170
- export { _default as default };
171
- export type { ModuleOptions };
@@ -1,10 +0,0 @@
1
- import { TransportConfig, Log } from '../../types.js';
2
-
3
- declare function initLog(options?: {
4
- pretty?: boolean;
5
- service?: string;
6
- transport?: TransportConfig;
7
- }): void;
8
- declare const log: Log;
9
-
10
- export { initLog, log };
@@ -1,3 +0,0 @@
1
- declare const _default: any;
2
-
3
- export { _default as default };
@@ -1,5 +0,0 @@
1
- import * as h3 from 'h3';
2
-
3
- declare const _default: h3.EventHandler<h3.EventHandlerRequest, Promise<null>>;
4
-
5
- export { _default as default };
@@ -1,28 +0,0 @@
1
- import { ServerEvent, RequestLogger } from '../../types.js';
2
-
3
- /**
4
- * Returns the request logger attached to the given server event.
5
- *
6
- * @param event - The current server event containing the context with the logger.
7
- * @param service - Optional service name to override the default service.
8
- * @returns The request-scoped logger.
9
- * @throws Error if the logger is not initialized on the event context.
10
- *
11
- * @example
12
- * export default defineEventHandler((event) => {
13
- * const log = useLogger(event)
14
- * log.set({ foo: 'bar' })
15
- * // ...
16
- * })
17
- *
18
- * @example
19
- * // Override service name for specific routes
20
- * export default defineEventHandler((event) => {
21
- * const log = useLogger(event, 'payment-service')
22
- * log.set({ foo: 'bar' })
23
- * // ...
24
- * })
25
- */
26
- declare function useLogger(event: ServerEvent, service?: string): RequestLogger;
27
-
28
- export { useLogger };
@@ -1,5 +0,0 @@
1
- import { ParsedError } from '../../types.js';
2
-
3
- declare function parseError(error: unknown): ParsedError;
4
-
5
- export { ParsedError, parseError };
@@ -1,10 +0,0 @@
1
- function getRuntimeConfig() {
2
- try {
3
- const { useRuntimeConfig } = require("nitropack/runtime");
4
- return useRuntimeConfig();
5
- } catch {
6
- return void 0;
7
- }
8
- }
9
-
10
- export { getRuntimeConfig as g };