@geekmidas/telescope 1.1.1 → 10.0.0-alpha.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 (167) hide show
  1. package/README.md +14 -4
  2. package/dist/{hono-Bz9PQQzj.mjs → hono-Bw-ey6CT.mjs} +2 -2
  3. package/dist/{hono-Bz9PQQzj.mjs.map → hono-Bw-ey6CT.mjs.map} +1 -1
  4. package/dist/{hono-Z_JIICmt.cjs → hono-CPHX7FAm.cjs} +2 -2
  5. package/dist/{hono-Z_JIICmt.cjs.map → hono-CPHX7FAm.cjs.map} +1 -1
  6. package/dist/{http-Crsriv32.mjs → http-BIvr0YdI.mjs} +1 -1
  7. package/dist/{http-Crsriv32.mjs.map → http-BIvr0YdI.mjs.map} +1 -1
  8. package/dist/{http-JycFRfSe.cjs → http-BsqmhurZ.cjs} +1 -1
  9. package/dist/{http-JycFRfSe.cjs.map → http-BsqmhurZ.cjs.map} +1 -1
  10. package/dist/{http-D5kn3_Mt.d.mts → http-DULM1u2L.d.cts} +3 -3
  11. package/dist/{http-D5kn3_Mt.d.mts.map → http-DULM1u2L.d.cts.map} +1 -1
  12. package/dist/{http-Dvca6fC3.d.cts → http-GB-Nlvwc.d.mts} +3 -3
  13. package/dist/{http-Dvca6fC3.d.cts.map → http-GB-Nlvwc.d.mts.map} +1 -1
  14. package/dist/instrumentation/hono.cjs +2 -2
  15. package/dist/instrumentation/hono.mjs +2 -2
  16. package/dist/instrumentation/http.cjs +1 -1
  17. package/dist/instrumentation/http.d.cts +1 -1
  18. package/dist/instrumentation/http.d.mts +1 -1
  19. package/dist/instrumentation/http.mjs +1 -1
  20. package/dist/instrumentation/index.cjs +5 -5
  21. package/dist/instrumentation/index.d.cts +3 -3
  22. package/dist/instrumentation/index.d.mts +3 -3
  23. package/dist/instrumentation/index.mjs +5 -5
  24. package/dist/instrumentation/middleware.cjs +2 -2
  25. package/dist/instrumentation/middleware.d.cts +1 -1
  26. package/dist/instrumentation/middleware.d.mts +1 -1
  27. package/dist/instrumentation/middleware.mjs +2 -2
  28. package/dist/instrumentation/otel.cjs +2 -2
  29. package/dist/instrumentation/otel.d.cts +1 -1
  30. package/dist/instrumentation/otel.d.mts +1 -1
  31. package/dist/instrumentation/otel.mjs +2 -2
  32. package/dist/instrumentation/setup.cjs +1 -1
  33. package/dist/instrumentation/setup.mjs +1 -1
  34. package/dist/logger/console.d.cts.map +1 -1
  35. package/dist/{middleware-D3v5SnSs.cjs → middleware-Bcq6XXGG.cjs} +3 -3
  36. package/dist/middleware-Bcq6XXGG.cjs.map +1 -0
  37. package/dist/{middleware-Dy1ctr2N.mjs → middleware-D1XEHvyy.mjs} +3 -3
  38. package/dist/middleware-D1XEHvyy.mjs.map +1 -0
  39. package/dist/{middleware-CA84nsNN.d.cts → middleware-PeyS-9Ny.d.cts} +2 -2
  40. package/dist/{middleware-CA84nsNN.d.cts.map → middleware-PeyS-9Ny.d.cts.map} +1 -1
  41. package/dist/{middleware-DAceVpfw.d.mts → middleware-oHvo_ZgU.d.mts} +2 -2
  42. package/dist/{middleware-DAceVpfw.d.mts.map → middleware-oHvo_ZgU.d.mts.map} +1 -1
  43. package/dist/{otel-DPKNyJ0t.mjs → otel-B9bNoeZ2.mjs} +4 -4
  44. package/dist/otel-B9bNoeZ2.mjs.map +1 -0
  45. package/dist/{otel-1bJPb2Z7.d.mts → otel-Bk89b1lX.d.cts} +3 -3
  46. package/dist/{otel-1bJPb2Z7.d.mts.map → otel-Bk89b1lX.d.cts.map} +1 -1
  47. package/dist/{otel-DuiBeBPU.cjs → otel-BzjOtVxZ.cjs} +4 -4
  48. package/dist/otel-BzjOtVxZ.cjs.map +1 -0
  49. package/dist/{otel-SBVoVEHr.d.cts → otel-lPMsM26e.d.mts} +3 -3
  50. package/dist/{otel-SBVoVEHr.d.cts.map → otel-lPMsM26e.d.mts.map} +1 -1
  51. package/dist/otlp/hono.cjs +3 -3
  52. package/dist/otlp/hono.mjs +3 -3
  53. package/dist/otlp/index.cjs +3 -3
  54. package/dist/otlp/index.mjs +3 -3
  55. package/dist/otlp/receiver.cjs +3 -3
  56. package/dist/otlp/receiver.mjs +3 -3
  57. package/dist/otlp/transformer.cjs +2 -2
  58. package/dist/otlp/transformer.mjs +2 -2
  59. package/dist/otlp/types.cjs +1 -1
  60. package/dist/otlp/types.mjs +1 -1
  61. package/dist/{receiver-q4f7eirs.mjs → receiver-D46dfkYI.mjs} +2 -2
  62. package/dist/{receiver-q4f7eirs.mjs.map → receiver-D46dfkYI.mjs.map} +1 -1
  63. package/dist/{receiver-BW_4go_X.cjs → receiver-slCoAFat.cjs} +2 -2
  64. package/dist/{receiver-BW_4go_X.cjs.map → receiver-slCoAFat.cjs.map} +1 -1
  65. package/dist/{setup-BhCp2LUp.mjs → setup-DC9JMEYZ.mjs} +1 -1
  66. package/dist/{setup-BhCp2LUp.mjs.map → setup-DC9JMEYZ.mjs.map} +1 -1
  67. package/dist/{setup-_uT4L_x5.cjs → setup-DufxQpi9.cjs} +1 -1
  68. package/dist/{setup-_uT4L_x5.cjs.map → setup-DufxQpi9.cjs.map} +1 -1
  69. package/dist/storage/kysely.cjs +48 -38
  70. package/dist/storage/kysely.cjs.map +1 -1
  71. package/dist/storage/kysely.d.cts +29 -9
  72. package/dist/storage/kysely.d.cts.map +1 -1
  73. package/dist/storage/kysely.d.mts +29 -9
  74. package/dist/storage/kysely.d.mts.map +1 -1
  75. package/dist/storage/kysely.mjs +48 -38
  76. package/dist/storage/kysely.mjs.map +1 -1
  77. package/dist/tracing-BX8uY2nR.d.cts.map +1 -1
  78. package/dist/tracing-PnECEbEu.d.mts.map +1 -1
  79. package/dist/{transformer-CFrJQkUg.mjs → transformer-CFQ4WFk6.mjs} +2 -2
  80. package/dist/{transformer-CFrJQkUg.mjs.map → transformer-CFQ4WFk6.mjs.map} +1 -1
  81. package/dist/{transformer-DvDYyFRQ.cjs → transformer-Csl6fbgv.cjs} +2 -2
  82. package/dist/{transformer-DvDYyFRQ.cjs.map → transformer-Csl6fbgv.cjs.map} +1 -1
  83. package/dist/types-B1EIa_cQ.d.mts.map +1 -1
  84. package/dist/{types-BBeTDpHr.cjs → types-BMiHgsi4.cjs} +1 -1
  85. package/dist/{types-BBeTDpHr.cjs.map → types-BMiHgsi4.cjs.map} +1 -1
  86. package/dist/{types-CXYLhG_G.mjs → types-Cj59nqy7.mjs} +1 -1
  87. package/dist/{types-CXYLhG_G.mjs.map → types-Cj59nqy7.mjs.map} +1 -1
  88. package/dist/types-l7Rlb5Mg.d.cts.map +1 -1
  89. package/package.json +6 -3
  90. package/CHANGELOG.md +0 -51
  91. package/dist/middleware-D3v5SnSs.cjs.map +0 -1
  92. package/dist/middleware-Dy1ctr2N.mjs.map +0 -1
  93. package/dist/otel-DPKNyJ0t.mjs.map +0 -1
  94. package/dist/otel-DuiBeBPU.cjs.map +0 -1
  95. package/src/Telescope.ts +0 -561
  96. package/src/__tests__/Telescope.spec.ts +0 -438
  97. package/src/__tests__/pino-transport.spec.ts +0 -115
  98. package/src/__tests__/redact.spec.ts +0 -336
  99. package/src/adapters/__tests__/lambda.spec.ts +0 -318
  100. package/src/adapters/__tests__/middy.spec.ts +0 -741
  101. package/src/adapters/index.ts +0 -22
  102. package/src/adapters/lambda.ts +0 -432
  103. package/src/adapters/middy.ts +0 -402
  104. package/src/adapters/types.ts +0 -181
  105. package/src/core.ts +0 -51
  106. package/src/index.ts +0 -34
  107. package/src/instrumentation/__tests__/core.spec.ts +0 -248
  108. package/src/instrumentation/__tests__/hono.spec.ts +0 -348
  109. package/src/instrumentation/__tests__/middleware.spec.ts +0 -528
  110. package/src/instrumentation/__tests__/otel.spec.ts +0 -291
  111. package/src/instrumentation/__tests__/tracing.spec.ts +0 -208
  112. package/src/instrumentation/core.ts +0 -228
  113. package/src/instrumentation/hono.ts +0 -270
  114. package/src/instrumentation/http.ts +0 -306
  115. package/src/instrumentation/index.ts +0 -90
  116. package/src/instrumentation/middleware.ts +0 -297
  117. package/src/instrumentation/otel.ts +0 -271
  118. package/src/instrumentation/setup.ts +0 -246
  119. package/src/instrumentation/tracing.ts +0 -145
  120. package/src/logger/__tests__/console.spec.ts +0 -366
  121. package/src/logger/__tests__/pino.spec.ts +0 -217
  122. package/src/logger/console.ts +0 -230
  123. package/src/logger/pino.ts +0 -201
  124. package/src/metrics/MetricsAggregator.ts +0 -555
  125. package/src/metrics/__tests__/MetricsAggregator.spec.ts +0 -298
  126. package/src/metrics/index.ts +0 -2
  127. package/src/metrics/storage/InMemoryMetricsStorage.ts +0 -380
  128. package/src/metrics/storage/MetricsStorage.ts +0 -74
  129. package/src/metrics/storage/index.ts +0 -3
  130. package/src/metrics/storage/types.ts +0 -243
  131. package/src/otlp/__tests__/receiver.spec.ts +0 -367
  132. package/src/otlp/__tests__/transformer.spec.ts +0 -455
  133. package/src/otlp/hono.ts +0 -120
  134. package/src/otlp/index.ts +0 -22
  135. package/src/otlp/receiver.ts +0 -162
  136. package/src/otlp/transformer.ts +0 -367
  137. package/src/otlp/types.ts +0 -364
  138. package/src/redact.ts +0 -116
  139. package/src/server/__tests__/hono.spec.ts +0 -814
  140. package/src/server/hono.ts +0 -442
  141. package/src/storage/__tests__/kysely.spec.ts +0 -715
  142. package/src/storage/__tests__/memory.spec.ts +0 -694
  143. package/src/storage/kysely.ts +0 -599
  144. package/src/storage/memory.ts +0 -204
  145. package/src/types.ts +0 -447
  146. package/src/ui-assets.ts +0 -40
  147. package/tsconfig.json +0 -9
  148. package/ui/CHANGELOG.md +0 -7
  149. package/ui/index.html +0 -12
  150. package/ui/node_modules/.bin/tsc +0 -21
  151. package/ui/node_modules/.bin/tsserver +0 -21
  152. package/ui/node_modules/.bin/vite +0 -21
  153. package/ui/package.json +0 -24
  154. package/ui/src/App.tsx +0 -595
  155. package/ui/src/api.ts +0 -88
  156. package/ui/src/components/ExceptionDetail.tsx +0 -100
  157. package/ui/src/components/FilterBar.tsx +0 -162
  158. package/ui/src/components/LogDetail.tsx +0 -91
  159. package/ui/src/components/RequestDetail.tsx +0 -143
  160. package/ui/src/main.tsx +0 -10
  161. package/ui/src/styles.css +0 -11
  162. package/ui/src/types.ts +0 -63
  163. package/ui/src/vite-env.d.ts +0 -1
  164. package/ui/src/vite-plugin-gkm-config.ts +0 -54
  165. package/ui/tsconfig.json +0 -20
  166. package/ui/tsconfig.tsbuildinfo +0 -1
  167. package/ui/vite.config.ts +0 -13
@@ -1,230 +0,0 @@
1
- import type { Telescope } from '../Telescope';
2
-
3
- /**
4
- * Logger interface matching @geekmidas/logger
5
- */
6
- export interface Logger {
7
- debug: LogFn;
8
- info: LogFn;
9
- warn: LogFn;
10
- error: LogFn;
11
- fatal: LogFn;
12
- trace: LogFn;
13
- child: (obj: object) => Logger;
14
- }
15
-
16
- export type LogFn = {
17
- <T extends object>(obj: T, msg?: string, ...args: any[]): void;
18
- (msg: string): void;
19
- };
20
-
21
- export interface TelescopeLoggerOptions {
22
- /**
23
- * The Telescope instance to send logs to
24
- */
25
- telescope: Telescope;
26
- /**
27
- * Optional underlying logger to also forward logs to.
28
- * If not provided, logs will only go to Telescope.
29
- */
30
- logger?: Logger;
31
- /**
32
- * Request ID to associate logs with a specific request.
33
- */
34
- requestId?: string;
35
- /**
36
- * Initial context data to include in all log messages
37
- */
38
- context?: Record<string, unknown>;
39
- }
40
-
41
- type LogLevel = 'debug' | 'info' | 'warn' | 'error';
42
-
43
- /**
44
- * A logger that sends logs to both Telescope and an optional underlying logger.
45
- * Implements the Logger interface from @geekmidas/logger.
46
- *
47
- * @example
48
- * ```typescript
49
- * import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
50
- * import { TelescopeLogger } from '@geekmidas/telescope/logger/console';
51
- * import { ConsoleLogger } from '@geekmidas/logger/console';
52
- *
53
- * const telescope = new Telescope({ storage: new InMemoryStorage() });
54
- *
55
- * // With underlying logger (logs to both console and Telescope)
56
- * const logger = new TelescopeLogger({
57
- * telescope,
58
- * logger: new ConsoleLogger({ app: 'myApp' }),
59
- * });
60
- *
61
- * // Without underlying logger (logs only to Telescope)
62
- * const telescopeOnly = new TelescopeLogger({ telescope });
63
- *
64
- * // Usage
65
- * logger.info({ userId: '123' }, 'User logged in');
66
- * logger.error({ error: 'Something failed' }, 'Operation failed');
67
- * ```
68
- */
69
- export class TelescopeLogger implements Logger {
70
- private telescope: Telescope;
71
- private logger?: Logger;
72
- private requestId?: string;
73
- private context: Record<string, unknown>;
74
-
75
- constructor(options: TelescopeLoggerOptions) {
76
- this.telescope = options.telescope;
77
- this.logger = options.logger;
78
- this.requestId = options.requestId;
79
- this.context = options.context ?? {};
80
- }
81
-
82
- private createLogFn(level: LogLevel): LogFn {
83
- const fn = <T extends object>(
84
- objOrMsg: T | string,
85
- msg?: string,
86
- ...args: any[]
87
- ): void => {
88
- let context: Record<string, unknown>;
89
- let message: string;
90
-
91
- if (typeof objOrMsg === 'string') {
92
- context = { ...this.context };
93
- message = objOrMsg;
94
- } else {
95
- context = { ...this.context, ...objOrMsg };
96
- message = msg ?? '';
97
- }
98
-
99
- // Forward to underlying logger if present
100
- if (this.logger) {
101
- if (typeof objOrMsg === 'string') {
102
- this.logger[level](objOrMsg);
103
- } else {
104
- this.logger[level](objOrMsg as any, msg, ...args);
105
- }
106
- }
107
-
108
- // Send to Telescope (fire and forget)
109
- this.telescope[level](message, context, this.requestId).catch(() => {});
110
- };
111
-
112
- return fn as LogFn;
113
- }
114
-
115
- debug: LogFn = this.createLogFn('debug');
116
- info: LogFn = this.createLogFn('info');
117
- warn: LogFn = this.createLogFn('warn');
118
- error: LogFn = this.createLogFn('error');
119
-
120
- // Map fatal and trace to error and debug for Telescope
121
- fatal: LogFn = ((
122
- objOrMsg: object | string,
123
- msg?: string,
124
- ...args: any[]
125
- ): void => {
126
- // Forward to underlying logger if present
127
- if (this.logger) {
128
- if (typeof objOrMsg === 'string') {
129
- this.logger.fatal(objOrMsg);
130
- } else {
131
- this.logger.fatal(objOrMsg as any, msg, ...args);
132
- }
133
- }
134
-
135
- // Send to Telescope as error level
136
- let context: Record<string, unknown>;
137
- let message: string;
138
-
139
- if (typeof objOrMsg === 'string') {
140
- context = { ...this.context, level: 'fatal' };
141
- message = objOrMsg;
142
- } else {
143
- context = { ...this.context, ...objOrMsg, level: 'fatal' };
144
- message = msg ?? '';
145
- }
146
-
147
- this.telescope.error(message, context, this.requestId).catch(() => {});
148
- }) as LogFn;
149
-
150
- trace: LogFn = ((
151
- objOrMsg: object | string,
152
- msg?: string,
153
- ...args: any[]
154
- ): void => {
155
- // Forward to underlying logger if present
156
- if (this.logger) {
157
- if (typeof objOrMsg === 'string') {
158
- this.logger.trace(objOrMsg);
159
- } else {
160
- this.logger.trace(objOrMsg as any, msg, ...args);
161
- }
162
- }
163
-
164
- // Send to Telescope as debug level
165
- let context: Record<string, unknown>;
166
- let message: string;
167
-
168
- if (typeof objOrMsg === 'string') {
169
- context = { ...this.context, level: 'trace' };
170
- message = objOrMsg;
171
- } else {
172
- context = { ...this.context, ...objOrMsg, level: 'trace' };
173
- message = msg ?? '';
174
- }
175
-
176
- this.telescope.debug(message, context, this.requestId).catch(() => {});
177
- }) as LogFn;
178
-
179
- /**
180
- * Creates a child logger with additional context.
181
- * The child logger inherits all context from the parent.
182
- */
183
- child(obj: object): Logger {
184
- return new TelescopeLogger({
185
- telescope: this.telescope,
186
- logger: this.logger?.child(obj),
187
- requestId: this.requestId,
188
- context: { ...this.context, ...obj },
189
- });
190
- }
191
-
192
- /**
193
- * Create a child logger bound to a specific request ID.
194
- * Useful for correlating logs with HTTP requests.
195
- */
196
- withRequestId(requestId: string): TelescopeLogger {
197
- return new TelescopeLogger({
198
- telescope: this.telescope,
199
- logger: this.logger,
200
- requestId,
201
- context: this.context,
202
- });
203
- }
204
- }
205
-
206
- /**
207
- * Create a logger that sends logs to Telescope.
208
- * Convenience function for creating a TelescopeLogger.
209
- *
210
- * @example
211
- * ```typescript
212
- * import { createTelescopeLogger } from '@geekmidas/telescope/logger/console';
213
- * import { ConsoleLogger } from '@geekmidas/logger/console';
214
- *
215
- * const telescope = new Telescope({ storage: new InMemoryStorage() });
216
- * const baseLogger = new ConsoleLogger({ app: 'myApp' });
217
- *
218
- * const logger = createTelescopeLogger(telescope, baseLogger);
219
- * logger.info({ action: 'startup' }, 'Application started');
220
- * ```
221
- */
222
- export function createTelescopeLogger(
223
- telescope: Telescope,
224
- logger?: Logger,
225
- context?: Record<string, unknown>,
226
- ): TelescopeLogger {
227
- return new TelescopeLogger({ telescope, logger, context });
228
- }
229
-
230
- export type { Telescope };
@@ -1,201 +0,0 @@
1
- import build from 'pino-abstract-transport';
2
- import type { Telescope } from '../Telescope';
3
-
4
- /**
5
- * Pino log object structure after parsing
6
- */
7
- export interface PinoLogObject {
8
- level: number | string;
9
- time: number;
10
- pid?: number;
11
- hostname?: string;
12
- msg?: string;
13
- [key: string]: unknown;
14
- }
15
-
16
- export interface TelescopePinoTransportOptions {
17
- /**
18
- * The Telescope instance to send logs to
19
- */
20
- telescope: Telescope;
21
- /**
22
- * Request ID to associate logs with a specific request.
23
- * Can be a static string or a function that extracts the ID from log data.
24
- */
25
- requestId?: string | ((data: PinoLogObject) => string | undefined);
26
- /**
27
- * Batch size before flushing to Telescope (default: 100)
28
- */
29
- batchSize?: number;
30
- /**
31
- * Flush interval in milliseconds (default: 1000ms)
32
- */
33
- flushIntervalMs?: number;
34
- }
35
-
36
- type TelescopeLogLevel = 'debug' | 'info' | 'warn' | 'error';
37
-
38
- interface LogBatch {
39
- level: TelescopeLogLevel;
40
- message: string;
41
- context: Record<string, unknown>;
42
- requestId?: string;
43
- }
44
-
45
- /**
46
- * Map Pino levels to Telescope log levels.
47
- * Handles both numeric levels (default pino) and string levels (custom formatters).
48
- */
49
- function mapPinoLevel(level: number | string): TelescopeLogLevel {
50
- // Handle string levels (from custom formatters like `level: label => ({ level: label.toUpperCase() })`)
51
- if (typeof level === 'string') {
52
- const normalized = level.toLowerCase();
53
- if (normalized === 'trace' || normalized === 'debug') return 'debug';
54
- if (normalized === 'info') return 'info';
55
- if (normalized === 'warn' || normalized === 'warning') return 'warn';
56
- return 'error'; // error, fatal, or unknown
57
- }
58
-
59
- // Pino numeric levels: trace=10, debug=20, info=30, warn=40, error=50, fatal=60
60
- if (level <= 20) return 'debug'; // trace, debug
61
- if (level <= 30) return 'info';
62
- if (level <= 40) return 'warn';
63
- return 'error'; // error, fatal
64
- }
65
-
66
- /**
67
- * Create a Pino transport that sends logs to Telescope.
68
- *
69
- * Uses pino-abstract-transport for proper async iteration and backpressure handling.
70
- * Logs are batched for performance and flushed either when the batch is full
71
- * or after the flush interval.
72
- *
73
- * @example
74
- * ```typescript
75
- * import pino from 'pino';
76
- * import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
77
- * import { createPinoTransport } from '@geekmidas/telescope/logger/pino';
78
- *
79
- * const telescope = new Telescope({ storage: new InMemoryStorage() });
80
- *
81
- * // Use with pino.multistream to log to both stdout and Telescope
82
- * const logger = pino(
83
- * { level: 'debug' },
84
- * pino.multistream([
85
- * { stream: process.stdout },
86
- * { stream: createPinoTransport({ telescope }) }
87
- * ])
88
- * );
89
- *
90
- * logger.info({ userId: '123' }, 'User logged in');
91
- * ```
92
- */
93
- export function createPinoTransport(options: TelescopePinoTransportOptions) {
94
- const {
95
- telescope,
96
- requestId,
97
- batchSize = 100,
98
- flushIntervalMs = 1000,
99
- } = options;
100
-
101
- const batch: LogBatch[] = [];
102
- let flushTimer: ReturnType<typeof setTimeout> | null = null;
103
-
104
- async function flush(): Promise<void> {
105
- if (batch.length === 0) return;
106
-
107
- const toFlush = batch.splice(0, batch.length);
108
-
109
- // Use batch insert for better performance
110
- try {
111
- await telescope.log(toFlush);
112
- } catch {
113
- // Silently ignore errors to not break logging
114
- }
115
- }
116
-
117
- function scheduleFlush(): void {
118
- if (flushTimer === null) {
119
- flushTimer = setTimeout(() => {
120
- flushTimer = null;
121
- flush().catch(() => {
122
- // Silently ignore flush errors
123
- });
124
- }, flushIntervalMs);
125
- }
126
- }
127
-
128
- function clearFlushTimer(): void {
129
- if (flushTimer !== null) {
130
- clearTimeout(flushTimer);
131
- flushTimer = null;
132
- }
133
- }
134
-
135
- return build(
136
- async (source) => {
137
- for await (const obj of source) {
138
- const data = obj as PinoLogObject;
139
- const { level, msg, time, pid, hostname, ...context } = data;
140
-
141
- const telescopeLevel = mapPinoLevel(level);
142
-
143
- // Extract request ID
144
- let reqId: string | undefined;
145
- if (typeof requestId === 'function') {
146
- reqId = requestId(data);
147
- } else if (typeof requestId === 'string') {
148
- reqId = requestId;
149
- } else if (typeof context.requestId === 'string') {
150
- reqId = context.requestId;
151
- delete context.requestId;
152
- }
153
-
154
- batch.push({
155
- level: telescopeLevel,
156
- message: msg || '',
157
- context,
158
- requestId: reqId,
159
- });
160
-
161
- if (batch.length >= batchSize) {
162
- clearFlushTimer();
163
- await flush();
164
- } else {
165
- scheduleFlush();
166
- }
167
- }
168
- },
169
- {
170
- async close() {
171
- clearFlushTimer();
172
- await flush();
173
- },
174
- },
175
- );
176
- }
177
-
178
- /**
179
- * Create a Pino destination that sends logs to Telescope.
180
- * Alias for createPinoTransport for API compatibility.
181
- *
182
- * @example
183
- * ```typescript
184
- * import pino from 'pino';
185
- * import { createPinoDestination } from '@geekmidas/telescope/logger/pino';
186
- *
187
- * const telescope = new Telescope({ storage: new InMemoryStorage() });
188
- *
189
- * // Use with pino.multistream to log to both stdout and Telescope
190
- * const logger = pino(
191
- * { level: 'debug' },
192
- * pino.multistream([
193
- * { stream: process.stdout },
194
- * { stream: createPinoDestination({ telescope }) }
195
- * ])
196
- * );
197
- * ```
198
- */
199
- export const createPinoDestination = createPinoTransport;
200
-
201
- export type { Telescope };