autotel-terminal 29.0.3 → 29.0.5
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/LICENSE +191 -21
- package/README.md +2 -2
- package/dist/cli.cjs +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{src-Bn1x8Neq.js → src-BbKL64Rh.js} +6 -4
- package/dist/{src-Bn1x8Neq.js.map → src-BbKL64Rh.js.map} +1 -1
- package/dist/{src-H7oZS-9-.cjs → src-adtyx8HT.cjs} +7 -5
- package/dist/{src-H7oZS-9-.cjs.map → src-adtyx8HT.cjs.map} +1 -1
- package/package.json +17 -17
package/LICENSE
CHANGED
|
@@ -1,21 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty
|
|
20
|
+
percent (50%) or more of the outstanding shares, or (iii) beneficial
|
|
21
|
+
ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source,
|
|
28
|
+
and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
31
|
+
or translation of a Source form, including but not limited to compiled
|
|
32
|
+
object code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that
|
|
36
|
+
is included in or attached to the work (an example is provided in the
|
|
37
|
+
Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as
|
|
42
|
+
a whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
+
verbal, or written communication sent to the Licensor or its
|
|
54
|
+
representatives, including but not limited to communication on electronic
|
|
55
|
+
mailing lists, source code control systems, and issue tracking systems that
|
|
56
|
+
are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
57
|
+
and improving the Work, but excluding communication that is conspicuously
|
|
58
|
+
marked or otherwise designated in writing by the copyright owner as "Not a
|
|
59
|
+
Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
62
|
+
behalf of whom a Contribution has been received by Licensor and
|
|
63
|
+
subsequently incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
66
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
67
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
68
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
69
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
70
|
+
Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
73
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
74
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
|
|
75
|
+
this section) patent license to make, have made, use, offer to sell, sell,
|
|
76
|
+
import, and otherwise transfer the Work, where such license applies only to
|
|
77
|
+
those patent claims licensable by such Contributor that are necessarily
|
|
78
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
79
|
+
Contribution(s) with the Work to which such Contribution(s) was submitted.
|
|
80
|
+
If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or
|
|
83
|
+
contributory patent infringement, then any patent licenses granted to You
|
|
84
|
+
under this License for that Work shall terminate as of the date such
|
|
85
|
+
litigation is filed.
|
|
86
|
+
|
|
87
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
88
|
+
Derivative Works thereof in any medium, with or without modifications, and
|
|
89
|
+
in Source or Object form, provided that You meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
92
|
+
a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
98
|
+
You distribute, all copyright, patent, trademark, and attribution notices
|
|
99
|
+
from the Source form of the Work, excluding those notices that do not
|
|
100
|
+
pertain to any part of the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
103
|
+
distribution, then any Derivative Works that You distribute must include a
|
|
104
|
+
readable copy of the attribution notices contained within such NOTICE file,
|
|
105
|
+
excluding those notices that do not pertain to any part of the Derivative
|
|
106
|
+
Works, in at least one of the following places: within a NOTICE text file
|
|
107
|
+
distributed as part of the Derivative Works; within the Source form or
|
|
108
|
+
documentation, if provided along with the Derivative Works; or, within a
|
|
109
|
+
display generated by the Derivative Works, if and wherever such third-party
|
|
110
|
+
notices normally appear. The contents of the NOTICE file are for
|
|
111
|
+
informational purposes only and do not modify the License. You may add Your
|
|
112
|
+
own attribution notices within Derivative Works that You distribute,
|
|
113
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that
|
|
114
|
+
such additional attribution notices cannot be construed as modifying the
|
|
115
|
+
License.
|
|
116
|
+
|
|
117
|
+
You may add Your own copyright statement to Your modifications and may
|
|
118
|
+
provide additional or different license terms and conditions for use,
|
|
119
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
120
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
121
|
+
distribution of the Work otherwise complies with the conditions stated in
|
|
122
|
+
this License.
|
|
123
|
+
|
|
124
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
125
|
+
Contribution intentionally submitted for inclusion in the Work by You to
|
|
126
|
+
the Licensor shall be under the terms and conditions of this License,
|
|
127
|
+
without any additional terms or conditions. Notwithstanding the above,
|
|
128
|
+
nothing herein shall supersede or modify the terms of any separate license
|
|
129
|
+
agreement you may have executed with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor, except
|
|
133
|
+
as required for reasonable and customary use in describing the origin of
|
|
134
|
+
the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
|
|
137
|
+
in writing, Licensor provides the Work (and each Contributor provides its
|
|
138
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
139
|
+
KIND, either express or implied, including, without limitation, any
|
|
140
|
+
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
|
|
141
|
+
FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
|
|
142
|
+
determining the appropriateness of using or redistributing the Work and
|
|
143
|
+
assume any risks associated with Your exercise of permissions under this
|
|
144
|
+
License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory, whether
|
|
147
|
+
in tort (including negligence), contract, or otherwise, unless required by
|
|
148
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
149
|
+
in writing, shall any Contributor be liable to You for damages, including
|
|
150
|
+
any direct, indirect, special, incidental, or consequential damages of any
|
|
151
|
+
character arising as a result of this License or out of the use or
|
|
152
|
+
inability to use the Work (including but not limited to damages for loss of
|
|
153
|
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
|
154
|
+
other commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing the
|
|
158
|
+
Work or Derivative Works thereof, You may choose to offer, and charge a fee
|
|
159
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
160
|
+
obligations and/or rights consistent with this License. However, in
|
|
161
|
+
accepting such obligations, You may act only on Your own behalf and on Your
|
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if
|
|
163
|
+
You agree to indemnify, defend, and hold each Contributor harmless for any
|
|
164
|
+
liability incurred by, or claims asserted against, such Contributor by
|
|
165
|
+
reason of your accepting any such warranty or additional liability.
|
|
166
|
+
|
|
167
|
+
END OF TERMS AND CONDITIONS
|
|
168
|
+
|
|
169
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
170
|
+
|
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
172
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
175
|
+
recommend that a file or class name and description of purpose be included
|
|
176
|
+
on the same "printed page" as the copyright notice for easier
|
|
177
|
+
identification within third-party archives.
|
|
178
|
+
|
|
179
|
+
Copyright [yyyy] [name of copyright owner]
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
**Terminal trace viewer for autotel** : Ink (React-for-CLI) powered dashboard for live trace inspection during development. Zero setup, trace-first, autotel-only.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/autotel-terminal)
|
|
6
|
-
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
7
|
|
|
8
8
|
## Overview
|
|
9
9
|
|
|
@@ -515,7 +515,7 @@ See the [autotel examples](../../apps/) directory for complete working examples:
|
|
|
515
515
|
|
|
516
516
|
## License
|
|
517
517
|
|
|
518
|
-
|
|
518
|
+
Apache-2.0 © [Jag Reehal](https://github.com/jagreehal)
|
|
519
519
|
|
|
520
520
|
## Links
|
|
521
521
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-adtyx8HT.cjs');
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_http = require("node:http");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
node_path = require_src.__toESM(node_path, 1);
|
|
7
7
|
|
|
8
8
|
//#region src/listen.ts
|
|
9
|
-
const LOOPBACK = new Set([
|
|
9
|
+
const LOOPBACK = /* @__PURE__ */ new Set([
|
|
10
10
|
"localhost",
|
|
11
11
|
"127.0.0.1",
|
|
12
12
|
"::1"
|
|
@@ -392,7 +392,7 @@ function parseArgs(argv) {
|
|
|
392
392
|
}
|
|
393
393
|
return options;
|
|
394
394
|
}
|
|
395
|
-
const OTLP_ROUTES = new Set([
|
|
395
|
+
const OTLP_ROUTES = /* @__PURE__ */ new Set([
|
|
396
396
|
"/v1/traces",
|
|
397
397
|
"/v1/logs",
|
|
398
398
|
"/v1/metrics"
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","names":["#subscribers","path","getTerminalLogStream"],"sources":["../src/listen.ts","../src/cli-stream.ts","../src/otlp-http-json.ts","../src/cli.ts"],"sourcesContent":["import { createServer, type Server } from 'node:http';\n\nconst LOOPBACK = new Set(['localhost', '127.0.0.1', '::1']);\n\nexport interface LoopbackListeners {\n /** Resolves once the primary and (attempted) sibling listeners are up. */\n ready: Promise<{ addresses: string[]; warnings: string[] }>;\n /** Close the sibling listener (the primary server is owned by the caller). */\n closeSibling: () => Promise<void>;\n}\n\n/** Format host:port, bracketing IPv6 literals (e.g. `[::1]:4319`). */\nexport function formatAddress(host: string, port: number): string {\n return host.includes(':') ? `[${host}]:${port}` : `${host}:${port}`;\n}\n\n/**\n * Listen on `host:port`, and when `host` is a loopback literal, ALSO listen on\n * the sibling loopback family (IPv4 ⟷ IPv6) so a client reaches the collector\n * whether the OS resolves `localhost` to `127.0.0.1` or `::1`.\n *\n * Kills a silent footgun: a dev-server proxy targeting `http://localhost:PORT`\n * on macOS resolves `localhost` to `::1`, but a collector bound only to\n * `127.0.0.1` never receives the request — spans vanish with no error. If the\n * sibling family cannot bind, it is surfaced as a warning, never fatal.\n */\nexport function listenLoopbackDualStack(args: {\n primary: Server;\n port: number;\n host: string;\n attachSecondary: (server: Server) => void;\n}): LoopbackListeners {\n const { primary, port, host, attachSecondary } = args;\n let sibling: Server | undefined;\n\n const ready = new Promise<{ addresses: string[]; warnings: string[] }>(\n (resolve) => {\n const addresses: string[] = [];\n const warnings: string[] = [];\n const primaryHost = host === 'localhost' ? '127.0.0.1' : host;\n\n primary.listen(port, primaryHost, () => {\n const addr = primary.address();\n const resolvedPort =\n addr && typeof addr === 'object' ? addr.port : port;\n addresses.push(formatAddress(primaryHost, resolvedPort));\n\n if (!LOOPBACK.has(host)) {\n resolve({ addresses, warnings });\n return;\n }\n\n const siblingHost = primaryHost === '::1' ? '127.0.0.1' : '::1';\n const s = createServer();\n attachSecondary(s);\n\n const onError = (e: Error) => {\n s.close();\n warnings.push(\n `could not also bind ${formatAddress(siblingHost, resolvedPort)} (${e.message}); ` +\n `clients using the ${siblingHost === '::1' ? 'IPv6' : 'IPv4'} form of \"localhost\" may not connect.`,\n );\n resolve({ addresses, warnings });\n };\n s.once('error', onError);\n s.listen(resolvedPort, siblingHost, () => {\n s.off('error', onError);\n sibling = s;\n addresses.push(formatAddress(siblingHost, resolvedPort));\n resolve({ addresses, warnings });\n });\n });\n },\n );\n\n return {\n ready,\n closeSibling: () =>\n new Promise<void>((res) => {\n if (!sibling) return res();\n sibling.close(() => res());\n }),\n };\n}\n","import type { TerminalSpanEvent, TerminalSpanStream } from './span-stream';\n\ntype Subscriber = (event: TerminalSpanEvent) => void;\n\n/**\n * In-memory stream implementation for standalone CLI ingestion.\n */\nexport class CliTerminalSpanStream implements TerminalSpanStream {\n #subscribers = new Set<Subscriber>();\n\n onSpanEnd(callback: Subscriber): () => void {\n this.#subscribers.add(callback);\n return () => {\n this.#subscribers.delete(callback);\n };\n }\n\n push(event: TerminalSpanEvent): void {\n for (const subscriber of this.#subscribers) {\n subscriber(event);\n }\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { TerminalSpanEvent, SpanEvent, SpanLink } from './span-stream';\nimport type { TerminalLogEvent, LogLevel } from './lib/log-model';\n\nconst MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB\n\ntype OtlpAnyValue = {\n stringValue?: string;\n boolValue?: boolean;\n intValue?: string | number;\n doubleValue?: number;\n bytesValue?: string;\n};\n\ntype OtlpKeyValue = {\n key: string;\n value?: OtlpAnyValue;\n};\n\ntype OtlpSpan = {\n traceId?: string;\n spanId?: string;\n parentSpanId?: string;\n name?: string;\n kind?: number | string;\n startTimeUnixNano?: string;\n endTimeUnixNano?: string;\n attributes?: OtlpKeyValue[];\n status?: {\n code?: number | string;\n };\n events?: {\n timeUnixNano?: string;\n name?: string;\n attributes?: OtlpKeyValue[];\n }[];\n links?: {\n traceId?: string;\n spanId?: string;\n attributes?: OtlpKeyValue[];\n }[];\n};\n\nfunction anyValueToPrimitive(value: OtlpAnyValue | undefined): unknown {\n if (!value) return undefined;\n if (value.stringValue !== undefined) return value.stringValue;\n if (value.boolValue !== undefined) return value.boolValue;\n if (value.intValue !== undefined) {\n const num = Number(value.intValue);\n return Number.isNaN(num) ? value.intValue : num;\n }\n if (value.doubleValue !== undefined) return value.doubleValue;\n if (value.bytesValue !== undefined) return value.bytesValue;\n return undefined;\n}\n\nfunction attrsToRecord(\n attributes: OtlpKeyValue[] | undefined,\n): Record<string, unknown> {\n if (!attributes || attributes.length === 0) return {};\n const out: Record<string, unknown> = {};\n for (const attribute of attributes) {\n out[attribute.key] = anyValueToPrimitive(attribute.value);\n }\n return out;\n}\n\nfunction normalizeHexId(\n id: string | undefined,\n expectedHexLength: number,\n): string {\n if (!id) return ''.padStart(expectedHexLength, '0');\n const trimmed = id.trim();\n if (/^[a-fA-F0-9]+$/.test(trimmed)) {\n return trimmed\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n try {\n const decoded = Buffer.from(trimmed, 'base64').toString('hex');\n if (decoded.length > 0) {\n return decoded\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n } catch {\n // ignore and fall through\n }\n return ''.padStart(expectedHexLength, '0');\n}\n\nfunction toMs(unixNano: string | undefined): number {\n if (!unixNano) return Date.now();\n const parsed = Number(unixNano);\n if (Number.isNaN(parsed)) return Date.now();\n return parsed / 1_000_000;\n}\n\nfunction mapStatus(\n code: number | string | undefined,\n): 'OK' | 'ERROR' | 'UNSET' {\n const normalized = typeof code === 'string' ? code.toUpperCase() : code;\n if (\n normalized === 1 ||\n normalized === 'STATUS_CODE_OK' ||\n normalized === 'OK'\n )\n return 'OK';\n if (\n normalized === 2 ||\n normalized === 'STATUS_CODE_ERROR' ||\n normalized === 'ERROR'\n ) {\n return 'ERROR';\n }\n return 'UNSET';\n}\n\nfunction mapKind(kind: number | string | undefined): string {\n if (typeof kind === 'string') return kind.toUpperCase();\n switch (kind) {\n case 1: {\n return 'INTERNAL';\n }\n case 2: {\n return 'SERVER';\n }\n case 3: {\n return 'CLIENT';\n }\n case 4: {\n return 'PRODUCER';\n }\n case 5: {\n return 'CONSUMER';\n }\n default: {\n return 'INTERNAL';\n }\n }\n}\n\nfunction* extractSpans(\n payload: unknown,\n): Generator<{ span: OtlpSpan; resourceAttrs: Record<string, unknown> }> {\n if (!payload || typeof payload !== 'object') return;\n const resourceSpans = (payload as { resourceSpans?: unknown[] })\n .resourceSpans;\n if (!Array.isArray(resourceSpans)) return;\n for (const resourceSpan of resourceSpans) {\n if (!resourceSpan || typeof resourceSpan !== 'object') continue;\n const resource = (resourceSpan as { resource?: { attributes?: OtlpKeyValue[] } }).resource;\n const resourceAttrs = attrsToRecord(resource?.attributes);\n const scopeSpans = (resourceSpan as { scopeSpans?: unknown[] }).scopeSpans;\n if (!Array.isArray(scopeSpans)) continue;\n for (const scopeSpan of scopeSpans) {\n if (!scopeSpan || typeof scopeSpan !== 'object') continue;\n const spans = (scopeSpan as { spans?: unknown[] }).spans;\n if (!Array.isArray(spans)) continue;\n for (const span of spans) {\n if (span && typeof span === 'object') {\n yield { span: span as OtlpSpan, resourceAttrs };\n }\n }\n }\n }\n}\n\nexport function otlpSpanToTerminalEvent(\n span: OtlpSpan,\n resourceAttrs: Record<string, unknown> = {},\n): TerminalSpanEvent {\n const startTime = toMs(span.startTimeUnixNano);\n const endTime = toMs(span.endTimeUnixNano);\n const spanAttrs = attrsToRecord(span.attributes);\n // Merge resource attributes (e.g. service.name) under span attributes,\n // with span-level attributes taking precedence\n const mergedAttrs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(resourceAttrs)) {\n mergedAttrs[k] = v;\n }\n for (const [k, v] of Object.entries(spanAttrs)) {\n mergedAttrs[k] = v;\n }\n const parsedEvents: SpanEvent[] | undefined = span.events?.length\n ? span.events.map((e) => ({\n name: e.name || '',\n timeMs: toMs(e.timeUnixNano),\n attributes: attrsToRecord(e.attributes),\n }))\n : undefined;\n\n const parsedLinks: SpanLink[] | undefined = span.links?.length\n ? span.links.map((l) => ({\n traceId: normalizeHexId(l.traceId, 32),\n spanId: normalizeHexId(l.spanId, 16),\n attributes: attrsToRecord(l.attributes),\n }))\n : undefined;\n\n return {\n name: span.name || 'unnamed',\n spanId: normalizeHexId(span.spanId, 16),\n traceId: normalizeHexId(span.traceId, 32),\n parentSpanId: span.parentSpanId\n ? normalizeHexId(span.parentSpanId, 16)\n : undefined,\n startTime,\n endTime,\n durationMs: Math.max(0, endTime - startTime),\n status: mapStatus(span.status?.code),\n kind: mapKind(span.kind),\n attributes: mergedAttrs,\n ...(parsedEvents ? { events: parsedEvents } : {}),\n ...(parsedLinks ? { links: parsedLinks } : {}),\n };\n}\n\nexport async function readJsonBody(req: IncomingMessage): Promise<unknown> {\n const chunks: Buffer[] = [];\n let totalLength = 0;\n for await (const chunk of req) {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n totalLength += buf.length;\n if (totalLength > MAX_BODY_BYTES) {\n throw new Error(`Body exceeds ${MAX_BODY_BYTES} byte limit`);\n }\n chunks.push(buf);\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (!raw) return {};\n return JSON.parse(raw);\n}\n\nexport function sendJson(\n res: ServerResponse,\n status: number,\n data: Record<string, unknown>,\n): void {\n res.statusCode = status;\n res.setHeader('content-type', 'application/json');\n res.end(JSON.stringify(data));\n}\n\nexport function parseOtlpEvents(payload: unknown): TerminalSpanEvent[] {\n const events: TerminalSpanEvent[] = [];\n for (const { span, resourceAttrs } of extractSpans(payload)) {\n events.push(otlpSpanToTerminalEvent(span, resourceAttrs));\n }\n return events;\n}\n\n// --- OTLP Log parsing ---\n\ntype OtlpLogRecord = {\n timeUnixNano?: string;\n observedTimeUnixNano?: string;\n severityNumber?: number;\n severityText?: string;\n body?: OtlpAnyValue;\n attributes?: OtlpKeyValue[];\n traceId?: string;\n spanId?: string;\n};\n\nfunction mapSeverityToLevel(\n severityNumber?: number,\n severityText?: string,\n): LogLevel {\n if (severityText) {\n const lower = severityText.toLowerCase();\n if (lower.startsWith('debug') || lower === 'trace') return 'debug';\n if (lower.startsWith('info')) return 'info';\n if (lower.startsWith('warn')) return 'warn';\n if (lower.startsWith('error') || lower.startsWith('fatal')) return 'error';\n }\n if (severityNumber !== undefined) {\n if (severityNumber <= 4) return 'debug';\n if (severityNumber <= 8) return 'debug';\n if (severityNumber <= 12) return 'info';\n if (severityNumber <= 16) return 'warn';\n return 'error';\n }\n return 'info';\n}\n\nfunction bodyToMessage(body: OtlpAnyValue | undefined): string {\n if (!body) return '';\n const value = anyValueToPrimitive(body);\n return value === undefined ? '' : String(value);\n}\n\nfunction* extractLogRecords(payload: unknown): Generator<OtlpLogRecord> {\n if (!payload || typeof payload !== 'object') return;\n const resourceLogs = (payload as { resourceLogs?: unknown[] }).resourceLogs;\n if (!Array.isArray(resourceLogs)) return;\n for (const resourceLog of resourceLogs) {\n if (!resourceLog || typeof resourceLog !== 'object') continue;\n const scopeLogs = (resourceLog as { scopeLogs?: unknown[] }).scopeLogs;\n if (!Array.isArray(scopeLogs)) continue;\n for (const scopeLog of scopeLogs) {\n if (!scopeLog || typeof scopeLog !== 'object') continue;\n const logRecords = (scopeLog as { logRecords?: unknown[] }).logRecords;\n if (!Array.isArray(logRecords)) continue;\n for (const record of logRecords) {\n if (record && typeof record === 'object') {\n yield record as OtlpLogRecord;\n }\n }\n }\n }\n}\n\nexport function parseOtlpLogEvents(payload: unknown): TerminalLogEvent[] {\n const events: TerminalLogEvent[] = [];\n for (const record of extractLogRecords(payload)) {\n const time = toMs(record.timeUnixNano || record.observedTimeUnixNano);\n events.push({\n time,\n level: mapSeverityToLevel(record.severityNumber, record.severityText),\n message: bodyToMessage(record.body),\n traceId: record.traceId ? normalizeHexId(record.traceId, 32) : undefined,\n spanId: record.spanId ? normalizeHexId(record.spanId, 16) : undefined,\n attributes: attrsToRecord(record.attributes),\n });\n }\n return events;\n}\n\n// --- OTLP Metrics parsing (accept and count) ---\n\nexport function countOtlpMetrics(payload: unknown): number {\n if (!payload || typeof payload !== 'object') return 0;\n let count = 0;\n const resourceMetrics = (payload as { resourceMetrics?: unknown[] })\n .resourceMetrics;\n if (!Array.isArray(resourceMetrics)) return 0;\n for (const resourceMetric of resourceMetrics) {\n if (!resourceMetric || typeof resourceMetric !== 'object') continue;\n const scopeMetrics = (resourceMetric as { scopeMetrics?: unknown[] })\n .scopeMetrics;\n if (!Array.isArray(scopeMetrics)) continue;\n for (const scopeMetric of scopeMetrics) {\n if (!scopeMetric || typeof scopeMetric !== 'object') continue;\n const metrics = (scopeMetric as { metrics?: unknown[] }).metrics;\n if (Array.isArray(metrics)) {\n count += metrics.length;\n }\n }\n }\n return count;\n}\n","#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport path from 'node:path';\nimport { renderTerminal } from './index';\nimport { listenLoopbackDualStack } from './listen';\nimport { getTerminalLogStream } from './log-stream';\nimport { CliTerminalSpanStream } from './cli-stream';\nimport {\n countOtlpMetrics,\n parseOtlpEvents,\n parseOtlpLogEvents,\n readJsonBody,\n sendJson,\n} from './otlp-http-json';\n\nimport type { AIConfig, AIProviderType } from './ai/types';\n\ntype CliOptions = {\n port: number;\n host: string;\n title?: string;\n ai: Partial<AIConfig>;\n};\n\nfunction printHelp(): void {\n process.stdout.write(\n String.raw`autotel-terminal - Standalone OTLP receiver with terminal dashboard\n\nUsage: autotel-terminal [options]\n\nOptions:\n -p, --port <port> Port to listen on (default: 4319, env: AUTOTEL_TERMINAL_PORT)\n -H, --host <host> Host to bind to (default: 127.0.0.1, env: AUTOTEL_TERMINAL_HOST)\n -t, --title <title> Dashboard title (env: AUTOTEL_TERMINAL_TITLE)\n -h, --help Show this help message\n -v, --version Show version number\n\nAI Options:\n --ai-provider <provider> AI provider: ollama, openai, openai-compatible (env: AI_PROVIDER)\n --ai-model <model> AI model name (env: AI_MODEL)\n --ai-api-key <key> API key for cloud providers (env: AI_API_KEY)\n --ai-base-url <url> Custom AI endpoint URL (env: AI_BASE_URL)\n\n Auto-detection: if Ollama is running locally, it is used automatically.\n If OPENAI_API_KEY is set, OpenAI is used. Press 'a' in the dashboard to toggle AI.\n\nEndpoints:\n POST /v1/traces Receive OTLP JSON trace data\n POST /v1/logs Receive OTLP JSON log data\n POST /v1/metrics Receive OTLP JSON metric data (accepted and counted)\n GET /healthz Health check\n\nExamples:\n npx autotel-terminal\n npx autotel-terminal --ai-provider ollama --ai-model granite4\n AI_API_KEY=sk-... npx autotel-terminal --ai-provider openai --ai-model gpt-4o\n` + '\\n',\n );\n}\n\nfunction printVersion(): void {\n try {\n const dir = import.meta.dirname ?? new URL('.', import.meta.url).pathname;\n const pkgPath = path.resolve(dir, '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n process.stdout.write(`${pkg.version}\\n`);\n } catch {\n process.stdout.write('unknown\\n');\n }\n}\n\nfunction parseArgs(argv: string[]): CliOptions | null {\n const options: CliOptions = {\n port: Number(process.env.AUTOTEL_TERMINAL_PORT || 4319),\n host: process.env.AUTOTEL_TERMINAL_HOST || '127.0.0.1',\n title: process.env.AUTOTEL_TERMINAL_TITLE,\n ai: {},\n };\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const next = argv[i + 1];\n\n if (arg === '--help' || arg === '-h') {\n printHelp();\n return null;\n }\n if (arg === '--version' || arg === '-v') {\n printVersion();\n return null;\n }\n if ((arg === '--port' || arg === '-p') && next) {\n options.port = Number(next);\n i++;\n continue;\n }\n if ((arg === '--host' || arg === '-H') && next) {\n options.host = next;\n i++;\n continue;\n }\n if ((arg === '--title' || arg === '-t') && next) {\n options.title = next;\n i++;\n continue;\n }\n if (arg === '--ai-provider' && next) {\n options.ai.provider = next as AIProviderType;\n i++;\n continue;\n }\n if (arg === '--ai-model' && next) {\n options.ai.model = next;\n i++;\n continue;\n }\n if (arg === '--ai-api-key' && next) {\n options.ai.apiKey = next;\n i++;\n continue;\n }\n if (arg === '--ai-base-url' && next) {\n options.ai.baseUrl = next;\n i++;\n }\n }\n\n return options;\n}\n\nconst OTLP_ROUTES = new Set(['/v1/traces', '/v1/logs', '/v1/metrics']);\n\nasync function main(): Promise<void> {\n const options = parseArgs(process.argv.slice(2));\n if (!options) {\n process.exit(0);\n }\n\n const spanStream = new CliTerminalSpanStream();\n const logStream = getTerminalLogStream();\n\n renderTerminal(\n {\n title:\n options.title || `Autotel Terminal (${options.host}:${options.port})`,\n ai: options.ai,\n },\n spanStream,\n );\n\n const requestHandler = async (\n req: IncomingMessage,\n res: ServerResponse,\n ): Promise<void> => {\n if (req.method === 'GET' && req.url === '/healthz') {\n sendJson(res, 200, { ok: true });\n return;\n }\n\n if (req.method !== 'POST' || !OTLP_ROUTES.has(req.url ?? '')) {\n sendJson(res, 404, { error: 'Not found' });\n return;\n }\n\n try {\n const payload = await readJsonBody(req);\n\n if (req.url === '/v1/traces') {\n const events = parseOtlpEvents(payload);\n for (const event of events) {\n spanStream.push(event);\n }\n sendJson(res, 200, { acceptedSpans: events.length });\n return;\n }\n\n if (req.url === '/v1/logs') {\n const events = parseOtlpLogEvents(payload);\n for (const event of events) {\n logStream.emit(event);\n }\n sendJson(res, 200, { acceptedLogs: events.length });\n return;\n }\n\n if (req.url === '/v1/metrics') {\n const count = countOtlpMetrics(payload);\n sendJson(res, 200, { acceptedMetrics: count });\n return;\n }\n } catch (error) {\n sendJson(res, 400, {\n error: 'Invalid OTLP JSON payload',\n message: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n const server = createServer(requestHandler);\n\n // Bind both loopback families when host is loopback, so a `localhost` proxy\n // reaches us whether it resolves to 127.0.0.1 or ::1 (the macOS IPv6 footgun).\n const listeners = listenLoopbackDualStack({\n primary: server,\n port: options.port,\n host: options.host,\n attachSecondary: (s) => s.on('request', requestHandler),\n });\n\n const { addresses, warnings } = await listeners.ready;\n process.stdout.write(\n `[autotel-terminal] listening on ${addresses.join(' + ')}\\n`,\n );\n process.stdout.write(\n '[autotel-terminal] endpoints: /v1/traces, /v1/logs, /v1/metrics\\n',\n );\n process.stdout.write(\n '[autotel-terminal] set OTEL_EXPORTER_OTLP_PROTOCOL=http/json and OTEL_EXPORTER_OTLP_ENDPOINT to this host/port\\n',\n );\n for (const w of warnings) {\n process.stdout.write(`[autotel-terminal] ⚠ ${w}\\n`);\n }\n\n const shutdown = () => {\n Promise.all([\n new Promise<void>((r) => server.close(() => r())),\n listeners.closeSibling(),\n ]).then(() => process.exit(0));\n };\n process.on('SIGINT', shutdown);\n process.on('SIGTERM', shutdown);\n}\n\nmain().catch((error) => {\n process.stderr.write(\n `[autotel-terminal] failed to start: ${error instanceof Error ? error.message : String(error)}\\n`,\n );\n process.exit(1);\n});\n"],"mappings":";;;;;;;;AAEA,MAAM,WAAW,IAAI,IAAI;CAAC;CAAa;CAAa;AAAK,CAAC;;AAU1D,SAAgB,cAAc,MAAc,MAAsB;CAChE,OAAO,KAAK,SAAS,GAAG,IAAI,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,GAAG;AAC/D;;;;;;;;;;;AAYA,SAAgB,wBAAwB,MAKlB;CACpB,MAAM,EAAE,SAAS,MAAM,MAAM,oBAAoB;CACjD,IAAI;CA0CJ,OAAO;EACL,WAzCgB,SACf,YAAY;GACX,MAAM,YAAsB,CAAC;GAC7B,MAAM,WAAqB,CAAC;GAC5B,MAAM,cAAc,SAAS,cAAc,cAAc;GAEzD,QAAQ,OAAO,MAAM,mBAAmB;IACtC,MAAM,OAAO,QAAQ,QAAQ;IAC7B,MAAM,eACJ,QAAQ,OAAO,SAAS,WAAW,KAAK,OAAO;IACjD,UAAU,KAAK,cAAc,aAAa,YAAY,CAAC;IAEvD,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG;KACvB,QAAQ;MAAE;MAAW;KAAS,CAAC;KAC/B;IACF;IAEA,MAAM,cAAc,gBAAgB,QAAQ,cAAc;IAC1D,MAAM,gCAAiB;IACvB,gBAAgB,CAAC;IAEjB,MAAM,WAAW,MAAa;KAC5B,EAAE,MAAM;KACR,SAAS,KACP,uBAAuB,cAAc,aAAa,YAAY,EAAE,IAAI,EAAE,QAAQ,uBACvD,gBAAgB,QAAQ,SAAS,OAAO,sCACjE;KACA,QAAQ;MAAE;MAAW;KAAS,CAAC;IACjC;IACA,EAAE,KAAK,SAAS,OAAO;IACvB,EAAE,OAAO,cAAc,mBAAmB;KACxC,EAAE,IAAI,SAAS,OAAO;KACtB,UAAU;KACV,UAAU,KAAK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AAU,QAAQ;CAC7B,QAAQ,GAAG,WAAW,QAAQ;AAChC;AAEA,KAAK,CAAC,CAAC,OAAO,UAAU;CACtB,QAAQ,OAAO,MACb,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAChG;CACA,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["#subscribers","path","getTerminalLogStream"],"sources":["../src/listen.ts","../src/cli-stream.ts","../src/otlp-http-json.ts","../src/cli.ts"],"sourcesContent":["import { createServer, type Server } from 'node:http';\n\nconst LOOPBACK = new Set(['localhost', '127.0.0.1', '::1']);\n\nexport interface LoopbackListeners {\n /** Resolves once the primary and (attempted) sibling listeners are up. */\n ready: Promise<{ addresses: string[]; warnings: string[] }>;\n /** Close the sibling listener (the primary server is owned by the caller). */\n closeSibling: () => Promise<void>;\n}\n\n/** Format host:port, bracketing IPv6 literals (e.g. `[::1]:4319`). */\nexport function formatAddress(host: string, port: number): string {\n return host.includes(':') ? `[${host}]:${port}` : `${host}:${port}`;\n}\n\n/**\n * Listen on `host:port`, and when `host` is a loopback literal, ALSO listen on\n * the sibling loopback family (IPv4 ⟷ IPv6) so a client reaches the collector\n * whether the OS resolves `localhost` to `127.0.0.1` or `::1`.\n *\n * Kills a silent footgun: a dev-server proxy targeting `http://localhost:PORT`\n * on macOS resolves `localhost` to `::1`, but a collector bound only to\n * `127.0.0.1` never receives the request — spans vanish with no error. If the\n * sibling family cannot bind, it is surfaced as a warning, never fatal.\n */\nexport function listenLoopbackDualStack(args: {\n primary: Server;\n port: number;\n host: string;\n attachSecondary: (server: Server) => void;\n}): LoopbackListeners {\n const { primary, port, host, attachSecondary } = args;\n let sibling: Server | undefined;\n\n const ready = new Promise<{ addresses: string[]; warnings: string[] }>(\n (resolve) => {\n const addresses: string[] = [];\n const warnings: string[] = [];\n const primaryHost = host === 'localhost' ? '127.0.0.1' : host;\n\n primary.listen(port, primaryHost, () => {\n const addr = primary.address();\n const resolvedPort =\n addr && typeof addr === 'object' ? addr.port : port;\n addresses.push(formatAddress(primaryHost, resolvedPort));\n\n if (!LOOPBACK.has(host)) {\n resolve({ addresses, warnings });\n return;\n }\n\n const siblingHost = primaryHost === '::1' ? '127.0.0.1' : '::1';\n const s = createServer();\n attachSecondary(s);\n\n const onError = (e: Error) => {\n s.close();\n warnings.push(\n `could not also bind ${formatAddress(siblingHost, resolvedPort)} (${e.message}); ` +\n `clients using the ${siblingHost === '::1' ? 'IPv6' : 'IPv4'} form of \"localhost\" may not connect.`,\n );\n resolve({ addresses, warnings });\n };\n s.once('error', onError);\n s.listen(resolvedPort, siblingHost, () => {\n s.off('error', onError);\n sibling = s;\n addresses.push(formatAddress(siblingHost, resolvedPort));\n resolve({ addresses, warnings });\n });\n });\n },\n );\n\n return {\n ready,\n closeSibling: () =>\n new Promise<void>((res) => {\n if (!sibling) return res();\n sibling.close(() => res());\n }),\n };\n}\n","import type { TerminalSpanEvent, TerminalSpanStream } from './span-stream';\n\ntype Subscriber = (event: TerminalSpanEvent) => void;\n\n/**\n * In-memory stream implementation for standalone CLI ingestion.\n */\nexport class CliTerminalSpanStream implements TerminalSpanStream {\n #subscribers = new Set<Subscriber>();\n\n onSpanEnd(callback: Subscriber): () => void {\n this.#subscribers.add(callback);\n return () => {\n this.#subscribers.delete(callback);\n };\n }\n\n push(event: TerminalSpanEvent): void {\n for (const subscriber of this.#subscribers) {\n subscriber(event);\n }\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { TerminalSpanEvent, SpanEvent, SpanLink } from './span-stream';\nimport type { TerminalLogEvent, LogLevel } from './lib/log-model';\n\nconst MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB\n\ntype OtlpAnyValue = {\n stringValue?: string;\n boolValue?: boolean;\n intValue?: string | number;\n doubleValue?: number;\n bytesValue?: string;\n};\n\ntype OtlpKeyValue = {\n key: string;\n value?: OtlpAnyValue;\n};\n\ntype OtlpSpan = {\n traceId?: string;\n spanId?: string;\n parentSpanId?: string;\n name?: string;\n kind?: number | string;\n startTimeUnixNano?: string;\n endTimeUnixNano?: string;\n attributes?: OtlpKeyValue[];\n status?: {\n code?: number | string;\n };\n events?: {\n timeUnixNano?: string;\n name?: string;\n attributes?: OtlpKeyValue[];\n }[];\n links?: {\n traceId?: string;\n spanId?: string;\n attributes?: OtlpKeyValue[];\n }[];\n};\n\nfunction anyValueToPrimitive(value: OtlpAnyValue | undefined): unknown {\n if (!value) return undefined;\n if (value.stringValue !== undefined) return value.stringValue;\n if (value.boolValue !== undefined) return value.boolValue;\n if (value.intValue !== undefined) {\n const num = Number(value.intValue);\n return Number.isNaN(num) ? value.intValue : num;\n }\n if (value.doubleValue !== undefined) return value.doubleValue;\n if (value.bytesValue !== undefined) return value.bytesValue;\n return undefined;\n}\n\nfunction attrsToRecord(\n attributes: OtlpKeyValue[] | undefined,\n): Record<string, unknown> {\n if (!attributes || attributes.length === 0) return {};\n const out: Record<string, unknown> = {};\n for (const attribute of attributes) {\n out[attribute.key] = anyValueToPrimitive(attribute.value);\n }\n return out;\n}\n\nfunction normalizeHexId(\n id: string | undefined,\n expectedHexLength: number,\n): string {\n if (!id) return ''.padStart(expectedHexLength, '0');\n const trimmed = id.trim();\n if (/^[a-fA-F0-9]+$/.test(trimmed)) {\n return trimmed\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n try {\n const decoded = Buffer.from(trimmed, 'base64').toString('hex');\n if (decoded.length > 0) {\n return decoded\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n } catch {\n // ignore and fall through\n }\n return ''.padStart(expectedHexLength, '0');\n}\n\nfunction toMs(unixNano: string | undefined): number {\n if (!unixNano) return Date.now();\n const parsed = Number(unixNano);\n if (Number.isNaN(parsed)) return Date.now();\n return parsed / 1_000_000;\n}\n\nfunction mapStatus(\n code: number | string | undefined,\n): 'OK' | 'ERROR' | 'UNSET' {\n const normalized = typeof code === 'string' ? code.toUpperCase() : code;\n if (\n normalized === 1 ||\n normalized === 'STATUS_CODE_OK' ||\n normalized === 'OK'\n )\n return 'OK';\n if (\n normalized === 2 ||\n normalized === 'STATUS_CODE_ERROR' ||\n normalized === 'ERROR'\n ) {\n return 'ERROR';\n }\n return 'UNSET';\n}\n\nfunction mapKind(kind: number | string | undefined): string {\n if (typeof kind === 'string') return kind.toUpperCase();\n switch (kind) {\n case 1: {\n return 'INTERNAL';\n }\n case 2: {\n return 'SERVER';\n }\n case 3: {\n return 'CLIENT';\n }\n case 4: {\n return 'PRODUCER';\n }\n case 5: {\n return 'CONSUMER';\n }\n default: {\n return 'INTERNAL';\n }\n }\n}\n\nfunction* extractSpans(\n payload: unknown,\n): Generator<{ span: OtlpSpan; resourceAttrs: Record<string, unknown> }> {\n if (!payload || typeof payload !== 'object') return;\n const resourceSpans = (payload as { resourceSpans?: unknown[] })\n .resourceSpans;\n if (!Array.isArray(resourceSpans)) return;\n for (const resourceSpan of resourceSpans) {\n if (!resourceSpan || typeof resourceSpan !== 'object') continue;\n const resource = (resourceSpan as { resource?: { attributes?: OtlpKeyValue[] } }).resource;\n const resourceAttrs = attrsToRecord(resource?.attributes);\n const scopeSpans = (resourceSpan as { scopeSpans?: unknown[] }).scopeSpans;\n if (!Array.isArray(scopeSpans)) continue;\n for (const scopeSpan of scopeSpans) {\n if (!scopeSpan || typeof scopeSpan !== 'object') continue;\n const spans = (scopeSpan as { spans?: unknown[] }).spans;\n if (!Array.isArray(spans)) continue;\n for (const span of spans) {\n if (span && typeof span === 'object') {\n yield { span: span as OtlpSpan, resourceAttrs };\n }\n }\n }\n }\n}\n\nexport function otlpSpanToTerminalEvent(\n span: OtlpSpan,\n resourceAttrs: Record<string, unknown> = {},\n): TerminalSpanEvent {\n const startTime = toMs(span.startTimeUnixNano);\n const endTime = toMs(span.endTimeUnixNano);\n const spanAttrs = attrsToRecord(span.attributes);\n // Merge resource attributes (e.g. service.name) under span attributes,\n // with span-level attributes taking precedence\n const mergedAttrs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(resourceAttrs)) {\n mergedAttrs[k] = v;\n }\n for (const [k, v] of Object.entries(spanAttrs)) {\n mergedAttrs[k] = v;\n }\n const parsedEvents: SpanEvent[] | undefined = span.events?.length\n ? span.events.map((e) => ({\n name: e.name || '',\n timeMs: toMs(e.timeUnixNano),\n attributes: attrsToRecord(e.attributes),\n }))\n : undefined;\n\n const parsedLinks: SpanLink[] | undefined = span.links?.length\n ? span.links.map((l) => ({\n traceId: normalizeHexId(l.traceId, 32),\n spanId: normalizeHexId(l.spanId, 16),\n attributes: attrsToRecord(l.attributes),\n }))\n : undefined;\n\n return {\n name: span.name || 'unnamed',\n spanId: normalizeHexId(span.spanId, 16),\n traceId: normalizeHexId(span.traceId, 32),\n parentSpanId: span.parentSpanId\n ? normalizeHexId(span.parentSpanId, 16)\n : undefined,\n startTime,\n endTime,\n durationMs: Math.max(0, endTime - startTime),\n status: mapStatus(span.status?.code),\n kind: mapKind(span.kind),\n attributes: mergedAttrs,\n ...(parsedEvents ? { events: parsedEvents } : {}),\n ...(parsedLinks ? { links: parsedLinks } : {}),\n };\n}\n\nexport async function readJsonBody(req: IncomingMessage): Promise<unknown> {\n const chunks: Buffer[] = [];\n let totalLength = 0;\n for await (const chunk of req) {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n totalLength += buf.length;\n if (totalLength > MAX_BODY_BYTES) {\n throw new Error(`Body exceeds ${MAX_BODY_BYTES} byte limit`);\n }\n chunks.push(buf);\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (!raw) return {};\n return JSON.parse(raw);\n}\n\nexport function sendJson(\n res: ServerResponse,\n status: number,\n data: Record<string, unknown>,\n): void {\n res.statusCode = status;\n res.setHeader('content-type', 'application/json');\n res.end(JSON.stringify(data));\n}\n\nexport function parseOtlpEvents(payload: unknown): TerminalSpanEvent[] {\n const events: TerminalSpanEvent[] = [];\n for (const { span, resourceAttrs } of extractSpans(payload)) {\n events.push(otlpSpanToTerminalEvent(span, resourceAttrs));\n }\n return events;\n}\n\n// --- OTLP Log parsing ---\n\ntype OtlpLogRecord = {\n timeUnixNano?: string;\n observedTimeUnixNano?: string;\n severityNumber?: number;\n severityText?: string;\n body?: OtlpAnyValue;\n attributes?: OtlpKeyValue[];\n traceId?: string;\n spanId?: string;\n};\n\nfunction mapSeverityToLevel(\n severityNumber?: number,\n severityText?: string,\n): LogLevel {\n if (severityText) {\n const lower = severityText.toLowerCase();\n if (lower.startsWith('debug') || lower === 'trace') return 'debug';\n if (lower.startsWith('info')) return 'info';\n if (lower.startsWith('warn')) return 'warn';\n if (lower.startsWith('error') || lower.startsWith('fatal')) return 'error';\n }\n if (severityNumber !== undefined) {\n if (severityNumber <= 4) return 'debug';\n if (severityNumber <= 8) return 'debug';\n if (severityNumber <= 12) return 'info';\n if (severityNumber <= 16) return 'warn';\n return 'error';\n }\n return 'info';\n}\n\nfunction bodyToMessage(body: OtlpAnyValue | undefined): string {\n if (!body) return '';\n const value = anyValueToPrimitive(body);\n return value === undefined ? '' : String(value);\n}\n\nfunction* extractLogRecords(payload: unknown): Generator<OtlpLogRecord> {\n if (!payload || typeof payload !== 'object') return;\n const resourceLogs = (payload as { resourceLogs?: unknown[] }).resourceLogs;\n if (!Array.isArray(resourceLogs)) return;\n for (const resourceLog of resourceLogs) {\n if (!resourceLog || typeof resourceLog !== 'object') continue;\n const scopeLogs = (resourceLog as { scopeLogs?: unknown[] }).scopeLogs;\n if (!Array.isArray(scopeLogs)) continue;\n for (const scopeLog of scopeLogs) {\n if (!scopeLog || typeof scopeLog !== 'object') continue;\n const logRecords = (scopeLog as { logRecords?: unknown[] }).logRecords;\n if (!Array.isArray(logRecords)) continue;\n for (const record of logRecords) {\n if (record && typeof record === 'object') {\n yield record as OtlpLogRecord;\n }\n }\n }\n }\n}\n\nexport function parseOtlpLogEvents(payload: unknown): TerminalLogEvent[] {\n const events: TerminalLogEvent[] = [];\n for (const record of extractLogRecords(payload)) {\n const time = toMs(record.timeUnixNano || record.observedTimeUnixNano);\n events.push({\n time,\n level: mapSeverityToLevel(record.severityNumber, record.severityText),\n message: bodyToMessage(record.body),\n traceId: record.traceId ? normalizeHexId(record.traceId, 32) : undefined,\n spanId: record.spanId ? normalizeHexId(record.spanId, 16) : undefined,\n attributes: attrsToRecord(record.attributes),\n });\n }\n return events;\n}\n\n// --- OTLP Metrics parsing (accept and count) ---\n\nexport function countOtlpMetrics(payload: unknown): number {\n if (!payload || typeof payload !== 'object') return 0;\n let count = 0;\n const resourceMetrics = (payload as { resourceMetrics?: unknown[] })\n .resourceMetrics;\n if (!Array.isArray(resourceMetrics)) return 0;\n for (const resourceMetric of resourceMetrics) {\n if (!resourceMetric || typeof resourceMetric !== 'object') continue;\n const scopeMetrics = (resourceMetric as { scopeMetrics?: unknown[] })\n .scopeMetrics;\n if (!Array.isArray(scopeMetrics)) continue;\n for (const scopeMetric of scopeMetrics) {\n if (!scopeMetric || typeof scopeMetric !== 'object') continue;\n const metrics = (scopeMetric as { metrics?: unknown[] }).metrics;\n if (Array.isArray(metrics)) {\n count += metrics.length;\n }\n }\n }\n return count;\n}\n","#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport path from 'node:path';\nimport { renderTerminal } from './index';\nimport { listenLoopbackDualStack } from './listen';\nimport { getTerminalLogStream } from './log-stream';\nimport { CliTerminalSpanStream } from './cli-stream';\nimport {\n countOtlpMetrics,\n parseOtlpEvents,\n parseOtlpLogEvents,\n readJsonBody,\n sendJson,\n} from './otlp-http-json';\n\nimport type { AIConfig, AIProviderType } from './ai/types';\n\ntype CliOptions = {\n port: number;\n host: string;\n title?: string;\n ai: Partial<AIConfig>;\n};\n\nfunction printHelp(): void {\n process.stdout.write(\n String.raw`autotel-terminal - Standalone OTLP receiver with terminal dashboard\n\nUsage: autotel-terminal [options]\n\nOptions:\n -p, --port <port> Port to listen on (default: 4319, env: AUTOTEL_TERMINAL_PORT)\n -H, --host <host> Host to bind to (default: 127.0.0.1, env: AUTOTEL_TERMINAL_HOST)\n -t, --title <title> Dashboard title (env: AUTOTEL_TERMINAL_TITLE)\n -h, --help Show this help message\n -v, --version Show version number\n\nAI Options:\n --ai-provider <provider> AI provider: ollama, openai, openai-compatible (env: AI_PROVIDER)\n --ai-model <model> AI model name (env: AI_MODEL)\n --ai-api-key <key> API key for cloud providers (env: AI_API_KEY)\n --ai-base-url <url> Custom AI endpoint URL (env: AI_BASE_URL)\n\n Auto-detection: if Ollama is running locally, it is used automatically.\n If OPENAI_API_KEY is set, OpenAI is used. Press 'a' in the dashboard to toggle AI.\n\nEndpoints:\n POST /v1/traces Receive OTLP JSON trace data\n POST /v1/logs Receive OTLP JSON log data\n POST /v1/metrics Receive OTLP JSON metric data (accepted and counted)\n GET /healthz Health check\n\nExamples:\n npx autotel-terminal\n npx autotel-terminal --ai-provider ollama --ai-model granite4\n AI_API_KEY=sk-... npx autotel-terminal --ai-provider openai --ai-model gpt-4o\n` + '\\n',\n );\n}\n\nfunction printVersion(): void {\n try {\n const dir = import.meta.dirname ?? new URL('.', import.meta.url).pathname;\n const pkgPath = path.resolve(dir, '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n process.stdout.write(`${pkg.version}\\n`);\n } catch {\n process.stdout.write('unknown\\n');\n }\n}\n\nfunction parseArgs(argv: string[]): CliOptions | null {\n const options: CliOptions = {\n port: Number(process.env.AUTOTEL_TERMINAL_PORT || 4319),\n host: process.env.AUTOTEL_TERMINAL_HOST || '127.0.0.1',\n title: process.env.AUTOTEL_TERMINAL_TITLE,\n ai: {},\n };\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const next = argv[i + 1];\n\n if (arg === '--help' || arg === '-h') {\n printHelp();\n return null;\n }\n if (arg === '--version' || arg === '-v') {\n printVersion();\n return null;\n }\n if ((arg === '--port' || arg === '-p') && next) {\n options.port = Number(next);\n i++;\n continue;\n }\n if ((arg === '--host' || arg === '-H') && next) {\n options.host = next;\n i++;\n continue;\n }\n if ((arg === '--title' || arg === '-t') && next) {\n options.title = next;\n i++;\n continue;\n }\n if (arg === '--ai-provider' && next) {\n options.ai.provider = next as AIProviderType;\n i++;\n continue;\n }\n if (arg === '--ai-model' && next) {\n options.ai.model = next;\n i++;\n continue;\n }\n if (arg === '--ai-api-key' && next) {\n options.ai.apiKey = next;\n i++;\n continue;\n }\n if (arg === '--ai-base-url' && next) {\n options.ai.baseUrl = next;\n i++;\n }\n }\n\n return options;\n}\n\nconst OTLP_ROUTES = new Set(['/v1/traces', '/v1/logs', '/v1/metrics']);\n\nasync function main(): Promise<void> {\n const options = parseArgs(process.argv.slice(2));\n if (!options) {\n process.exit(0);\n }\n\n const spanStream = new CliTerminalSpanStream();\n const logStream = getTerminalLogStream();\n\n renderTerminal(\n {\n title:\n options.title || `Autotel Terminal (${options.host}:${options.port})`,\n ai: options.ai,\n },\n spanStream,\n );\n\n const requestHandler = async (\n req: IncomingMessage,\n res: ServerResponse,\n ): Promise<void> => {\n if (req.method === 'GET' && req.url === '/healthz') {\n sendJson(res, 200, { ok: true });\n return;\n }\n\n if (req.method !== 'POST' || !OTLP_ROUTES.has(req.url ?? '')) {\n sendJson(res, 404, { error: 'Not found' });\n return;\n }\n\n try {\n const payload = await readJsonBody(req);\n\n if (req.url === '/v1/traces') {\n const events = parseOtlpEvents(payload);\n for (const event of events) {\n spanStream.push(event);\n }\n sendJson(res, 200, { acceptedSpans: events.length });\n return;\n }\n\n if (req.url === '/v1/logs') {\n const events = parseOtlpLogEvents(payload);\n for (const event of events) {\n logStream.emit(event);\n }\n sendJson(res, 200, { acceptedLogs: events.length });\n return;\n }\n\n if (req.url === '/v1/metrics') {\n const count = countOtlpMetrics(payload);\n sendJson(res, 200, { acceptedMetrics: count });\n return;\n }\n } catch (error) {\n sendJson(res, 400, {\n error: 'Invalid OTLP JSON payload',\n message: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n const server = createServer(requestHandler);\n\n // Bind both loopback families when host is loopback, so a `localhost` proxy\n // reaches us whether it resolves to 127.0.0.1 or ::1 (the macOS IPv6 footgun).\n const listeners = listenLoopbackDualStack({\n primary: server,\n port: options.port,\n host: options.host,\n attachSecondary: (s) => s.on('request', requestHandler),\n });\n\n const { addresses, warnings } = await listeners.ready;\n process.stdout.write(\n `[autotel-terminal] listening on ${addresses.join(' + ')}\\n`,\n );\n process.stdout.write(\n '[autotel-terminal] endpoints: /v1/traces, /v1/logs, /v1/metrics\\n',\n );\n process.stdout.write(\n '[autotel-terminal] set OTEL_EXPORTER_OTLP_PROTOCOL=http/json and OTEL_EXPORTER_OTLP_ENDPOINT to this host/port\\n',\n );\n for (const w of warnings) {\n process.stdout.write(`[autotel-terminal] ⚠ ${w}\\n`);\n }\n\n const shutdown = () => {\n Promise.all([\n new Promise<void>((r) => server.close(() => r())),\n listeners.closeSibling(),\n ]).then(() => process.exit(0));\n };\n process.on('SIGINT', shutdown);\n process.on('SIGTERM', shutdown);\n}\n\nmain().catch((error) => {\n process.stderr.write(\n `[autotel-terminal] failed to start: ${error instanceof Error ? error.message : String(error)}\\n`,\n );\n process.exit(1);\n});\n"],"mappings":";;;;;;;;AAEA,MAAM,2BAAW,IAAI,IAAI;CAAC;CAAa;CAAa;AAAK,CAAC;;AAU1D,SAAgB,cAAc,MAAc,MAAsB;CAChE,OAAO,KAAK,SAAS,GAAG,IAAI,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,GAAG;AAC/D;;;;;;;;;;;AAYA,SAAgB,wBAAwB,MAKlB;CACpB,MAAM,EAAE,SAAS,MAAM,MAAM,oBAAoB;CACjD,IAAI;CA0CJ,OAAO;EACL,WAzCgB,SACf,YAAY;GACX,MAAM,YAAsB,CAAC;GAC7B,MAAM,WAAqB,CAAC;GAC5B,MAAM,cAAc,SAAS,cAAc,cAAc;GAEzD,QAAQ,OAAO,MAAM,mBAAmB;IACtC,MAAM,OAAO,QAAQ,QAAQ;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ACH;CACF;CAEA,MAAM,qCAAsB,cAAc;CAI1C,MAAM,YAAY,wBAAwB;EACxC,SAAS;EACT,MAAM,QAAQ;EACd,MAAM,QAAQ;EACd,kBAAkB,MAAM,EAAE,GAAG,WAAW,cAAc;CACxD,CAAC;CAED,MAAM,EAAE,WAAW,aAAa,MAAM,UAAU;CAChD,QAAQ,OAAO,MACb,mCAAmC,UAAU,KAAK,KAAK,EAAE,GAC3D;CACA,QAAQ,OAAO,MACb,mEACF;CACA,QAAQ,OAAO,MACb,kHACF;CACA,KAAK,MAAM,KAAK,UACd,QAAQ,OAAO,MAAM,wBAAwB,EAAE,GAAG;CAGpD,MAAM,iBAAiB;EACrB,QAAQ,IAAI,CACV,IAAI,SAAe,MAAM,OAAO,YAAY,EAAE,CAAC,CAAC,GAChD,UAAU,aAAa,CACzB,CAAC,CAAC,CAAC,WAAW,QAAQ,KAAK,CAAC,CAAC;CAC/B;CACA,QAAQ,GAAG,UAAU,QAAQ;CAC7B,QAAQ,GAAG,WAAW,QAAQ;AAChC;AAEA,KAAK,CAAC,CAAC,OAAO,UAAU;CACtB,QAAQ,OAAO,MACb,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAChG;CACA,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as getTerminalLogStream, i as renderTerminal } from "./src-
|
|
2
|
+
import { a as getTerminalLogStream, i as renderTerminal } from "./src-BbKL64Rh.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
7
7
|
//#region src/listen.ts
|
|
8
|
-
const LOOPBACK = new Set([
|
|
8
|
+
const LOOPBACK = /* @__PURE__ */ new Set([
|
|
9
9
|
"localhost",
|
|
10
10
|
"127.0.0.1",
|
|
11
11
|
"::1"
|
|
@@ -391,7 +391,7 @@ function parseArgs(argv) {
|
|
|
391
391
|
}
|
|
392
392
|
return options;
|
|
393
393
|
}
|
|
394
|
-
const OTLP_ROUTES = new Set([
|
|
394
|
+
const OTLP_ROUTES = /* @__PURE__ */ new Set([
|
|
395
395
|
"/v1/traces",
|
|
396
396
|
"/v1/logs",
|
|
397
397
|
"/v1/metrics"
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":["#subscribers"],"sources":["../src/listen.ts","../src/cli-stream.ts","../src/otlp-http-json.ts","../src/cli.ts"],"sourcesContent":["import { createServer, type Server } from 'node:http';\n\nconst LOOPBACK = new Set(['localhost', '127.0.0.1', '::1']);\n\nexport interface LoopbackListeners {\n /** Resolves once the primary and (attempted) sibling listeners are up. */\n ready: Promise<{ addresses: string[]; warnings: string[] }>;\n /** Close the sibling listener (the primary server is owned by the caller). */\n closeSibling: () => Promise<void>;\n}\n\n/** Format host:port, bracketing IPv6 literals (e.g. `[::1]:4319`). */\nexport function formatAddress(host: string, port: number): string {\n return host.includes(':') ? `[${host}]:${port}` : `${host}:${port}`;\n}\n\n/**\n * Listen on `host:port`, and when `host` is a loopback literal, ALSO listen on\n * the sibling loopback family (IPv4 ⟷ IPv6) so a client reaches the collector\n * whether the OS resolves `localhost` to `127.0.0.1` or `::1`.\n *\n * Kills a silent footgun: a dev-server proxy targeting `http://localhost:PORT`\n * on macOS resolves `localhost` to `::1`, but a collector bound only to\n * `127.0.0.1` never receives the request — spans vanish with no error. If the\n * sibling family cannot bind, it is surfaced as a warning, never fatal.\n */\nexport function listenLoopbackDualStack(args: {\n primary: Server;\n port: number;\n host: string;\n attachSecondary: (server: Server) => void;\n}): LoopbackListeners {\n const { primary, port, host, attachSecondary } = args;\n let sibling: Server | undefined;\n\n const ready = new Promise<{ addresses: string[]; warnings: string[] }>(\n (resolve) => {\n const addresses: string[] = [];\n const warnings: string[] = [];\n const primaryHost = host === 'localhost' ? '127.0.0.1' : host;\n\n primary.listen(port, primaryHost, () => {\n const addr = primary.address();\n const resolvedPort =\n addr && typeof addr === 'object' ? addr.port : port;\n addresses.push(formatAddress(primaryHost, resolvedPort));\n\n if (!LOOPBACK.has(host)) {\n resolve({ addresses, warnings });\n return;\n }\n\n const siblingHost = primaryHost === '::1' ? '127.0.0.1' : '::1';\n const s = createServer();\n attachSecondary(s);\n\n const onError = (e: Error) => {\n s.close();\n warnings.push(\n `could not also bind ${formatAddress(siblingHost, resolvedPort)} (${e.message}); ` +\n `clients using the ${siblingHost === '::1' ? 'IPv6' : 'IPv4'} form of \"localhost\" may not connect.`,\n );\n resolve({ addresses, warnings });\n };\n s.once('error', onError);\n s.listen(resolvedPort, siblingHost, () => {\n s.off('error', onError);\n sibling = s;\n addresses.push(formatAddress(siblingHost, resolvedPort));\n resolve({ addresses, warnings });\n });\n });\n },\n );\n\n return {\n ready,\n closeSibling: () =>\n new Promise<void>((res) => {\n if (!sibling) return res();\n sibling.close(() => res());\n }),\n };\n}\n","import type { TerminalSpanEvent, TerminalSpanStream } from './span-stream';\n\ntype Subscriber = (event: TerminalSpanEvent) => void;\n\n/**\n * In-memory stream implementation for standalone CLI ingestion.\n */\nexport class CliTerminalSpanStream implements TerminalSpanStream {\n #subscribers = new Set<Subscriber>();\n\n onSpanEnd(callback: Subscriber): () => void {\n this.#subscribers.add(callback);\n return () => {\n this.#subscribers.delete(callback);\n };\n }\n\n push(event: TerminalSpanEvent): void {\n for (const subscriber of this.#subscribers) {\n subscriber(event);\n }\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { TerminalSpanEvent, SpanEvent, SpanLink } from './span-stream';\nimport type { TerminalLogEvent, LogLevel } from './lib/log-model';\n\nconst MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB\n\ntype OtlpAnyValue = {\n stringValue?: string;\n boolValue?: boolean;\n intValue?: string | number;\n doubleValue?: number;\n bytesValue?: string;\n};\n\ntype OtlpKeyValue = {\n key: string;\n value?: OtlpAnyValue;\n};\n\ntype OtlpSpan = {\n traceId?: string;\n spanId?: string;\n parentSpanId?: string;\n name?: string;\n kind?: number | string;\n startTimeUnixNano?: string;\n endTimeUnixNano?: string;\n attributes?: OtlpKeyValue[];\n status?: {\n code?: number | string;\n };\n events?: {\n timeUnixNano?: string;\n name?: string;\n attributes?: OtlpKeyValue[];\n }[];\n links?: {\n traceId?: string;\n spanId?: string;\n attributes?: OtlpKeyValue[];\n }[];\n};\n\nfunction anyValueToPrimitive(value: OtlpAnyValue | undefined): unknown {\n if (!value) return undefined;\n if (value.stringValue !== undefined) return value.stringValue;\n if (value.boolValue !== undefined) return value.boolValue;\n if (value.intValue !== undefined) {\n const num = Number(value.intValue);\n return Number.isNaN(num) ? value.intValue : num;\n }\n if (value.doubleValue !== undefined) return value.doubleValue;\n if (value.bytesValue !== undefined) return value.bytesValue;\n return undefined;\n}\n\nfunction attrsToRecord(\n attributes: OtlpKeyValue[] | undefined,\n): Record<string, unknown> {\n if (!attributes || attributes.length === 0) return {};\n const out: Record<string, unknown> = {};\n for (const attribute of attributes) {\n out[attribute.key] = anyValueToPrimitive(attribute.value);\n }\n return out;\n}\n\nfunction normalizeHexId(\n id: string | undefined,\n expectedHexLength: number,\n): string {\n if (!id) return ''.padStart(expectedHexLength, '0');\n const trimmed = id.trim();\n if (/^[a-fA-F0-9]+$/.test(trimmed)) {\n return trimmed\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n try {\n const decoded = Buffer.from(trimmed, 'base64').toString('hex');\n if (decoded.length > 0) {\n return decoded\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n } catch {\n // ignore and fall through\n }\n return ''.padStart(expectedHexLength, '0');\n}\n\nfunction toMs(unixNano: string | undefined): number {\n if (!unixNano) return Date.now();\n const parsed = Number(unixNano);\n if (Number.isNaN(parsed)) return Date.now();\n return parsed / 1_000_000;\n}\n\nfunction mapStatus(\n code: number | string | undefined,\n): 'OK' | 'ERROR' | 'UNSET' {\n const normalized = typeof code === 'string' ? code.toUpperCase() : code;\n if (\n normalized === 1 ||\n normalized === 'STATUS_CODE_OK' ||\n normalized === 'OK'\n )\n return 'OK';\n if (\n normalized === 2 ||\n normalized === 'STATUS_CODE_ERROR' ||\n normalized === 'ERROR'\n ) {\n return 'ERROR';\n }\n return 'UNSET';\n}\n\nfunction mapKind(kind: number | string | undefined): string {\n if (typeof kind === 'string') return kind.toUpperCase();\n switch (kind) {\n case 1: {\n return 'INTERNAL';\n }\n case 2: {\n return 'SERVER';\n }\n case 3: {\n return 'CLIENT';\n }\n case 4: {\n return 'PRODUCER';\n }\n case 5: {\n return 'CONSUMER';\n }\n default: {\n return 'INTERNAL';\n }\n }\n}\n\nfunction* extractSpans(\n payload: unknown,\n): Generator<{ span: OtlpSpan; resourceAttrs: Record<string, unknown> }> {\n if (!payload || typeof payload !== 'object') return;\n const resourceSpans = (payload as { resourceSpans?: unknown[] })\n .resourceSpans;\n if (!Array.isArray(resourceSpans)) return;\n for (const resourceSpan of resourceSpans) {\n if (!resourceSpan || typeof resourceSpan !== 'object') continue;\n const resource = (resourceSpan as { resource?: { attributes?: OtlpKeyValue[] } }).resource;\n const resourceAttrs = attrsToRecord(resource?.attributes);\n const scopeSpans = (resourceSpan as { scopeSpans?: unknown[] }).scopeSpans;\n if (!Array.isArray(scopeSpans)) continue;\n for (const scopeSpan of scopeSpans) {\n if (!scopeSpan || typeof scopeSpan !== 'object') continue;\n const spans = (scopeSpan as { spans?: unknown[] }).spans;\n if (!Array.isArray(spans)) continue;\n for (const span of spans) {\n if (span && typeof span === 'object') {\n yield { span: span as OtlpSpan, resourceAttrs };\n }\n }\n }\n }\n}\n\nexport function otlpSpanToTerminalEvent(\n span: OtlpSpan,\n resourceAttrs: Record<string, unknown> = {},\n): TerminalSpanEvent {\n const startTime = toMs(span.startTimeUnixNano);\n const endTime = toMs(span.endTimeUnixNano);\n const spanAttrs = attrsToRecord(span.attributes);\n // Merge resource attributes (e.g. service.name) under span attributes,\n // with span-level attributes taking precedence\n const mergedAttrs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(resourceAttrs)) {\n mergedAttrs[k] = v;\n }\n for (const [k, v] of Object.entries(spanAttrs)) {\n mergedAttrs[k] = v;\n }\n const parsedEvents: SpanEvent[] | undefined = span.events?.length\n ? span.events.map((e) => ({\n name: e.name || '',\n timeMs: toMs(e.timeUnixNano),\n attributes: attrsToRecord(e.attributes),\n }))\n : undefined;\n\n const parsedLinks: SpanLink[] | undefined = span.links?.length\n ? span.links.map((l) => ({\n traceId: normalizeHexId(l.traceId, 32),\n spanId: normalizeHexId(l.spanId, 16),\n attributes: attrsToRecord(l.attributes),\n }))\n : undefined;\n\n return {\n name: span.name || 'unnamed',\n spanId: normalizeHexId(span.spanId, 16),\n traceId: normalizeHexId(span.traceId, 32),\n parentSpanId: span.parentSpanId\n ? normalizeHexId(span.parentSpanId, 16)\n : undefined,\n startTime,\n endTime,\n durationMs: Math.max(0, endTime - startTime),\n status: mapStatus(span.status?.code),\n kind: mapKind(span.kind),\n attributes: mergedAttrs,\n ...(parsedEvents ? { events: parsedEvents } : {}),\n ...(parsedLinks ? { links: parsedLinks } : {}),\n };\n}\n\nexport async function readJsonBody(req: IncomingMessage): Promise<unknown> {\n const chunks: Buffer[] = [];\n let totalLength = 0;\n for await (const chunk of req) {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n totalLength += buf.length;\n if (totalLength > MAX_BODY_BYTES) {\n throw new Error(`Body exceeds ${MAX_BODY_BYTES} byte limit`);\n }\n chunks.push(buf);\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (!raw) return {};\n return JSON.parse(raw);\n}\n\nexport function sendJson(\n res: ServerResponse,\n status: number,\n data: Record<string, unknown>,\n): void {\n res.statusCode = status;\n res.setHeader('content-type', 'application/json');\n res.end(JSON.stringify(data));\n}\n\nexport function parseOtlpEvents(payload: unknown): TerminalSpanEvent[] {\n const events: TerminalSpanEvent[] = [];\n for (const { span, resourceAttrs } of extractSpans(payload)) {\n events.push(otlpSpanToTerminalEvent(span, resourceAttrs));\n }\n return events;\n}\n\n// --- OTLP Log parsing ---\n\ntype OtlpLogRecord = {\n timeUnixNano?: string;\n observedTimeUnixNano?: string;\n severityNumber?: number;\n severityText?: string;\n body?: OtlpAnyValue;\n attributes?: OtlpKeyValue[];\n traceId?: string;\n spanId?: string;\n};\n\nfunction mapSeverityToLevel(\n severityNumber?: number,\n severityText?: string,\n): LogLevel {\n if (severityText) {\n const lower = severityText.toLowerCase();\n if (lower.startsWith('debug') || lower === 'trace') return 'debug';\n if (lower.startsWith('info')) return 'info';\n if (lower.startsWith('warn')) return 'warn';\n if (lower.startsWith('error') || lower.startsWith('fatal')) return 'error';\n }\n if (severityNumber !== undefined) {\n if (severityNumber <= 4) return 'debug';\n if (severityNumber <= 8) return 'debug';\n if (severityNumber <= 12) return 'info';\n if (severityNumber <= 16) return 'warn';\n return 'error';\n }\n return 'info';\n}\n\nfunction bodyToMessage(body: OtlpAnyValue | undefined): string {\n if (!body) return '';\n const value = anyValueToPrimitive(body);\n return value === undefined ? '' : String(value);\n}\n\nfunction* extractLogRecords(payload: unknown): Generator<OtlpLogRecord> {\n if (!payload || typeof payload !== 'object') return;\n const resourceLogs = (payload as { resourceLogs?: unknown[] }).resourceLogs;\n if (!Array.isArray(resourceLogs)) return;\n for (const resourceLog of resourceLogs) {\n if (!resourceLog || typeof resourceLog !== 'object') continue;\n const scopeLogs = (resourceLog as { scopeLogs?: unknown[] }).scopeLogs;\n if (!Array.isArray(scopeLogs)) continue;\n for (const scopeLog of scopeLogs) {\n if (!scopeLog || typeof scopeLog !== 'object') continue;\n const logRecords = (scopeLog as { logRecords?: unknown[] }).logRecords;\n if (!Array.isArray(logRecords)) continue;\n for (const record of logRecords) {\n if (record && typeof record === 'object') {\n yield record as OtlpLogRecord;\n }\n }\n }\n }\n}\n\nexport function parseOtlpLogEvents(payload: unknown): TerminalLogEvent[] {\n const events: TerminalLogEvent[] = [];\n for (const record of extractLogRecords(payload)) {\n const time = toMs(record.timeUnixNano || record.observedTimeUnixNano);\n events.push({\n time,\n level: mapSeverityToLevel(record.severityNumber, record.severityText),\n message: bodyToMessage(record.body),\n traceId: record.traceId ? normalizeHexId(record.traceId, 32) : undefined,\n spanId: record.spanId ? normalizeHexId(record.spanId, 16) : undefined,\n attributes: attrsToRecord(record.attributes),\n });\n }\n return events;\n}\n\n// --- OTLP Metrics parsing (accept and count) ---\n\nexport function countOtlpMetrics(payload: unknown): number {\n if (!payload || typeof payload !== 'object') return 0;\n let count = 0;\n const resourceMetrics = (payload as { resourceMetrics?: unknown[] })\n .resourceMetrics;\n if (!Array.isArray(resourceMetrics)) return 0;\n for (const resourceMetric of resourceMetrics) {\n if (!resourceMetric || typeof resourceMetric !== 'object') continue;\n const scopeMetrics = (resourceMetric as { scopeMetrics?: unknown[] })\n .scopeMetrics;\n if (!Array.isArray(scopeMetrics)) continue;\n for (const scopeMetric of scopeMetrics) {\n if (!scopeMetric || typeof scopeMetric !== 'object') continue;\n const metrics = (scopeMetric as { metrics?: unknown[] }).metrics;\n if (Array.isArray(metrics)) {\n count += metrics.length;\n }\n }\n }\n return count;\n}\n","#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport path from 'node:path';\nimport { renderTerminal } from './index';\nimport { listenLoopbackDualStack } from './listen';\nimport { getTerminalLogStream } from './log-stream';\nimport { CliTerminalSpanStream } from './cli-stream';\nimport {\n countOtlpMetrics,\n parseOtlpEvents,\n parseOtlpLogEvents,\n readJsonBody,\n sendJson,\n} from './otlp-http-json';\n\nimport type { AIConfig, AIProviderType } from './ai/types';\n\ntype CliOptions = {\n port: number;\n host: string;\n title?: string;\n ai: Partial<AIConfig>;\n};\n\nfunction printHelp(): void {\n process.stdout.write(\n String.raw`autotel-terminal - Standalone OTLP receiver with terminal dashboard\n\nUsage: autotel-terminal [options]\n\nOptions:\n -p, --port <port> Port to listen on (default: 4319, env: AUTOTEL_TERMINAL_PORT)\n -H, --host <host> Host to bind to (default: 127.0.0.1, env: AUTOTEL_TERMINAL_HOST)\n -t, --title <title> Dashboard title (env: AUTOTEL_TERMINAL_TITLE)\n -h, --help Show this help message\n -v, --version Show version number\n\nAI Options:\n --ai-provider <provider> AI provider: ollama, openai, openai-compatible (env: AI_PROVIDER)\n --ai-model <model> AI model name (env: AI_MODEL)\n --ai-api-key <key> API key for cloud providers (env: AI_API_KEY)\n --ai-base-url <url> Custom AI endpoint URL (env: AI_BASE_URL)\n\n Auto-detection: if Ollama is running locally, it is used automatically.\n If OPENAI_API_KEY is set, OpenAI is used. Press 'a' in the dashboard to toggle AI.\n\nEndpoints:\n POST /v1/traces Receive OTLP JSON trace data\n POST /v1/logs Receive OTLP JSON log data\n POST /v1/metrics Receive OTLP JSON metric data (accepted and counted)\n GET /healthz Health check\n\nExamples:\n npx autotel-terminal\n npx autotel-terminal --ai-provider ollama --ai-model granite4\n AI_API_KEY=sk-... npx autotel-terminal --ai-provider openai --ai-model gpt-4o\n` + '\\n',\n );\n}\n\nfunction printVersion(): void {\n try {\n const dir = import.meta.dirname ?? new URL('.', import.meta.url).pathname;\n const pkgPath = path.resolve(dir, '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n process.stdout.write(`${pkg.version}\\n`);\n } catch {\n process.stdout.write('unknown\\n');\n }\n}\n\nfunction parseArgs(argv: string[]): CliOptions | null {\n const options: CliOptions = {\n port: Number(process.env.AUTOTEL_TERMINAL_PORT || 4319),\n host: process.env.AUTOTEL_TERMINAL_HOST || '127.0.0.1',\n title: process.env.AUTOTEL_TERMINAL_TITLE,\n ai: {},\n };\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const next = argv[i + 1];\n\n if (arg === '--help' || arg === '-h') {\n printHelp();\n return null;\n }\n if (arg === '--version' || arg === '-v') {\n printVersion();\n return null;\n }\n if ((arg === '--port' || arg === '-p') && next) {\n options.port = Number(next);\n i++;\n continue;\n }\n if ((arg === '--host' || arg === '-H') && next) {\n options.host = next;\n i++;\n continue;\n }\n if ((arg === '--title' || arg === '-t') && next) {\n options.title = next;\n i++;\n continue;\n }\n if (arg === '--ai-provider' && next) {\n options.ai.provider = next as AIProviderType;\n i++;\n continue;\n }\n if (arg === '--ai-model' && next) {\n options.ai.model = next;\n i++;\n continue;\n }\n if (arg === '--ai-api-key' && next) {\n options.ai.apiKey = next;\n i++;\n continue;\n }\n if (arg === '--ai-base-url' && next) {\n options.ai.baseUrl = next;\n i++;\n }\n }\n\n return options;\n}\n\nconst OTLP_ROUTES = new Set(['/v1/traces', '/v1/logs', '/v1/metrics']);\n\nasync function main(): Promise<void> {\n const options = parseArgs(process.argv.slice(2));\n if (!options) {\n process.exit(0);\n }\n\n const spanStream = new CliTerminalSpanStream();\n const logStream = getTerminalLogStream();\n\n renderTerminal(\n {\n title:\n options.title || `Autotel Terminal (${options.host}:${options.port})`,\n ai: options.ai,\n },\n spanStream,\n );\n\n const requestHandler = async (\n req: IncomingMessage,\n res: ServerResponse,\n ): Promise<void> => {\n if (req.method === 'GET' && req.url === '/healthz') {\n sendJson(res, 200, { ok: true });\n return;\n }\n\n if (req.method !== 'POST' || !OTLP_ROUTES.has(req.url ?? '')) {\n sendJson(res, 404, { error: 'Not found' });\n return;\n }\n\n try {\n const payload = await readJsonBody(req);\n\n if (req.url === '/v1/traces') {\n const events = parseOtlpEvents(payload);\n for (const event of events) {\n spanStream.push(event);\n }\n sendJson(res, 200, { acceptedSpans: events.length });\n return;\n }\n\n if (req.url === '/v1/logs') {\n const events = parseOtlpLogEvents(payload);\n for (const event of events) {\n logStream.emit(event);\n }\n sendJson(res, 200, { acceptedLogs: events.length });\n return;\n }\n\n if (req.url === '/v1/metrics') {\n const count = countOtlpMetrics(payload);\n sendJson(res, 200, { acceptedMetrics: count });\n return;\n }\n } catch (error) {\n sendJson(res, 400, {\n error: 'Invalid OTLP JSON payload',\n message: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n const server = createServer(requestHandler);\n\n // Bind both loopback families when host is loopback, so a `localhost` proxy\n // reaches us whether it resolves to 127.0.0.1 or ::1 (the macOS IPv6 footgun).\n const listeners = listenLoopbackDualStack({\n primary: server,\n port: options.port,\n host: options.host,\n attachSecondary: (s) => s.on('request', requestHandler),\n });\n\n const { addresses, warnings } = await listeners.ready;\n process.stdout.write(\n `[autotel-terminal] listening on ${addresses.join(' + ')}\\n`,\n );\n process.stdout.write(\n '[autotel-terminal] endpoints: /v1/traces, /v1/logs, /v1/metrics\\n',\n );\n process.stdout.write(\n '[autotel-terminal] set OTEL_EXPORTER_OTLP_PROTOCOL=http/json and OTEL_EXPORTER_OTLP_ENDPOINT to this host/port\\n',\n );\n for (const w of warnings) {\n process.stdout.write(`[autotel-terminal] ⚠ ${w}\\n`);\n }\n\n const shutdown = () => {\n Promise.all([\n new Promise<void>((r) => server.close(() => r())),\n listeners.closeSibling(),\n ]).then(() => process.exit(0));\n };\n process.on('SIGINT', shutdown);\n process.on('SIGTERM', shutdown);\n}\n\nmain().catch((error) => {\n process.stderr.write(\n `[autotel-terminal] failed to start: ${error instanceof Error ? error.message : String(error)}\\n`,\n );\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAEA,MAAM,WAAW,IAAI,IAAI;CAAC;CAAa;CAAa;AAAK,CAAC;;AAU1D,SAAgB,cAAc,MAAc,MAAsB;CAChE,OAAO,KAAK,SAAS,GAAG,IAAI,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,GAAG;AAC/D;;;;;;;;;;;AAYA,SAAgB,wBAAwB,MAKlB;CACpB,MAAM,EAAE,SAAS,MAAM,MAAM,oBAAoB;CACjD,IAAI;CA0CJ,OAAO;EACL,WAzCgB,SACf,YAAY;GACX,MAAM,YAAsB,CAAC;GAC7B,MAAM,WAAqB,CAAC;GAC5B,MAAM,cAAc,SAAS,cAAc,cAAc;GAEzD,QAAQ,OAAO,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AK;IACjB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;CAEA,MAAM,SAAS,aAAa,cAAc;CAI1C,MAAM,YAAY,wBAAwB;EACxC,SAAS;EACT,MAAM,QAAQ;EACd,MAAM,QAAQ;EACd,kBAAkB,MAAM,EAAE,GAAG,WAAW,cAAc;CACxD,CAAC;CAED,MAAM,EAAE,WAAW,aAAa,MAAM,UAAU;CAChD,QAAQ,OAAO,MACb,mCAAmC,UAAU,KAAK,KAAK,EAAE,GAC3D;CACA,QAAQ,OAAO,MACb,mEACF;CACA,QAAQ,OAAO,MACb,kHACF;CACA,KAAK,MAAM,KAAK,UACd,QAAQ,OAAO,MAAM,wBAAwB,EAAE,GAAG;CAGpD,MAAM,iBAAiB;EACrB,QAAQ,IAAI,CACV,IAAI,SAAe,MAAM,OAAO,YAAY,EAAE,CAAC,CAAC,GAChD,UAAU,aAAa,CACzB,CAAC,CAAC,CAAC,WAAW,QAAQ,KAAK,CAAC,CAAC;CAC/B;CACA,QAAQ,GAAG,UAAU,QAAQ;CAC7B,QAAQ,GAAG,WAAW,QAAQ;AAChC;AAEA,KAAK,CAAC,CAAC,OAAO,UAAU;CACtB,QAAQ,OAAO,MACb,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAChG;CACA,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":["#subscribers"],"sources":["../src/listen.ts","../src/cli-stream.ts","../src/otlp-http-json.ts","../src/cli.ts"],"sourcesContent":["import { createServer, type Server } from 'node:http';\n\nconst LOOPBACK = new Set(['localhost', '127.0.0.1', '::1']);\n\nexport interface LoopbackListeners {\n /** Resolves once the primary and (attempted) sibling listeners are up. */\n ready: Promise<{ addresses: string[]; warnings: string[] }>;\n /** Close the sibling listener (the primary server is owned by the caller). */\n closeSibling: () => Promise<void>;\n}\n\n/** Format host:port, bracketing IPv6 literals (e.g. `[::1]:4319`). */\nexport function formatAddress(host: string, port: number): string {\n return host.includes(':') ? `[${host}]:${port}` : `${host}:${port}`;\n}\n\n/**\n * Listen on `host:port`, and when `host` is a loopback literal, ALSO listen on\n * the sibling loopback family (IPv4 ⟷ IPv6) so a client reaches the collector\n * whether the OS resolves `localhost` to `127.0.0.1` or `::1`.\n *\n * Kills a silent footgun: a dev-server proxy targeting `http://localhost:PORT`\n * on macOS resolves `localhost` to `::1`, but a collector bound only to\n * `127.0.0.1` never receives the request — spans vanish with no error. If the\n * sibling family cannot bind, it is surfaced as a warning, never fatal.\n */\nexport function listenLoopbackDualStack(args: {\n primary: Server;\n port: number;\n host: string;\n attachSecondary: (server: Server) => void;\n}): LoopbackListeners {\n const { primary, port, host, attachSecondary } = args;\n let sibling: Server | undefined;\n\n const ready = new Promise<{ addresses: string[]; warnings: string[] }>(\n (resolve) => {\n const addresses: string[] = [];\n const warnings: string[] = [];\n const primaryHost = host === 'localhost' ? '127.0.0.1' : host;\n\n primary.listen(port, primaryHost, () => {\n const addr = primary.address();\n const resolvedPort =\n addr && typeof addr === 'object' ? addr.port : port;\n addresses.push(formatAddress(primaryHost, resolvedPort));\n\n if (!LOOPBACK.has(host)) {\n resolve({ addresses, warnings });\n return;\n }\n\n const siblingHost = primaryHost === '::1' ? '127.0.0.1' : '::1';\n const s = createServer();\n attachSecondary(s);\n\n const onError = (e: Error) => {\n s.close();\n warnings.push(\n `could not also bind ${formatAddress(siblingHost, resolvedPort)} (${e.message}); ` +\n `clients using the ${siblingHost === '::1' ? 'IPv6' : 'IPv4'} form of \"localhost\" may not connect.`,\n );\n resolve({ addresses, warnings });\n };\n s.once('error', onError);\n s.listen(resolvedPort, siblingHost, () => {\n s.off('error', onError);\n sibling = s;\n addresses.push(formatAddress(siblingHost, resolvedPort));\n resolve({ addresses, warnings });\n });\n });\n },\n );\n\n return {\n ready,\n closeSibling: () =>\n new Promise<void>((res) => {\n if (!sibling) return res();\n sibling.close(() => res());\n }),\n };\n}\n","import type { TerminalSpanEvent, TerminalSpanStream } from './span-stream';\n\ntype Subscriber = (event: TerminalSpanEvent) => void;\n\n/**\n * In-memory stream implementation for standalone CLI ingestion.\n */\nexport class CliTerminalSpanStream implements TerminalSpanStream {\n #subscribers = new Set<Subscriber>();\n\n onSpanEnd(callback: Subscriber): () => void {\n this.#subscribers.add(callback);\n return () => {\n this.#subscribers.delete(callback);\n };\n }\n\n push(event: TerminalSpanEvent): void {\n for (const subscriber of this.#subscribers) {\n subscriber(event);\n }\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { TerminalSpanEvent, SpanEvent, SpanLink } from './span-stream';\nimport type { TerminalLogEvent, LogLevel } from './lib/log-model';\n\nconst MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB\n\ntype OtlpAnyValue = {\n stringValue?: string;\n boolValue?: boolean;\n intValue?: string | number;\n doubleValue?: number;\n bytesValue?: string;\n};\n\ntype OtlpKeyValue = {\n key: string;\n value?: OtlpAnyValue;\n};\n\ntype OtlpSpan = {\n traceId?: string;\n spanId?: string;\n parentSpanId?: string;\n name?: string;\n kind?: number | string;\n startTimeUnixNano?: string;\n endTimeUnixNano?: string;\n attributes?: OtlpKeyValue[];\n status?: {\n code?: number | string;\n };\n events?: {\n timeUnixNano?: string;\n name?: string;\n attributes?: OtlpKeyValue[];\n }[];\n links?: {\n traceId?: string;\n spanId?: string;\n attributes?: OtlpKeyValue[];\n }[];\n};\n\nfunction anyValueToPrimitive(value: OtlpAnyValue | undefined): unknown {\n if (!value) return undefined;\n if (value.stringValue !== undefined) return value.stringValue;\n if (value.boolValue !== undefined) return value.boolValue;\n if (value.intValue !== undefined) {\n const num = Number(value.intValue);\n return Number.isNaN(num) ? value.intValue : num;\n }\n if (value.doubleValue !== undefined) return value.doubleValue;\n if (value.bytesValue !== undefined) return value.bytesValue;\n return undefined;\n}\n\nfunction attrsToRecord(\n attributes: OtlpKeyValue[] | undefined,\n): Record<string, unknown> {\n if (!attributes || attributes.length === 0) return {};\n const out: Record<string, unknown> = {};\n for (const attribute of attributes) {\n out[attribute.key] = anyValueToPrimitive(attribute.value);\n }\n return out;\n}\n\nfunction normalizeHexId(\n id: string | undefined,\n expectedHexLength: number,\n): string {\n if (!id) return ''.padStart(expectedHexLength, '0');\n const trimmed = id.trim();\n if (/^[a-fA-F0-9]+$/.test(trimmed)) {\n return trimmed\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n try {\n const decoded = Buffer.from(trimmed, 'base64').toString('hex');\n if (decoded.length > 0) {\n return decoded\n .toLowerCase()\n .padStart(expectedHexLength, '0')\n .slice(-expectedHexLength);\n }\n } catch {\n // ignore and fall through\n }\n return ''.padStart(expectedHexLength, '0');\n}\n\nfunction toMs(unixNano: string | undefined): number {\n if (!unixNano) return Date.now();\n const parsed = Number(unixNano);\n if (Number.isNaN(parsed)) return Date.now();\n return parsed / 1_000_000;\n}\n\nfunction mapStatus(\n code: number | string | undefined,\n): 'OK' | 'ERROR' | 'UNSET' {\n const normalized = typeof code === 'string' ? code.toUpperCase() : code;\n if (\n normalized === 1 ||\n normalized === 'STATUS_CODE_OK' ||\n normalized === 'OK'\n )\n return 'OK';\n if (\n normalized === 2 ||\n normalized === 'STATUS_CODE_ERROR' ||\n normalized === 'ERROR'\n ) {\n return 'ERROR';\n }\n return 'UNSET';\n}\n\nfunction mapKind(kind: number | string | undefined): string {\n if (typeof kind === 'string') return kind.toUpperCase();\n switch (kind) {\n case 1: {\n return 'INTERNAL';\n }\n case 2: {\n return 'SERVER';\n }\n case 3: {\n return 'CLIENT';\n }\n case 4: {\n return 'PRODUCER';\n }\n case 5: {\n return 'CONSUMER';\n }\n default: {\n return 'INTERNAL';\n }\n }\n}\n\nfunction* extractSpans(\n payload: unknown,\n): Generator<{ span: OtlpSpan; resourceAttrs: Record<string, unknown> }> {\n if (!payload || typeof payload !== 'object') return;\n const resourceSpans = (payload as { resourceSpans?: unknown[] })\n .resourceSpans;\n if (!Array.isArray(resourceSpans)) return;\n for (const resourceSpan of resourceSpans) {\n if (!resourceSpan || typeof resourceSpan !== 'object') continue;\n const resource = (resourceSpan as { resource?: { attributes?: OtlpKeyValue[] } }).resource;\n const resourceAttrs = attrsToRecord(resource?.attributes);\n const scopeSpans = (resourceSpan as { scopeSpans?: unknown[] }).scopeSpans;\n if (!Array.isArray(scopeSpans)) continue;\n for (const scopeSpan of scopeSpans) {\n if (!scopeSpan || typeof scopeSpan !== 'object') continue;\n const spans = (scopeSpan as { spans?: unknown[] }).spans;\n if (!Array.isArray(spans)) continue;\n for (const span of spans) {\n if (span && typeof span === 'object') {\n yield { span: span as OtlpSpan, resourceAttrs };\n }\n }\n }\n }\n}\n\nexport function otlpSpanToTerminalEvent(\n span: OtlpSpan,\n resourceAttrs: Record<string, unknown> = {},\n): TerminalSpanEvent {\n const startTime = toMs(span.startTimeUnixNano);\n const endTime = toMs(span.endTimeUnixNano);\n const spanAttrs = attrsToRecord(span.attributes);\n // Merge resource attributes (e.g. service.name) under span attributes,\n // with span-level attributes taking precedence\n const mergedAttrs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(resourceAttrs)) {\n mergedAttrs[k] = v;\n }\n for (const [k, v] of Object.entries(spanAttrs)) {\n mergedAttrs[k] = v;\n }\n const parsedEvents: SpanEvent[] | undefined = span.events?.length\n ? span.events.map((e) => ({\n name: e.name || '',\n timeMs: toMs(e.timeUnixNano),\n attributes: attrsToRecord(e.attributes),\n }))\n : undefined;\n\n const parsedLinks: SpanLink[] | undefined = span.links?.length\n ? span.links.map((l) => ({\n traceId: normalizeHexId(l.traceId, 32),\n spanId: normalizeHexId(l.spanId, 16),\n attributes: attrsToRecord(l.attributes),\n }))\n : undefined;\n\n return {\n name: span.name || 'unnamed',\n spanId: normalizeHexId(span.spanId, 16),\n traceId: normalizeHexId(span.traceId, 32),\n parentSpanId: span.parentSpanId\n ? normalizeHexId(span.parentSpanId, 16)\n : undefined,\n startTime,\n endTime,\n durationMs: Math.max(0, endTime - startTime),\n status: mapStatus(span.status?.code),\n kind: mapKind(span.kind),\n attributes: mergedAttrs,\n ...(parsedEvents ? { events: parsedEvents } : {}),\n ...(parsedLinks ? { links: parsedLinks } : {}),\n };\n}\n\nexport async function readJsonBody(req: IncomingMessage): Promise<unknown> {\n const chunks: Buffer[] = [];\n let totalLength = 0;\n for await (const chunk of req) {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n totalLength += buf.length;\n if (totalLength > MAX_BODY_BYTES) {\n throw new Error(`Body exceeds ${MAX_BODY_BYTES} byte limit`);\n }\n chunks.push(buf);\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (!raw) return {};\n return JSON.parse(raw);\n}\n\nexport function sendJson(\n res: ServerResponse,\n status: number,\n data: Record<string, unknown>,\n): void {\n res.statusCode = status;\n res.setHeader('content-type', 'application/json');\n res.end(JSON.stringify(data));\n}\n\nexport function parseOtlpEvents(payload: unknown): TerminalSpanEvent[] {\n const events: TerminalSpanEvent[] = [];\n for (const { span, resourceAttrs } of extractSpans(payload)) {\n events.push(otlpSpanToTerminalEvent(span, resourceAttrs));\n }\n return events;\n}\n\n// --- OTLP Log parsing ---\n\ntype OtlpLogRecord = {\n timeUnixNano?: string;\n observedTimeUnixNano?: string;\n severityNumber?: number;\n severityText?: string;\n body?: OtlpAnyValue;\n attributes?: OtlpKeyValue[];\n traceId?: string;\n spanId?: string;\n};\n\nfunction mapSeverityToLevel(\n severityNumber?: number,\n severityText?: string,\n): LogLevel {\n if (severityText) {\n const lower = severityText.toLowerCase();\n if (lower.startsWith('debug') || lower === 'trace') return 'debug';\n if (lower.startsWith('info')) return 'info';\n if (lower.startsWith('warn')) return 'warn';\n if (lower.startsWith('error') || lower.startsWith('fatal')) return 'error';\n }\n if (severityNumber !== undefined) {\n if (severityNumber <= 4) return 'debug';\n if (severityNumber <= 8) return 'debug';\n if (severityNumber <= 12) return 'info';\n if (severityNumber <= 16) return 'warn';\n return 'error';\n }\n return 'info';\n}\n\nfunction bodyToMessage(body: OtlpAnyValue | undefined): string {\n if (!body) return '';\n const value = anyValueToPrimitive(body);\n return value === undefined ? '' : String(value);\n}\n\nfunction* extractLogRecords(payload: unknown): Generator<OtlpLogRecord> {\n if (!payload || typeof payload !== 'object') return;\n const resourceLogs = (payload as { resourceLogs?: unknown[] }).resourceLogs;\n if (!Array.isArray(resourceLogs)) return;\n for (const resourceLog of resourceLogs) {\n if (!resourceLog || typeof resourceLog !== 'object') continue;\n const scopeLogs = (resourceLog as { scopeLogs?: unknown[] }).scopeLogs;\n if (!Array.isArray(scopeLogs)) continue;\n for (const scopeLog of scopeLogs) {\n if (!scopeLog || typeof scopeLog !== 'object') continue;\n const logRecords = (scopeLog as { logRecords?: unknown[] }).logRecords;\n if (!Array.isArray(logRecords)) continue;\n for (const record of logRecords) {\n if (record && typeof record === 'object') {\n yield record as OtlpLogRecord;\n }\n }\n }\n }\n}\n\nexport function parseOtlpLogEvents(payload: unknown): TerminalLogEvent[] {\n const events: TerminalLogEvent[] = [];\n for (const record of extractLogRecords(payload)) {\n const time = toMs(record.timeUnixNano || record.observedTimeUnixNano);\n events.push({\n time,\n level: mapSeverityToLevel(record.severityNumber, record.severityText),\n message: bodyToMessage(record.body),\n traceId: record.traceId ? normalizeHexId(record.traceId, 32) : undefined,\n spanId: record.spanId ? normalizeHexId(record.spanId, 16) : undefined,\n attributes: attrsToRecord(record.attributes),\n });\n }\n return events;\n}\n\n// --- OTLP Metrics parsing (accept and count) ---\n\nexport function countOtlpMetrics(payload: unknown): number {\n if (!payload || typeof payload !== 'object') return 0;\n let count = 0;\n const resourceMetrics = (payload as { resourceMetrics?: unknown[] })\n .resourceMetrics;\n if (!Array.isArray(resourceMetrics)) return 0;\n for (const resourceMetric of resourceMetrics) {\n if (!resourceMetric || typeof resourceMetric !== 'object') continue;\n const scopeMetrics = (resourceMetric as { scopeMetrics?: unknown[] })\n .scopeMetrics;\n if (!Array.isArray(scopeMetrics)) continue;\n for (const scopeMetric of scopeMetrics) {\n if (!scopeMetric || typeof scopeMetric !== 'object') continue;\n const metrics = (scopeMetric as { metrics?: unknown[] }).metrics;\n if (Array.isArray(metrics)) {\n count += metrics.length;\n }\n }\n }\n return count;\n}\n","#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { createServer, type IncomingMessage, type ServerResponse } from 'node:http';\nimport path from 'node:path';\nimport { renderTerminal } from './index';\nimport { listenLoopbackDualStack } from './listen';\nimport { getTerminalLogStream } from './log-stream';\nimport { CliTerminalSpanStream } from './cli-stream';\nimport {\n countOtlpMetrics,\n parseOtlpEvents,\n parseOtlpLogEvents,\n readJsonBody,\n sendJson,\n} from './otlp-http-json';\n\nimport type { AIConfig, AIProviderType } from './ai/types';\n\ntype CliOptions = {\n port: number;\n host: string;\n title?: string;\n ai: Partial<AIConfig>;\n};\n\nfunction printHelp(): void {\n process.stdout.write(\n String.raw`autotel-terminal - Standalone OTLP receiver with terminal dashboard\n\nUsage: autotel-terminal [options]\n\nOptions:\n -p, --port <port> Port to listen on (default: 4319, env: AUTOTEL_TERMINAL_PORT)\n -H, --host <host> Host to bind to (default: 127.0.0.1, env: AUTOTEL_TERMINAL_HOST)\n -t, --title <title> Dashboard title (env: AUTOTEL_TERMINAL_TITLE)\n -h, --help Show this help message\n -v, --version Show version number\n\nAI Options:\n --ai-provider <provider> AI provider: ollama, openai, openai-compatible (env: AI_PROVIDER)\n --ai-model <model> AI model name (env: AI_MODEL)\n --ai-api-key <key> API key for cloud providers (env: AI_API_KEY)\n --ai-base-url <url> Custom AI endpoint URL (env: AI_BASE_URL)\n\n Auto-detection: if Ollama is running locally, it is used automatically.\n If OPENAI_API_KEY is set, OpenAI is used. Press 'a' in the dashboard to toggle AI.\n\nEndpoints:\n POST /v1/traces Receive OTLP JSON trace data\n POST /v1/logs Receive OTLP JSON log data\n POST /v1/metrics Receive OTLP JSON metric data (accepted and counted)\n GET /healthz Health check\n\nExamples:\n npx autotel-terminal\n npx autotel-terminal --ai-provider ollama --ai-model granite4\n AI_API_KEY=sk-... npx autotel-terminal --ai-provider openai --ai-model gpt-4o\n` + '\\n',\n );\n}\n\nfunction printVersion(): void {\n try {\n const dir = import.meta.dirname ?? new URL('.', import.meta.url).pathname;\n const pkgPath = path.resolve(dir, '..', 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n process.stdout.write(`${pkg.version}\\n`);\n } catch {\n process.stdout.write('unknown\\n');\n }\n}\n\nfunction parseArgs(argv: string[]): CliOptions | null {\n const options: CliOptions = {\n port: Number(process.env.AUTOTEL_TERMINAL_PORT || 4319),\n host: process.env.AUTOTEL_TERMINAL_HOST || '127.0.0.1',\n title: process.env.AUTOTEL_TERMINAL_TITLE,\n ai: {},\n };\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const next = argv[i + 1];\n\n if (arg === '--help' || arg === '-h') {\n printHelp();\n return null;\n }\n if (arg === '--version' || arg === '-v') {\n printVersion();\n return null;\n }\n if ((arg === '--port' || arg === '-p') && next) {\n options.port = Number(next);\n i++;\n continue;\n }\n if ((arg === '--host' || arg === '-H') && next) {\n options.host = next;\n i++;\n continue;\n }\n if ((arg === '--title' || arg === '-t') && next) {\n options.title = next;\n i++;\n continue;\n }\n if (arg === '--ai-provider' && next) {\n options.ai.provider = next as AIProviderType;\n i++;\n continue;\n }\n if (arg === '--ai-model' && next) {\n options.ai.model = next;\n i++;\n continue;\n }\n if (arg === '--ai-api-key' && next) {\n options.ai.apiKey = next;\n i++;\n continue;\n }\n if (arg === '--ai-base-url' && next) {\n options.ai.baseUrl = next;\n i++;\n }\n }\n\n return options;\n}\n\nconst OTLP_ROUTES = new Set(['/v1/traces', '/v1/logs', '/v1/metrics']);\n\nasync function main(): Promise<void> {\n const options = parseArgs(process.argv.slice(2));\n if (!options) {\n process.exit(0);\n }\n\n const spanStream = new CliTerminalSpanStream();\n const logStream = getTerminalLogStream();\n\n renderTerminal(\n {\n title:\n options.title || `Autotel Terminal (${options.host}:${options.port})`,\n ai: options.ai,\n },\n spanStream,\n );\n\n const requestHandler = async (\n req: IncomingMessage,\n res: ServerResponse,\n ): Promise<void> => {\n if (req.method === 'GET' && req.url === '/healthz') {\n sendJson(res, 200, { ok: true });\n return;\n }\n\n if (req.method !== 'POST' || !OTLP_ROUTES.has(req.url ?? '')) {\n sendJson(res, 404, { error: 'Not found' });\n return;\n }\n\n try {\n const payload = await readJsonBody(req);\n\n if (req.url === '/v1/traces') {\n const events = parseOtlpEvents(payload);\n for (const event of events) {\n spanStream.push(event);\n }\n sendJson(res, 200, { acceptedSpans: events.length });\n return;\n }\n\n if (req.url === '/v1/logs') {\n const events = parseOtlpLogEvents(payload);\n for (const event of events) {\n logStream.emit(event);\n }\n sendJson(res, 200, { acceptedLogs: events.length });\n return;\n }\n\n if (req.url === '/v1/metrics') {\n const count = countOtlpMetrics(payload);\n sendJson(res, 200, { acceptedMetrics: count });\n return;\n }\n } catch (error) {\n sendJson(res, 400, {\n error: 'Invalid OTLP JSON payload',\n message: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n const server = createServer(requestHandler);\n\n // Bind both loopback families when host is loopback, so a `localhost` proxy\n // reaches us whether it resolves to 127.0.0.1 or ::1 (the macOS IPv6 footgun).\n const listeners = listenLoopbackDualStack({\n primary: server,\n port: options.port,\n host: options.host,\n attachSecondary: (s) => s.on('request', requestHandler),\n });\n\n const { addresses, warnings } = await listeners.ready;\n process.stdout.write(\n `[autotel-terminal] listening on ${addresses.join(' + ')}\\n`,\n );\n process.stdout.write(\n '[autotel-terminal] endpoints: /v1/traces, /v1/logs, /v1/metrics\\n',\n );\n process.stdout.write(\n '[autotel-terminal] set OTEL_EXPORTER_OTLP_PROTOCOL=http/json and OTEL_EXPORTER_OTLP_ENDPOINT to this host/port\\n',\n );\n for (const w of warnings) {\n process.stdout.write(`[autotel-terminal] ⚠ ${w}\\n`);\n }\n\n const shutdown = () => {\n Promise.all([\n new Promise<void>((r) => server.close(() => r())),\n listeners.closeSibling(),\n ]).then(() => process.exit(0));\n };\n process.on('SIGINT', shutdown);\n process.on('SIGTERM', shutdown);\n}\n\nmain().catch((error) => {\n process.stderr.write(\n `[autotel-terminal] failed to start: ${error instanceof Error ? error.message : String(error)}\\n`,\n );\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAEA,MAAM,2BAAW,IAAI,IAAI;CAAC;CAAa;CAAa;AAAK,CAAC;;AAU1D,SAAgB,cAAc,MAAc,MAAsB;CAChE,OAAO,KAAK,SAAS,GAAG,IAAI,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,GAAG;AAC/D;;;;;;;;;;;AAYA,SAAgB,wBAAwB,MAKlB;CACpB,MAAM,EAAE,SAAS,MAAM,MAAM,oBAAoB;CACjD,IAAI;CA0CJ,OAAO;EACL,WAzCgB,SACf,YAAY;GACX,MAAM,YAAsB,CAAC;GAC7B,MAAM,WAAqB,CAAC;GAC5B,MAAM,cAAc,SAAS,cAAc,cAAc;GAEzD,QAAQ,OAAO,MAAM,mBAAmB;IACtC,MAAM,OAAO,QAAQ,QAAQ;IAC7B,MAAM,eACJ,QAAQ,OAAO,SAAS,WAAW,KAAK,OAAO;IACjD,UAAU,KAAK,cAAc,aAAa,YAAY,CAAC;IAEvD,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG;KACvB,QAAQ;MAAE;MAAW;KAAS,CAAC;KAC/B;IACF;IAEA,MAAM,cAAc,gBAAgB,QAAQ,cAAc;IAC1D,MAAM,IAAI,aAAa;IACvB,gBAAgB,CAAC;IAEjB,MAAM,WAAW,MAAa;KAC5B,EAAE,MAAM;KACR,SAAS,KACP,uBAAuB,cAAc,aAAa,YAAY,EAAE,IAAI,EAAE,QAAQ,uBACvD,gBAAgB,QAAQ,SAAS,OAAO,sCACjE;KACA,QAAQ;MAAE;MAAW;KAAS,CAAC;IACjC;IACA,EAAE,KAAK,SAAS,OAAO;IACvB,EAAE,OAAO,cAAc,mBAAmB;KACxC,EAAE,IAAI,SAAS,OAAO;KACtB,UAAU;K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AQ,KAAK,CAAC,CAAC;CAC/B;CACA,QAAQ,GAAG,UAAU,QAAQ;CAC7B,QAAQ,GAAG,WAAW,QAAQ;AAChC;AAEA,KAAK,CAAC,CAAC,OAAO,UAAU;CACtB,QAAQ,OAAO,MACb,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAChG;CACA,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-adtyx8HT.cjs');
|
|
3
3
|
let autotel_exporters = require("autotel/exporters");
|
|
4
4
|
let autotel = require("autotel");
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-
|
|
1
|
+
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-BbKL64Rh.js";
|
|
2
2
|
|
|
3
3
|
export { PrettyConsoleExporter, SpanKind, SpanStatusCode, StreamingSpanProcessor, createTerminalSpanStream, getTerminalLogStream, renderTerminal };
|