@senpi/runtime 1.1.0-dev.runtime-phase-2.20260609123448 → 1.1.0-dev.runtime-phase-2.20260609132603

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/actions/close-position/close-position.action.d.ts +16 -0
  2. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  3. package/dist/actions/close-position/close-position.action.js +299 -38
  4. package/dist/actions/close-position/close-position.action.js.map +1 -1
  5. package/dist/actions/decision-engine.d.ts +2 -0
  6. package/dist/actions/decision-engine.d.ts.map +1 -1
  7. package/dist/actions/decision-engine.js.map +1 -1
  8. package/dist/actions/llm-decision/factory.d.ts +3 -0
  9. package/dist/actions/llm-decision/factory.d.ts.map +1 -1
  10. package/dist/actions/llm-decision/factory.js +1 -0
  11. package/dist/actions/llm-decision/factory.js.map +1 -1
  12. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +13 -0
  13. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  14. package/dist/actions/llm-decision/openclaw-llm-decision.js +195 -68
  15. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  16. package/dist/actions/open-position/open-position.action.d.ts +12 -0
  17. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  18. package/dist/actions/open-position/open-position.action.js +356 -109
  19. package/dist/actions/open-position/open-position.action.js.map +1 -1
  20. package/dist/actions/otel-helpers.d.ts +65 -0
  21. package/dist/actions/otel-helpers.d.ts.map +1 -0
  22. package/dist/actions/otel-helpers.js +122 -0
  23. package/dist/actions/otel-helpers.js.map +1 -0
  24. package/dist/actions/position-tracker/position-tracker.action.d.ts +6 -0
  25. package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
  26. package/dist/actions/position-tracker/position-tracker.action.js +48 -0
  27. package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
  28. package/dist/otel/context.d.ts +24 -0
  29. package/dist/otel/context.d.ts.map +1 -0
  30. package/dist/otel/context.js +29 -0
  31. package/dist/otel/context.js.map +1 -0
  32. package/dist/otel/emitter.d.ts +73 -0
  33. package/dist/otel/emitter.d.ts.map +1 -0
  34. package/dist/otel/emitter.js +248 -0
  35. package/dist/otel/emitter.js.map +1 -0
  36. package/dist/otel/encode.d.ts +48 -0
  37. package/dist/otel/encode.d.ts.map +1 -0
  38. package/dist/otel/encode.js +100 -0
  39. package/dist/otel/encode.js.map +1 -0
  40. package/dist/otel/index.d.ts +13 -0
  41. package/dist/otel/index.d.ts.map +1 -0
  42. package/dist/otel/index.js +10 -0
  43. package/dist/otel/index.js.map +1 -0
  44. package/dist/otel/transport.d.ts +57 -0
  45. package/dist/otel/transport.d.ts.map +1 -0
  46. package/dist/otel/transport.js +208 -0
  47. package/dist/otel/transport.js.map +1 -0
  48. package/dist/otel/types.d.ts +62 -0
  49. package/dist/otel/types.d.ts.map +1 -0
  50. package/dist/otel/types.js +2 -0
  51. package/dist/otel/types.js.map +1 -0
  52. package/dist/runtime/create-actions.d.ts.map +1 -1
  53. package/dist/runtime/create-actions.js +2 -0
  54. package/dist/runtime/create-actions.js.map +1 -1
  55. package/dist/runtime/create-runtime-context.d.ts +2 -0
  56. package/dist/runtime/create-runtime-context.d.ts.map +1 -1
  57. package/dist/runtime/create-runtime-context.js +1 -0
  58. package/dist/runtime/create-runtime-context.js.map +1 -1
  59. package/dist/runtime/create-scanner-module.d.ts +1 -1
  60. package/dist/runtime/create-scanner-module.d.ts.map +1 -1
  61. package/dist/runtime/create-scanner-module.js +2 -1
  62. package/dist/runtime/create-scanner-module.js.map +1 -1
  63. package/dist/runtime/risk-guard.d.ts +10 -0
  64. package/dist/runtime/risk-guard.d.ts.map +1 -1
  65. package/dist/runtime/risk-guard.js +6 -12
  66. package/dist/runtime/risk-guard.js.map +1 -1
  67. package/dist/runtime/runtime-schema.d.ts +24 -0
  68. package/dist/runtime/runtime-schema.d.ts.map +1 -1
  69. package/dist/runtime/runtime-schema.js +1 -0
  70. package/dist/runtime/runtime-schema.js.map +1 -1
  71. package/dist/runtime/runtime.d.ts +5 -0
  72. package/dist/runtime/runtime.d.ts.map +1 -1
  73. package/dist/runtime/runtime.js +140 -4
  74. package/dist/runtime/runtime.js.map +1 -1
  75. package/dist/runtime/strategy-lifecycle.d.ts +45 -0
  76. package/dist/runtime/strategy-lifecycle.d.ts.map +1 -0
  77. package/dist/runtime/strategy-lifecycle.js +117 -0
  78. package/dist/runtime/strategy-lifecycle.js.map +1 -0
  79. package/dist/scanners/engine/data-providers.d.ts +2 -0
  80. package/dist/scanners/engine/data-providers.d.ts.map +1 -1
  81. package/dist/scanners/engine/data-providers.js.map +1 -1
  82. package/dist/scanners/engine/engine.d.ts.map +1 -1
  83. package/dist/scanners/engine/engine.js +68 -9
  84. package/dist/scanners/engine/engine.js.map +1 -1
  85. package/dist/scanners/runtime-module.d.ts +2 -0
  86. package/dist/scanners/runtime-module.d.ts.map +1 -1
  87. package/dist/scanners/runtime-module.js +1 -0
  88. package/dist/scanners/runtime-module.js.map +1 -1
  89. package/dist/senpi/client.d.ts +2 -2
  90. package/dist/senpi/client.d.ts.map +1 -1
  91. package/dist/senpi/client.js +120 -20
  92. package/dist/senpi/client.js.map +1 -1
  93. package/dist/senpi/types.d.ts +68 -1
  94. package/dist/senpi/types.d.ts.map +1 -1
  95. package/dist/strategy/strategy-state.d.ts +1 -1
  96. package/dist/strategy/strategy-state.d.ts.map +1 -1
  97. package/dist/tracking/spans/plugin-span-tracker.d.ts.map +1 -1
  98. package/dist/tracking/spans/plugin-span-tracker.js +4 -24
  99. package/dist/tracking/spans/plugin-span-tracker.js.map +1 -1
  100. package/dist/tracking/spans/redact-pii.d.ts +10 -0
  101. package/dist/tracking/spans/redact-pii.d.ts.map +1 -1
  102. package/dist/tracking/spans/redact-pii.js +80 -2
  103. package/dist/tracking/spans/redact-pii.js.map +1 -1
  104. package/dist/types/hooks.d.ts +1 -0
  105. package/dist/types/hooks.d.ts.map +1 -1
  106. package/dist/types/hooks.js +1 -0
  107. package/dist/types/hooks.js.map +1 -1
  108. package/dist/types/runtime.d.ts +3 -0
  109. package/dist/types/runtime.d.ts.map +1 -1
  110. package/dist/types/strategy.d.ts +2 -2
  111. package/dist/types/strategy.d.ts.map +1 -1
  112. package/package.json +1 -1
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Per-Runtime OTEL emitter. Constructed once with the identity envelope baked
3
+ * in; stamps `position.id` from the OTEL ALS frame onto every span/log at emit
4
+ * time. Independent of the deprecating `src/tracking/` layer.
5
+ *
6
+ * Base host is shared with the legacy tracking layer via SENPI_TRACKING_URL
7
+ * (defaulting to the prod tracking host); the OTEL route paths are appended.
8
+ * When SENPI_OTEL_API_KEY is unset the emitter is `disabled` and all methods
9
+ * are cheap no-ops (the ingest rejects unauthenticated batches).
10
+ */
11
+ import os from "node:os";
12
+ import { createLogger } from "../utils/logger.js";
13
+ import { ensureDefaultPiiRedactor } from "../tracking/spans/redact-pii.js";
14
+ import { VERSION } from "../version.js";
15
+ import { getCurrentSpan, getPositionId } from "./context.js";
16
+ import { newSpanId, newTraceId, nowNs, nowNsBigInt, toStringMap, toStringValue } from "./encode.js";
17
+ import { OtelHttpTransport } from "./transport.js";
18
+ const logger = createLogger("[senpi-core][otel-emitter]");
19
+ // Same base host as the legacy tracking layer (events/spans). Local constant so
20
+ // the OTEL path stays self-contained while still honoring SENPI_TRACKING_URL.
21
+ const DEFAULT_TRACKING_BASE_URL = "https://agent-telemetry.prod.senpi.ai";
22
+ /** Severity → OTEL semconv 1-24 number. Lowercase is the canonical wire form. */
23
+ const SEVERITY_NUMBER = {
24
+ trace: 1,
25
+ debug: 5,
26
+ info: 9,
27
+ warn: 13,
28
+ error: 17,
29
+ fatal: 21,
30
+ };
31
+ export class OtelEmitter {
32
+ resource;
33
+ serviceName;
34
+ spans;
35
+ logs;
36
+ disabled;
37
+ constructor(options) {
38
+ const endpoint = options.endpoint ??
39
+ process.env.SENPI_TRACKING_URL ??
40
+ DEFAULT_TRACKING_BASE_URL;
41
+ // Intentionally NO fallback to SENPI_API_KEY. The master Senpi API key
42
+ // grants broad access; posting it as a Bearer would expose it beyond its
43
+ // intended scope. Require SENPI_OTEL_API_KEY explicitly — without it the
44
+ // emitter disables rather than posting unauth (the ingest rejects
45
+ // unauthenticated batches with 401).
46
+ const apiKey = options.apiKey ?? process.env.SENPI_OTEL_API_KEY;
47
+ // Resource map produced once at construction (no per-call rebuild).
48
+ const id = options.identity;
49
+ const resource = {
50
+ "service.name": id.serviceName,
51
+ "service.version": VERSION,
52
+ "host.name": os.hostname(),
53
+ "runtime.boot_id": id.runtimeBootId,
54
+ "runtime.version": id.runtimeVersion ?? VERSION,
55
+ };
56
+ // `user.id` is intentionally NOT stamped here. The ingest service
57
+ // overwrites it from the verified bearer token (`stampUser` in
58
+ // agent_telemetry's otel route), so a producer-side stamp is bytes on
59
+ // the wire and a small attack-surface: a compromised producer credential
60
+ // could otherwise lie about identity for empty-`strategy.address` rows
61
+ // that bypass the ownership gate. Server-stamp is the authoritative path.
62
+ if (id.strategyAddress)
63
+ resource["strategy.address"] = id.strategyAddress;
64
+ if (id.recipeName)
65
+ resource["recipe.name"] = id.recipeName;
66
+ if (id.recipeVersion)
67
+ resource["recipe.version"] = id.recipeVersion;
68
+ this.resource = resource;
69
+ this.serviceName = id.serviceName;
70
+ this.disabled = options.disabled === true || !apiKey;
71
+ if (this.disabled) {
72
+ if (!apiKey && options.disabled !== true) {
73
+ logger.info("OTEL emitter disabled: SENPI_OTEL_API_KEY unset");
74
+ }
75
+ this.spans = null;
76
+ this.logs = null;
77
+ return;
78
+ }
79
+ this.spans = new OtelHttpTransport({
80
+ url: joinUrl(endpoint, "/api/v1/tracking/traces"),
81
+ apiKey,
82
+ kind: "spans",
83
+ });
84
+ this.logs = new OtelHttpTransport({
85
+ url: joinUrl(endpoint, "/api/v1/tracking/logs"),
86
+ apiKey,
87
+ kind: "logs",
88
+ });
89
+ // Kick off PII redactor init on the V2 path too (the legacy span tracker
90
+ // also calls this; the helper is idempotent). Without this, an OTel-only
91
+ // deployment with `SENPI_API_KEY` unset would never construct the legacy
92
+ // span tracker and emit un-redacted.
93
+ void ensureDefaultPiiRedactor();
94
+ }
95
+ startSpan(name, opts = {}) {
96
+ // B1 — when no explicit parent, fall back to ALS-`currentSpan`.
97
+ const parent = opts.parent ?? getCurrentSpan();
98
+ const traceId = parent?.traceId ?? newTraceId();
99
+ const spanId = newSpanId();
100
+ const parentSpanId = parent?.spanId ?? "";
101
+ const startTimeNs = nowNsBigInt();
102
+ const kind = opts.kind ?? "Internal";
103
+ const attrMap = {};
104
+ if (opts.attrs) {
105
+ for (const [k, v] of Object.entries(opts.attrs)) {
106
+ // Skip undefined; emit empty-string for null per CH convention.
107
+ if (v === undefined)
108
+ continue;
109
+ attrMap[k] = toStringValue(v);
110
+ }
111
+ }
112
+ const events = [];
113
+ let ended = false;
114
+ let exceptionRecorded = false;
115
+ const emit = (row) => {
116
+ this.spans?.emit(row);
117
+ };
118
+ const cachedResource = this.resource;
119
+ const cachedServiceName = this.serviceName;
120
+ const handle = {
121
+ traceId,
122
+ spanId,
123
+ name,
124
+ setAttr(key, value) {
125
+ // C6 — only skip `undefined`; null, false, 0, '' are all valid values.
126
+ if (value === undefined)
127
+ return;
128
+ attrMap[key] = toStringValue(value);
129
+ },
130
+ setAttrs(record) {
131
+ for (const [k, v] of Object.entries(record)) {
132
+ if (v === undefined)
133
+ continue;
134
+ attrMap[k] = toStringValue(v);
135
+ }
136
+ },
137
+ addEvent(eventName, eventAttrs) {
138
+ events.push({
139
+ Timestamp: nowNs(),
140
+ Name: eventName,
141
+ Attributes: eventAttrs ? toStringMap(eventAttrs) : {},
142
+ });
143
+ },
144
+ recordException(err) {
145
+ const e = err;
146
+ events.push({
147
+ Timestamp: nowNs(),
148
+ Name: "exception",
149
+ Attributes: {
150
+ "exception.type": e?.name ?? "Error",
151
+ "exception.message": e?.message ?? String(err),
152
+ "exception.stacktrace": e?.stack ?? "",
153
+ },
154
+ });
155
+ exceptionRecorded = true;
156
+ },
157
+ end(endOpts) {
158
+ if (ended)
159
+ return;
160
+ ended = true;
161
+ const positionId = getPositionId();
162
+ if (positionId && attrMap["position.id"] === undefined) {
163
+ attrMap["position.id"] = positionId;
164
+ }
165
+ // C2 — default StatusCode: explicit > exception-implied 'Error' > 'Ok'.
166
+ const statusCode = endOpts?.statusCode ?? (exceptionRecorded ? "Error" : "Ok");
167
+ const endTimeNs = nowNsBigInt();
168
+ const startTimestamp = startTimeNs.toString();
169
+ const duration = (endTimeNs - startTimeNs).toString();
170
+ const row = {
171
+ Timestamp: startTimestamp,
172
+ TraceId: traceId,
173
+ SpanId: spanId,
174
+ ParentSpanId: parentSpanId,
175
+ SpanName: name,
176
+ SpanKind: kind,
177
+ Duration: duration,
178
+ ServiceName: cachedServiceName,
179
+ StatusCode: statusCode,
180
+ StatusMessage: endOpts?.message ?? "",
181
+ SpanAttributes: attrMap,
182
+ ResourceAttributes: cachedResource,
183
+ Events: events,
184
+ ScopeName: "",
185
+ ScopeVersion: "",
186
+ TraceFlags: 0,
187
+ TraceState: "",
188
+ };
189
+ emit(row);
190
+ },
191
+ };
192
+ return handle;
193
+ }
194
+ emitLog(opts) {
195
+ if (!this.logs)
196
+ return;
197
+ const severity = opts.severity ?? "info";
198
+ const parent = opts.parent ?? getCurrentSpan();
199
+ const baseAttrs = {
200
+ "event.name": opts.eventName,
201
+ ...(opts.attrs ?? {}),
202
+ };
203
+ const positionId = getPositionId();
204
+ if (positionId && baseAttrs["position.id"] === undefined) {
205
+ baseAttrs["position.id"] = positionId;
206
+ }
207
+ let body = "";
208
+ if (opts.body !== undefined && opts.body !== null) {
209
+ body = typeof opts.body === "string" ? opts.body : toStringValue(opts.body);
210
+ }
211
+ const row = {
212
+ Timestamp: nowNs(),
213
+ TraceId: parent?.traceId ?? "",
214
+ SpanId: parent?.spanId ?? "",
215
+ ServiceName: this.serviceName,
216
+ SeverityText: severity,
217
+ SeverityNumber: SEVERITY_NUMBER[severity],
218
+ Body: body,
219
+ LogAttributes: toStringMap(baseAttrs),
220
+ ResourceAttributes: this.resource,
221
+ EventName: opts.eventName,
222
+ };
223
+ this.logs.emit(row);
224
+ }
225
+ /** Drain both transports' buffers and await in-flight POSTs. */
226
+ async shutdown() {
227
+ await Promise.allSettled([
228
+ this.spans?.shutdown() ?? Promise.resolve(),
229
+ this.logs?.shutdown() ?? Promise.resolve(),
230
+ ]);
231
+ }
232
+ /**
233
+ * No-op emitter satisfying the `OtelEmitter` shape. Useful as a fallback in
234
+ * paths (e.g. tests or callers that build a runtime context without a real
235
+ * runtime) where stamping `{ disabled: true }` plus an identity envelope is
236
+ * boilerplate.
237
+ */
238
+ static disabled() {
239
+ return new OtelEmitter({
240
+ identity: { serviceName: "senpi-trading-runtime", runtimeBootId: "disabled" },
241
+ disabled: true,
242
+ });
243
+ }
244
+ }
245
+ function joinUrl(base, path) {
246
+ return base.replace(/\/+$/, "") + path;
247
+ }
248
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/otel/emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAUnD,MAAM,MAAM,GAAG,YAAY,CAAC,4BAA4B,CAAC,CAAC;AAE1D,gFAAgF;AAChF,8EAA8E;AAC9E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C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;AACzC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * ID generation, ns timestamps, and string-attribute encoding.
3
+ *
4
+ * Wire-format requirements (see remediation plan "Wire format"):
5
+ * - traceId = 32-hex lowercase from 16 random bytes
6
+ * - spanId = 16-hex lowercase from 8 random bytes
7
+ * - timestamps = epoch nanoseconds as UInt64-string
8
+ * - attribute values = flat strings (`Map(LC(String), String)` in HyperDX)
9
+ *
10
+ * Callers pre-flatten nested objects via the separate `flatten()` helper —
11
+ * `toStringValue` JSON-stringifies arrays and plain objects as a fallback.
12
+ */
13
+ export declare function newTraceId(): string;
14
+ export declare function newSpanId(): string;
15
+ /**
16
+ * High-precision ns timestamp combining `performance.timeOrigin` (epoch ms
17
+ * resolved at process start) with `performance.now()` (sub-ms monotonic).
18
+ * Returned as a UInt64-string for direct insertion into DateTime64(9) columns.
19
+ *
20
+ * Arithmetic note: a naive `(timeOrigin + now()) * 1e6` overflows Number
21
+ * precision (timeOrigin*1e6 ≈ 1.7e18, well past 2^53 ≈ 9e15) and would zero
22
+ * the sub-µs bits. We keep the large epoch component in BigInt and only
23
+ * multiply the small `performance.now()` value inside a Number — that
24
+ * preserves `performance.now()`'s native µs precision end-to-end.
25
+ */
26
+ export declare function nowNs(): string;
27
+ /** BigInt variant for callers that need to subtract (span duration). */
28
+ export declare function nowNsBigInt(): bigint;
29
+ /**
30
+ * Stringify any JS value into the canonical CH-row attribute encoding.
31
+ * Strings pass through; primitives map to their natural string form;
32
+ * objects/arrays are JSON-stringified. Returns `''` for null/undefined so
33
+ * callers can decide whether to emit the entry or skip it.
34
+ */
35
+ export declare function toStringValue(v: unknown): string;
36
+ /**
37
+ * Convert a record of mixed values to a flat string-only attribute map.
38
+ * Entries whose value is `null` or `undefined` are skipped — CH schema
39
+ * defaults handle absence (per CH convention, empty-string > null > undefined).
40
+ */
41
+ export declare function toStringMap(record: Record<string, unknown> | undefined): Record<string, string>;
42
+ /**
43
+ * Flatten a `Record<string, primitive>` into dot-namespaced string attrs.
44
+ * Primitives map to their natural string form; arrays and nested objects
45
+ * are JSON-stringified via `toStringValue` so nothing gets silently dropped.
46
+ */
47
+ export declare function flatten(prefix: string, obj: Record<string, unknown> | undefined): Record<string, string>;
48
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/otel/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED,wEAAwE;AACxE,wBAAgB,WAAW,IAAI,MAAM,CAOpC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAWhD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ/F;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxB"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * ID generation, ns timestamps, and string-attribute encoding.
3
+ *
4
+ * Wire-format requirements (see remediation plan "Wire format"):
5
+ * - traceId = 32-hex lowercase from 16 random bytes
6
+ * - spanId = 16-hex lowercase from 8 random bytes
7
+ * - timestamps = epoch nanoseconds as UInt64-string
8
+ * - attribute values = flat strings (`Map(LC(String), String)` in HyperDX)
9
+ *
10
+ * Callers pre-flatten nested objects via the separate `flatten()` helper —
11
+ * `toStringValue` JSON-stringifies arrays and plain objects as a fallback.
12
+ */
13
+ import { randomBytes } from "node:crypto";
14
+ import { performance } from "node:perf_hooks";
15
+ export function newTraceId() {
16
+ return randomBytes(16).toString("hex");
17
+ }
18
+ export function newSpanId() {
19
+ return randomBytes(8).toString("hex");
20
+ }
21
+ /**
22
+ * High-precision ns timestamp combining `performance.timeOrigin` (epoch ms
23
+ * resolved at process start) with `performance.now()` (sub-ms monotonic).
24
+ * Returned as a UInt64-string for direct insertion into DateTime64(9) columns.
25
+ *
26
+ * Arithmetic note: a naive `(timeOrigin + now()) * 1e6` overflows Number
27
+ * precision (timeOrigin*1e6 ≈ 1.7e18, well past 2^53 ≈ 9e15) and would zero
28
+ * the sub-µs bits. We keep the large epoch component in BigInt and only
29
+ * multiply the small `performance.now()` value inside a Number — that
30
+ * preserves `performance.now()`'s native µs precision end-to-end.
31
+ */
32
+ export function nowNs() {
33
+ return nowNsBigInt().toString();
34
+ }
35
+ /** BigInt variant for callers that need to subtract (span duration). */
36
+ export function nowNsBigInt() {
37
+ const originMs = performance.timeOrigin;
38
+ const originWholeMs = Math.floor(originMs);
39
+ const originFracNs = Math.round((originMs - originWholeMs) * 1_000_000);
40
+ const originNs = BigInt(originWholeMs) * 1000000n + BigInt(originFracNs);
41
+ const offsetNs = BigInt(Math.round(performance.now() * 1_000_000));
42
+ return originNs + offsetNs;
43
+ }
44
+ /**
45
+ * Stringify any JS value into the canonical CH-row attribute encoding.
46
+ * Strings pass through; primitives map to their natural string form;
47
+ * objects/arrays are JSON-stringified. Returns `''` for null/undefined so
48
+ * callers can decide whether to emit the entry or skip it.
49
+ */
50
+ export function toStringValue(v) {
51
+ if (v === null || v === undefined)
52
+ return "";
53
+ if (typeof v === "string")
54
+ return v;
55
+ if (typeof v === "boolean")
56
+ return v ? "true" : "false";
57
+ if (typeof v === "bigint")
58
+ return v.toString();
59
+ if (typeof v === "number")
60
+ return String(v);
61
+ try {
62
+ return JSON.stringify(v);
63
+ }
64
+ catch {
65
+ return String(v);
66
+ }
67
+ }
68
+ /**
69
+ * Convert a record of mixed values to a flat string-only attribute map.
70
+ * Entries whose value is `null` or `undefined` are skipped — CH schema
71
+ * defaults handle absence (per CH convention, empty-string > null > undefined).
72
+ */
73
+ export function toStringMap(record) {
74
+ if (!record)
75
+ return {};
76
+ const out = {};
77
+ for (const [key, v] of Object.entries(record)) {
78
+ if (v === null || v === undefined)
79
+ continue;
80
+ out[key] = toStringValue(v);
81
+ }
82
+ return out;
83
+ }
84
+ /**
85
+ * Flatten a `Record<string, primitive>` into dot-namespaced string attrs.
86
+ * Primitives map to their natural string form; arrays and nested objects
87
+ * are JSON-stringified via `toStringValue` so nothing gets silently dropped.
88
+ */
89
+ export function flatten(prefix, obj) {
90
+ if (!obj)
91
+ return {};
92
+ const out = {};
93
+ for (const [k, v] of Object.entries(obj)) {
94
+ if (v === null || v === undefined)
95
+ continue;
96
+ out[`${prefix}.${k}`] = toStringValue(v);
97
+ }
98
+ return out;
99
+ }
100
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/otel/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,UAAU,UAAU;IACxB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK;IACnB,OAAO,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;AAClC,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,WAAW;I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AA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC5C,GAAG,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACrB,MAAc,EACd,GAAwC;IAExC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC5C,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Public surface of the OTEL V2 recording module.
3
+ *
4
+ * Exports are limited to symbols consumed outside `src/otel/`. Transport,
5
+ * encode helpers, and registry stubs are intentionally not re-exported.
6
+ */
7
+ export type { LogRow, OtelSeverity, OtelSpanKind, OtelStatusCode, SpanEvent, SpanRow, } from "./types.js";
8
+ export { getCurrentSpan, getPositionId, otelContext, setCurrentSpan, setPositionId, } from "./context.js";
9
+ export type { OtelContext } from "./context.js";
10
+ export { flatten } from "./encode.js";
11
+ export { OtelEmitter } from "./emitter.js";
12
+ export type { LogEmitOpts, OtelEmitterOptions, OtelIdentity, OtelSpanHandle, SpanEndOpts, SpanStartOpts, } from "./emitter.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/otel/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,SAAS,EACT,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Public surface of the OTEL V2 recording module.
3
+ *
4
+ * Exports are limited to symbols consumed outside `src/otel/`. Transport,
5
+ * encode helpers, and registry stubs are intentionally not re-exported.
6
+ */
7
+ export { getCurrentSpan, getPositionId, otelContext, setCurrentSpan, setPositionId, } from "./context.js";
8
+ export { flatten } from "./encode.js";
9
+ export { OtelEmitter } from "./emitter.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/otel/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Fire-and-forget HTTP transport with micro-batching.
3
+ *
4
+ * Records are buffered in memory and flushed to the consumer when either:
5
+ * - the buffer reaches `maxBatch` records, OR
6
+ * - `maxAgeMs` elapse since the first record landed (timer-driven).
7
+ *
8
+ * Each flush issues one POST containing `{ spans: [...] }` / `{ logs: [...] }`.
9
+ * The consumer already accepts an array; single-record posts (the prior
10
+ * behavior) were just N=1 batches. Trade-off: per-record latency up to
11
+ * `maxAgeMs` (default 250ms); SIGKILL loses the in-flight buffer. Graceful
12
+ * shutdown via `shutdown()` drains.
13
+ *
14
+ * Oversize guard: if the serialized batch exceeds `MAX_RECORD_BYTES`, splits
15
+ * the batch in halves and re-flushes recursively until each fragment fits.
16
+ * For singletons that still overflow, the blob-strip fallback kicks in
17
+ * (`gen_ai.message.body`, `senpi.order_response.body`, `decision.reasoning`,
18
+ * and log Body get cleared; row tagged `senpi.degraded=true`).
19
+ *
20
+ * Failure modes are fail-open: redactor throws → warn + emit un-redacted;
21
+ * fetch fails → warn + drop the batch; oversize singleton → warn + drop.
22
+ * Nothing in this layer blocks the trade path.
23
+ */
24
+ import type { LogRow, SpanRow } from "./types.js";
25
+ export type OtelTransportKind = "spans" | "logs";
26
+ export interface OtelHttpTransportOptions {
27
+ url: string;
28
+ apiKey?: string;
29
+ kind: OtelTransportKind;
30
+ /** Records buffered before forcing a flush. Default 100. */
31
+ maxBatch?: number;
32
+ /** Max age in ms of the oldest buffered record before flushing. Default 250. */
33
+ maxAgeMs?: number;
34
+ }
35
+ export declare class OtelHttpTransport<T extends SpanRow | LogRow> {
36
+ private readonly url;
37
+ private readonly apiKey?;
38
+ private readonly kind;
39
+ private readonly maxBatch;
40
+ private readonly maxAgeMs;
41
+ private buf;
42
+ private flushTimer;
43
+ private inFlight;
44
+ constructor(opts: OtelHttpTransportOptions);
45
+ /**
46
+ * Enqueue a record for the next flush. Synchronous, never throws, never
47
+ * blocks. Triggers an immediate flush when the buffer reaches `maxBatch`.
48
+ */
49
+ emit(record: T): void;
50
+ /** Drain the buffer and await all in-flight POSTs. Idempotent. */
51
+ shutdown(): Promise<void>;
52
+ private flush;
53
+ private dispatch;
54
+ private dispatchSerialized;
55
+ private buildEnvelope;
56
+ }
57
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/otel/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAQlD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjD,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC;IACxB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,MAAM;IACvD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAA4B;gBAEhC,IAAI,EAAE,wBAAwB;IAQ1C;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAarB,kEAAkE;IAC5D,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAO/B,OAAO,CAAC,KAAK;YAaC,QAAQ;YA0BR,kBAAkB;IA2DhC,OAAO,CAAC,aAAa;CAMtB"}