@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,455 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- transformLogs,
4
- transformMetrics,
5
- transformTraces,
6
- } from '../transformer';
7
- import {
8
- type ExportLogsServiceRequest,
9
- type ExportMetricsServiceRequest,
10
- type ExportTraceServiceRequest,
11
- SeverityNumber,
12
- SpanKind,
13
- SpanStatusCode,
14
- } from '../types';
15
-
16
- describe('OTLP Transformer', () => {
17
- describe('transformTraces', () => {
18
- it('should transform HTTP server spans to request entries', () => {
19
- const request: ExportTraceServiceRequest = {
20
- resourceSpans: [
21
- {
22
- resource: {
23
- attributes: [
24
- { key: 'service.name', value: { stringValue: 'my-api' } },
25
- ],
26
- },
27
- scopeSpans: [
28
- {
29
- scope: { name: '@opentelemetry/instrumentation-http' },
30
- spans: [
31
- {
32
- traceId: 'abc123',
33
- spanId: 'def456',
34
- name: 'GET /users',
35
- kind: SpanKind.SPAN_KIND_SERVER,
36
- startTimeUnixNano: '1704067200000000000', // 2024-01-01 00:00:00
37
- endTimeUnixNano: '1704067200050000000', // +50ms
38
- attributes: [
39
- { key: 'http.method', value: { stringValue: 'GET' } },
40
- { key: 'http.target', value: { stringValue: '/users' } },
41
- { key: 'http.status_code', value: { intValue: '200' } },
42
- {
43
- key: 'http.url',
44
- value: { stringValue: 'http://localhost:3000/users' },
45
- },
46
- ],
47
- status: { code: SpanStatusCode.STATUS_CODE_OK },
48
- },
49
- ],
50
- },
51
- ],
52
- },
53
- ],
54
- };
55
-
56
- const entries = transformTraces(request);
57
-
58
- expect(entries).toHaveLength(1);
59
- expect(entries[0]).toMatchObject({
60
- method: 'GET',
61
- path: '/users',
62
- url: 'http://localhost:3000/users',
63
- status: 200,
64
- duration: 50,
65
- });
66
- expect(entries[0].tags).toContain('trace:abc123');
67
- expect(entries[0].tags).toContain('span:def456');
68
- expect(entries[0].tags).toContain('service:my-api');
69
- });
70
-
71
- it('should ignore non-HTTP server spans', () => {
72
- const request: ExportTraceServiceRequest = {
73
- resourceSpans: [
74
- {
75
- scopeSpans: [
76
- {
77
- spans: [
78
- {
79
- traceId: 'abc123',
80
- spanId: 'def456',
81
- name: 'internal-operation',
82
- kind: SpanKind.SPAN_KIND_INTERNAL,
83
- startTimeUnixNano: '1704067200000000000',
84
- endTimeUnixNano: '1704067200050000000',
85
- attributes: [],
86
- },
87
- {
88
- traceId: 'abc123',
89
- spanId: 'ghi789',
90
- name: 'db-query',
91
- kind: SpanKind.SPAN_KIND_CLIENT,
92
- startTimeUnixNano: '1704067200000000000',
93
- endTimeUnixNano: '1704067200010000000',
94
- attributes: [
95
- {
96
- key: 'db.system',
97
- value: { stringValue: 'postgresql' },
98
- },
99
- ],
100
- },
101
- ],
102
- },
103
- ],
104
- },
105
- ],
106
- };
107
-
108
- const entries = transformTraces(request);
109
- expect(entries).toHaveLength(0);
110
- });
111
-
112
- it('should handle error spans', () => {
113
- const request: ExportTraceServiceRequest = {
114
- resourceSpans: [
115
- {
116
- scopeSpans: [
117
- {
118
- spans: [
119
- {
120
- traceId: 'abc123',
121
- spanId: 'def456',
122
- name: 'POST /error',
123
- kind: SpanKind.SPAN_KIND_SERVER,
124
- startTimeUnixNano: '1704067200000000000',
125
- endTimeUnixNano: '1704067200100000000',
126
- attributes: [
127
- { key: 'http.method', value: { stringValue: 'POST' } },
128
- { key: 'http.target', value: { stringValue: '/error' } },
129
- ],
130
- status: {
131
- code: SpanStatusCode.STATUS_CODE_ERROR,
132
- message: 'Internal server error',
133
- },
134
- },
135
- ],
136
- },
137
- ],
138
- },
139
- ],
140
- };
141
-
142
- const entries = transformTraces(request);
143
-
144
- expect(entries).toHaveLength(1);
145
- expect(entries[0].status).toBe(500);
146
- });
147
-
148
- it('should handle empty request', () => {
149
- const entries = transformTraces({});
150
- expect(entries).toHaveLength(0);
151
- });
152
-
153
- it('should extract client IP from attributes', () => {
154
- const request: ExportTraceServiceRequest = {
155
- resourceSpans: [
156
- {
157
- scopeSpans: [
158
- {
159
- spans: [
160
- {
161
- traceId: 'abc123',
162
- spanId: 'def456',
163
- name: 'GET /test',
164
- kind: SpanKind.SPAN_KIND_SERVER,
165
- startTimeUnixNano: '1704067200000000000',
166
- endTimeUnixNano: '1704067200050000000',
167
- attributes: [
168
- { key: 'http.method', value: { stringValue: 'GET' } },
169
- { key: 'http.target', value: { stringValue: '/test' } },
170
- { key: 'http.status_code', value: { intValue: '200' } },
171
- {
172
- key: 'client.address',
173
- value: { stringValue: '192.168.1.1' },
174
- },
175
- ],
176
- },
177
- ],
178
- },
179
- ],
180
- },
181
- ],
182
- };
183
-
184
- const entries = transformTraces(request);
185
- expect(entries[0].ip).toBe('192.168.1.1');
186
- });
187
- });
188
-
189
- describe('transformLogs', () => {
190
- it('should transform log records to log entries', () => {
191
- const request: ExportLogsServiceRequest = {
192
- resourceLogs: [
193
- {
194
- resource: {
195
- attributes: [
196
- { key: 'service.name', value: { stringValue: 'my-api' } },
197
- ],
198
- },
199
- scopeLogs: [
200
- {
201
- scope: { name: 'my-logger' },
202
- logRecords: [
203
- {
204
- observedTimeUnixNano: '1704067200000000000',
205
- severityNumber: SeverityNumber.SEVERITY_NUMBER_INFO,
206
- severityText: 'INFO',
207
- body: { stringValue: 'User logged in' },
208
- attributes: [
209
- { key: 'userId', value: { stringValue: '123' } },
210
- ],
211
- traceId: 'abc123',
212
- spanId: 'def456',
213
- },
214
- ],
215
- },
216
- ],
217
- },
218
- ],
219
- };
220
-
221
- const entries = transformLogs(request);
222
-
223
- expect(entries).toHaveLength(1);
224
- expect(entries[0]).toMatchObject({
225
- level: 'info',
226
- message: 'User logged in',
227
- requestId: 'span:def456',
228
- });
229
- expect(entries[0].context).toMatchObject({
230
- userId: '123',
231
- 'service.name': 'my-api',
232
- 'instrumentation.scope': 'my-logger',
233
- });
234
- });
235
-
236
- it('should map severity levels correctly', () => {
237
- const createLogRequest = (
238
- severity: SeverityNumber,
239
- ): ExportLogsServiceRequest => ({
240
- resourceLogs: [
241
- {
242
- scopeLogs: [
243
- {
244
- logRecords: [
245
- {
246
- observedTimeUnixNano: '1704067200000000000',
247
- severityNumber: severity,
248
- body: { stringValue: 'Test message' },
249
- },
250
- ],
251
- },
252
- ],
253
- },
254
- ],
255
- });
256
-
257
- expect(
258
- transformLogs(createLogRequest(SeverityNumber.SEVERITY_NUMBER_DEBUG))[0]
259
- .level,
260
- ).toBe('debug');
261
- expect(
262
- transformLogs(createLogRequest(SeverityNumber.SEVERITY_NUMBER_INFO))[0]
263
- .level,
264
- ).toBe('info');
265
- expect(
266
- transformLogs(createLogRequest(SeverityNumber.SEVERITY_NUMBER_WARN))[0]
267
- .level,
268
- ).toBe('warn');
269
- expect(
270
- transformLogs(createLogRequest(SeverityNumber.SEVERITY_NUMBER_ERROR))[0]
271
- .level,
272
- ).toBe('error');
273
- expect(
274
- transformLogs(createLogRequest(SeverityNumber.SEVERITY_NUMBER_FATAL))[0]
275
- .level,
276
- ).toBe('error');
277
- });
278
-
279
- it('should handle object body', () => {
280
- const request: ExportLogsServiceRequest = {
281
- resourceLogs: [
282
- {
283
- scopeLogs: [
284
- {
285
- logRecords: [
286
- {
287
- observedTimeUnixNano: '1704067200000000000',
288
- severityNumber: SeverityNumber.SEVERITY_NUMBER_INFO,
289
- body: {
290
- kvlistValue: {
291
- values: [
292
- { key: 'event', value: { stringValue: 'login' } },
293
- { key: 'success', value: { boolValue: true } },
294
- ],
295
- },
296
- },
297
- },
298
- ],
299
- },
300
- ],
301
- },
302
- ],
303
- };
304
-
305
- const entries = transformLogs(request);
306
- expect(entries[0].message).toBe('{"event":"login","success":true}');
307
- });
308
-
309
- it('should handle empty request', () => {
310
- const entries = transformLogs({});
311
- expect(entries).toHaveLength(0);
312
- });
313
- });
314
-
315
- describe('transformMetrics', () => {
316
- it('should transform gauge metrics', () => {
317
- const request: ExportMetricsServiceRequest = {
318
- resourceMetrics: [
319
- {
320
- resource: {
321
- attributes: [
322
- { key: 'service.name', value: { stringValue: 'my-api' } },
323
- ],
324
- },
325
- scopeMetrics: [
326
- {
327
- metrics: [
328
- {
329
- name: 'cpu_usage',
330
- description: 'CPU usage percentage',
331
- unit: '%',
332
- gauge: {
333
- dataPoints: [
334
- {
335
- timeUnixNano: '1704067200000000000',
336
- asDouble: 45.5,
337
- attributes: [
338
- { key: 'host', value: { stringValue: 'server-1' } },
339
- ],
340
- },
341
- ],
342
- },
343
- },
344
- ],
345
- },
346
- ],
347
- },
348
- ],
349
- };
350
-
351
- const points = transformMetrics(request);
352
-
353
- expect(points).toHaveLength(1);
354
- expect(points[0]).toMatchObject({
355
- name: 'cpu_usage',
356
- description: 'CPU usage percentage',
357
- unit: '%',
358
- value: 45.5,
359
- type: 'gauge',
360
- });
361
- expect(points[0].attributes).toMatchObject({ host: 'server-1' });
362
- expect(points[0].resourceAttributes).toMatchObject({
363
- 'service.name': 'my-api',
364
- });
365
- });
366
-
367
- it('should transform sum (counter) metrics', () => {
368
- const request: ExportMetricsServiceRequest = {
369
- resourceMetrics: [
370
- {
371
- scopeMetrics: [
372
- {
373
- metrics: [
374
- {
375
- name: 'http_requests_total',
376
- sum: {
377
- dataPoints: [
378
- {
379
- timeUnixNano: '1704067200000000000',
380
- asInt: '1234',
381
- },
382
- ],
383
- aggregationTemporality: 2, // CUMULATIVE
384
- isMonotonic: true,
385
- },
386
- },
387
- ],
388
- },
389
- ],
390
- },
391
- ],
392
- };
393
-
394
- const points = transformMetrics(request);
395
-
396
- expect(points).toHaveLength(1);
397
- expect(points[0]).toMatchObject({
398
- name: 'http_requests_total',
399
- value: 1234,
400
- type: 'sum',
401
- });
402
- });
403
-
404
- it('should transform histogram metrics', () => {
405
- const request: ExportMetricsServiceRequest = {
406
- resourceMetrics: [
407
- {
408
- scopeMetrics: [
409
- {
410
- metrics: [
411
- {
412
- name: 'http_request_duration',
413
- histogram: {
414
- dataPoints: [
415
- {
416
- timeUnixNano: '1704067200000000000',
417
- count: '100',
418
- sum: 5000,
419
- min: 10,
420
- max: 500,
421
- bucketCounts: ['10', '30', '40', '15', '5'],
422
- explicitBounds: [50, 100, 200, 500],
423
- },
424
- ],
425
- aggregationTemporality: 2,
426
- },
427
- },
428
- ],
429
- },
430
- ],
431
- },
432
- ],
433
- };
434
-
435
- const points = transformMetrics(request);
436
-
437
- expect(points).toHaveLength(1);
438
- expect(points[0]).toMatchObject({
439
- name: 'http_request_duration',
440
- value: 5000,
441
- type: 'histogram',
442
- });
443
- expect(points[0].attributes).toMatchObject({
444
- count: 100,
445
- min: 10,
446
- max: 500,
447
- });
448
- });
449
-
450
- it('should handle empty request', () => {
451
- const points = transformMetrics({});
452
- expect(points).toHaveLength(0);
453
- });
454
- });
455
- });
package/src/otlp/hono.ts DELETED
@@ -1,120 +0,0 @@
1
- import { Hono } from 'hono';
2
- import type { MetricsHandler, OTLPReceiverOptions } from './receiver';
3
- import { OTLPReceiver } from './receiver';
4
- import type {
5
- ExportLogsServiceRequest,
6
- ExportMetricsServiceRequest,
7
- ExportTraceServiceRequest,
8
- } from './types';
9
-
10
- /**
11
- * Create Hono routes for OTLP endpoints.
12
- *
13
- * Mount this at /v1 to get the standard OTLP paths:
14
- * - POST /v1/traces
15
- * - POST /v1/logs
16
- * - POST /v1/metrics
17
- *
18
- * @example
19
- * ```typescript
20
- * import { createOTLPRoutes } from '@geekmidas/telescope/otlp/hono';
21
- *
22
- * const telescope = new Telescope({ storage: new InMemoryStorage() });
23
- * const app = new Hono();
24
- *
25
- * // Mount OTLP endpoints at /v1
26
- * app.route('/v1', createOTLPRoutes({ telescope }));
27
- *
28
- * // Now accepts:
29
- * // POST /v1/traces
30
- * // POST /v1/logs
31
- * // POST /v1/metrics
32
- * ```
33
- */
34
- export function createOTLPRoutes(options: OTLPReceiverOptions): Hono {
35
- const receiver = new OTLPReceiver(options);
36
- const app = new Hono();
37
-
38
- // POST /traces - Receive trace data
39
- app.post('/traces', async (c) => {
40
- try {
41
- const contentType = c.req.header('content-type') || '';
42
-
43
- // Only support JSON for now
44
- if (!contentType.includes('application/json')) {
45
- return c.json({ error: 'Only application/json is supported' }, 415);
46
- }
47
-
48
- const request = await c.req.json<ExportTraceServiceRequest>();
49
- const response = await receiver.receiveTraces(request);
50
-
51
- return c.json(response, response.partialSuccess ? 206 : 200);
52
- } catch (error) {
53
- return c.json(
54
- {
55
- error:
56
- error instanceof Error ? error.message : 'Failed to process traces',
57
- },
58
- 400,
59
- );
60
- }
61
- });
62
-
63
- // POST /logs - Receive log data
64
- app.post('/logs', async (c) => {
65
- try {
66
- const contentType = c.req.header('content-type') || '';
67
-
68
- if (!contentType.includes('application/json')) {
69
- return c.json({ error: 'Only application/json is supported' }, 415);
70
- }
71
-
72
- const request = await c.req.json<ExportLogsServiceRequest>();
73
- const response = await receiver.receiveLogs(request);
74
-
75
- return c.json(response, response.partialSuccess ? 206 : 200);
76
- } catch (error) {
77
- return c.json(
78
- {
79
- error:
80
- error instanceof Error ? error.message : 'Failed to process logs',
81
- },
82
- 400,
83
- );
84
- }
85
- });
86
-
87
- // POST /metrics - Receive metrics data
88
- app.post('/metrics', async (c) => {
89
- try {
90
- const contentType = c.req.header('content-type') || '';
91
-
92
- if (!contentType.includes('application/json')) {
93
- return c.json({ error: 'Only application/json is supported' }, 415);
94
- }
95
-
96
- const request = await c.req.json<ExportMetricsServiceRequest>();
97
- const response = await receiver.receiveMetrics(request);
98
-
99
- return c.json(response, response.partialSuccess ? 206 : 200);
100
- } catch (error) {
101
- return c.json(
102
- {
103
- error:
104
- error instanceof Error
105
- ? error.message
106
- : 'Failed to process metrics',
107
- },
108
- 400,
109
- );
110
- }
111
- });
112
-
113
- return app;
114
- }
115
-
116
- /**
117
- * Re-export the receiver for custom usage
118
- */
119
- export { OTLPReceiver };
120
- export type { MetricsHandler, OTLPReceiverOptions };
package/src/otlp/index.ts DELETED
@@ -1,22 +0,0 @@
1
- export type { MetricsHandler, OTLPReceiverOptions } from './receiver';
2
- export { OTLPReceiver } from './receiver';
3
- export type { MetricDataPoint } from './transformer';
4
- export {
5
- transformLogs,
6
- transformMetrics,
7
- transformTraces,
8
- } from './transformer';
9
- export type {
10
- ExportLogsServiceRequest,
11
- ExportLogsServiceResponse,
12
- ExportMetricsServiceRequest,
13
- ExportMetricsServiceResponse,
14
- ExportTraceServiceRequest,
15
- ExportTraceServiceResponse,
16
- KeyValue,
17
- LogRecord,
18
- Metric,
19
- Resource,
20
- Span,
21
- } from './types';
22
- export { SeverityNumber, SpanKind, SpanStatusCode } from './types';