@geekmidas/telescope 9.0.2 → 10.0.0-alpha.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.
Files changed (122) hide show
  1. package/README.md +14 -4
  2. package/dist/{http-D5kn3_Mt.d.mts → http-BiNtg85L.d.mts} +3 -3
  3. package/dist/{http-D5kn3_Mt.d.mts.map → http-BiNtg85L.d.mts.map} +1 -1
  4. package/dist/instrumentation/http.d.mts +1 -1
  5. package/dist/instrumentation/index.cjs +2 -2
  6. package/dist/instrumentation/index.d.cts +2 -2
  7. package/dist/instrumentation/index.d.mts +3 -3
  8. package/dist/instrumentation/index.mjs +2 -2
  9. package/dist/instrumentation/middleware.cjs +1 -1
  10. package/dist/instrumentation/middleware.d.cts +1 -1
  11. package/dist/instrumentation/middleware.d.mts +1 -1
  12. package/dist/instrumentation/middleware.mjs +1 -1
  13. package/dist/instrumentation/otel.cjs +1 -1
  14. package/dist/instrumentation/otel.d.cts +1 -1
  15. package/dist/instrumentation/otel.d.mts +1 -1
  16. package/dist/instrumentation/otel.mjs +1 -1
  17. package/dist/logger/console.d.cts.map +1 -1
  18. package/dist/logger/pino.d.mts +2 -2
  19. package/dist/{middleware-DqPQpcup.cjs → middleware-Bcq6XXGG.cjs} +2 -2
  20. package/dist/middleware-Bcq6XXGG.cjs.map +1 -0
  21. package/dist/{middleware-4-GrQlOT.mjs → middleware-D1XEHvyy.mjs} +2 -2
  22. package/dist/middleware-D1XEHvyy.mjs.map +1 -0
  23. package/dist/{middleware-CA84nsNN.d.cts → middleware-PeyS-9Ny.d.cts} +2 -2
  24. package/dist/{middleware-CA84nsNN.d.cts.map → middleware-PeyS-9Ny.d.cts.map} +1 -1
  25. package/dist/{middleware-DAceVpfw.d.mts → middleware-oHvo_ZgU.d.mts} +2 -2
  26. package/dist/{middleware-DAceVpfw.d.mts.map → middleware-oHvo_ZgU.d.mts.map} +1 -1
  27. package/dist/{otel-40udNP5g.mjs → otel-B9bNoeZ2.mjs} +3 -3
  28. package/dist/otel-B9bNoeZ2.mjs.map +1 -0
  29. package/dist/{otel-SBVoVEHr.d.cts → otel-Bk89b1lX.d.cts} +3 -3
  30. package/dist/{otel-1bJPb2Z7.d.mts.map → otel-Bk89b1lX.d.cts.map} +1 -1
  31. package/dist/{otel-COrpz_GZ.cjs → otel-BzjOtVxZ.cjs} +3 -3
  32. package/dist/otel-BzjOtVxZ.cjs.map +1 -0
  33. package/dist/{otel-1bJPb2Z7.d.mts → otel-lPMsM26e.d.mts} +3 -3
  34. package/dist/{otel-SBVoVEHr.d.cts.map → otel-lPMsM26e.d.mts.map} +1 -1
  35. package/dist/storage/kysely.cjs +48 -38
  36. package/dist/storage/kysely.cjs.map +1 -1
  37. package/dist/storage/kysely.d.cts +29 -9
  38. package/dist/storage/kysely.d.cts.map +1 -1
  39. package/dist/storage/kysely.d.mts +29 -9
  40. package/dist/storage/kysely.d.mts.map +1 -1
  41. package/dist/storage/kysely.mjs +48 -38
  42. package/dist/storage/kysely.mjs.map +1 -1
  43. package/dist/tracing-PnECEbEu.d.mts.map +1 -1
  44. package/package.json +6 -3
  45. package/CHANGELOG.md +0 -72
  46. package/dist/middleware-4-GrQlOT.mjs.map +0 -1
  47. package/dist/middleware-DqPQpcup.cjs.map +0 -1
  48. package/dist/otel-40udNP5g.mjs.map +0 -1
  49. package/dist/otel-COrpz_GZ.cjs.map +0 -1
  50. package/src/Telescope.ts +0 -561
  51. package/src/__tests__/Telescope.spec.ts +0 -438
  52. package/src/__tests__/pino-transport.spec.ts +0 -115
  53. package/src/__tests__/redact.spec.ts +0 -336
  54. package/src/adapters/__tests__/lambda.spec.ts +0 -318
  55. package/src/adapters/__tests__/middy.spec.ts +0 -741
  56. package/src/adapters/index.ts +0 -22
  57. package/src/adapters/lambda.ts +0 -432
  58. package/src/adapters/middy.ts +0 -402
  59. package/src/adapters/types.ts +0 -181
  60. package/src/core.ts +0 -51
  61. package/src/index.ts +0 -34
  62. package/src/instrumentation/__tests__/core.spec.ts +0 -248
  63. package/src/instrumentation/__tests__/hono.spec.ts +0 -348
  64. package/src/instrumentation/__tests__/middleware.spec.ts +0 -528
  65. package/src/instrumentation/__tests__/otel.spec.ts +0 -291
  66. package/src/instrumentation/__tests__/tracing.spec.ts +0 -208
  67. package/src/instrumentation/core.ts +0 -228
  68. package/src/instrumentation/hono.ts +0 -270
  69. package/src/instrumentation/http.ts +0 -306
  70. package/src/instrumentation/index.ts +0 -90
  71. package/src/instrumentation/middleware.ts +0 -297
  72. package/src/instrumentation/otel.ts +0 -271
  73. package/src/instrumentation/setup.ts +0 -246
  74. package/src/instrumentation/tracing.ts +0 -145
  75. package/src/logger/__tests__/console.spec.ts +0 -366
  76. package/src/logger/__tests__/pino.spec.ts +0 -217
  77. package/src/logger/console.ts +0 -230
  78. package/src/logger/pino.ts +0 -201
  79. package/src/metrics/MetricsAggregator.ts +0 -555
  80. package/src/metrics/__tests__/MetricsAggregator.spec.ts +0 -298
  81. package/src/metrics/index.ts +0 -2
  82. package/src/metrics/storage/InMemoryMetricsStorage.ts +0 -380
  83. package/src/metrics/storage/MetricsStorage.ts +0 -74
  84. package/src/metrics/storage/index.ts +0 -3
  85. package/src/metrics/storage/types.ts +0 -243
  86. package/src/otlp/__tests__/receiver.spec.ts +0 -367
  87. package/src/otlp/__tests__/transformer.spec.ts +0 -455
  88. package/src/otlp/hono.ts +0 -120
  89. package/src/otlp/index.ts +0 -22
  90. package/src/otlp/receiver.ts +0 -162
  91. package/src/otlp/transformer.ts +0 -367
  92. package/src/otlp/types.ts +0 -364
  93. package/src/redact.ts +0 -116
  94. package/src/server/__tests__/hono.spec.ts +0 -814
  95. package/src/server/hono.ts +0 -442
  96. package/src/storage/__tests__/kysely.spec.ts +0 -715
  97. package/src/storage/__tests__/memory.spec.ts +0 -694
  98. package/src/storage/kysely.ts +0 -599
  99. package/src/storage/memory.ts +0 -204
  100. package/src/types.ts +0 -447
  101. package/src/ui-assets.ts +0 -40
  102. package/tsconfig.json +0 -9
  103. package/ui/CHANGELOG.md +0 -7
  104. package/ui/index.html +0 -12
  105. package/ui/node_modules/.bin/tsc +0 -21
  106. package/ui/node_modules/.bin/tsserver +0 -21
  107. package/ui/node_modules/.bin/vite +0 -21
  108. package/ui/package.json +0 -24
  109. package/ui/src/App.tsx +0 -595
  110. package/ui/src/api.ts +0 -88
  111. package/ui/src/components/ExceptionDetail.tsx +0 -100
  112. package/ui/src/components/FilterBar.tsx +0 -162
  113. package/ui/src/components/LogDetail.tsx +0 -91
  114. package/ui/src/components/RequestDetail.tsx +0 -143
  115. package/ui/src/main.tsx +0 -10
  116. package/ui/src/styles.css +0 -11
  117. package/ui/src/types.ts +0 -63
  118. package/ui/src/vite-env.d.ts +0 -1
  119. package/ui/src/vite-plugin-gkm-config.ts +0 -54
  120. package/ui/tsconfig.json +0 -20
  121. package/ui/tsconfig.tsbuildinfo +0 -1
  122. 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 };