@senpi/runtime 1.1.0-dev.runtime-phase-2.20260609132603 → 1.1.0-dev.runtime-phase-2.20260610130051
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/dist/actions/close-position/close-position.action.d.ts +0 -16
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +38 -299
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/decision-engine.d.ts +0 -2
- package/dist/actions/decision-engine.d.ts.map +1 -1
- package/dist/actions/decision-engine.js.map +1 -1
- package/dist/actions/llm-decision/factory.d.ts +0 -3
- package/dist/actions/llm-decision/factory.d.ts.map +1 -1
- package/dist/actions/llm-decision/factory.js +0 -1
- package/dist/actions/llm-decision/factory.js.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +0 -13
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +68 -195
- package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts +0 -12
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +123 -346
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts +0 -6
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +0 -48
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +4 -0
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/recording/emitter.d.ts +21 -0
- package/dist/recording/emitter.d.ts.map +1 -0
- package/dist/recording/emitter.js +2 -0
- package/dist/recording/emitter.js.map +1 -0
- package/dist/recording/identity.d.ts +34 -0
- package/dist/recording/identity.d.ts.map +1 -0
- package/dist/recording/identity.js +2 -0
- package/dist/recording/identity.js.map +1 -0
- package/dist/recording/index.d.ts +11 -0
- package/dist/recording/index.d.ts.map +1 -0
- package/dist/recording/index.js +2 -0
- package/dist/recording/index.js.map +1 -0
- package/dist/recording/noop-emitter.d.ts +17 -0
- package/dist/recording/noop-emitter.d.ts.map +1 -0
- package/dist/recording/noop-emitter.js +16 -0
- package/dist/recording/noop-emitter.js.map +1 -0
- package/dist/recording/otel/attributes.d.ts +35 -0
- package/dist/recording/otel/attributes.d.ts.map +1 -0
- package/dist/recording/otel/attributes.js +131 -0
- package/dist/recording/otel/attributes.js.map +1 -0
- package/dist/recording/otel/constants.d.ts +81 -0
- package/dist/recording/otel/constants.d.ts.map +1 -0
- package/dist/recording/otel/constants.js +96 -0
- package/dist/recording/otel/constants.js.map +1 -0
- package/dist/recording/otel/ids.d.ts +14 -0
- package/dist/recording/otel/ids.d.ts.map +1 -0
- package/dist/recording/otel/ids.js +12 -0
- package/dist/recording/otel/ids.js.map +1 -0
- package/dist/recording/otel/index.d.ts +13 -0
- package/dist/recording/otel/index.d.ts.map +1 -0
- package/dist/recording/otel/index.js +9 -0
- package/dist/recording/otel/index.js.map +1 -0
- package/dist/recording/otel/mappers.d.ts +42 -0
- package/dist/recording/otel/mappers.d.ts.map +1 -0
- package/dist/recording/otel/mappers.js +337 -0
- package/dist/recording/otel/mappers.js.map +1 -0
- package/dist/recording/otel/otel-emitter.d.ts +37 -0
- package/dist/recording/otel/otel-emitter.d.ts.map +1 -0
- package/dist/recording/otel/otel-emitter.js +75 -0
- package/dist/recording/otel/otel-emitter.js.map +1 -0
- package/dist/recording/otel/redaction.d.ts +31 -0
- package/dist/recording/otel/redaction.d.ts.map +1 -0
- package/dist/recording/otel/redaction.js +40 -0
- package/dist/recording/otel/redaction.js.map +1 -0
- package/dist/recording/records.d.ts +327 -0
- package/dist/recording/records.d.ts.map +1 -0
- package/dist/recording/records.js +14 -0
- package/dist/recording/records.js.map +1 -0
- package/dist/recording/transport/batcher.d.ts +59 -0
- package/dist/recording/transport/batcher.d.ts.map +1 -0
- package/dist/recording/transport/batcher.js +234 -0
- package/dist/recording/transport/batcher.js.map +1 -0
- package/dist/recording/transport/client.d.ts +41 -0
- package/dist/recording/transport/client.d.ts.map +1 -0
- package/dist/recording/transport/client.js +69 -0
- package/dist/recording/transport/client.js.map +1 -0
- package/dist/recording/transport/config.d.ts +53 -0
- package/dist/recording/transport/config.d.ts.map +1 -0
- package/dist/recording/transport/config.js +41 -0
- package/dist/recording/transport/config.js.map +1 -0
- package/dist/recording/transport/index.d.ts +16 -0
- package/dist/recording/transport/index.d.ts.map +1 -0
- package/dist/recording/transport/index.js +12 -0
- package/dist/recording/transport/index.js.map +1 -0
- package/dist/recording/transport/rows.d.ts +88 -0
- package/dist/recording/transport/rows.d.ts.map +1 -0
- package/dist/recording/transport/rows.js +15 -0
- package/dist/recording/transport/rows.js.map +1 -0
- package/dist/recording/wiring/emitter-factory.d.ts +39 -0
- package/dist/recording/wiring/emitter-factory.d.ts.map +1 -0
- package/dist/recording/wiring/emitter-factory.js +62 -0
- package/dist/recording/wiring/emitter-factory.js.map +1 -0
- package/dist/recording/wiring/identity.d.ts +27 -0
- package/dist/recording/wiring/identity.d.ts.map +1 -0
- package/dist/recording/wiring/identity.js +51 -0
- package/dist/recording/wiring/identity.js.map +1 -0
- package/dist/recording/wiring/index.d.ts +12 -0
- package/dist/recording/wiring/index.d.ts.map +1 -0
- package/dist/recording/wiring/index.js +9 -0
- package/dist/recording/wiring/index.js.map +1 -0
- package/dist/recording/wiring/record-builders.d.ts +68 -0
- package/dist/recording/wiring/record-builders.d.ts.map +1 -0
- package/dist/recording/wiring/record-builders.js +441 -0
- package/dist/recording/wiring/record-builders.js.map +1 -0
- package/dist/recording/wiring/subscriber.d.ts +21 -0
- package/dist/recording/wiring/subscriber.d.ts.map +1 -0
- package/dist/recording/wiring/subscriber.js +171 -0
- package/dist/recording/wiring/subscriber.js.map +1 -0
- package/dist/recording/wiring/values.d.ts +19 -0
- package/dist/recording/wiring/values.d.ts.map +1 -0
- package/dist/recording/wiring/values.js +49 -0
- package/dist/recording/wiring/values.js.map +1 -0
- package/dist/runtime/create-actions.d.ts.map +1 -1
- package/dist/runtime/create-actions.js +0 -2
- package/dist/runtime/create-actions.js.map +1 -1
- package/dist/runtime/create-runtime-context.d.ts +0 -2
- package/dist/runtime/create-runtime-context.d.ts.map +1 -1
- package/dist/runtime/create-runtime-context.js +0 -1
- package/dist/runtime/create-runtime-context.js.map +1 -1
- package/dist/runtime/create-scanner-module.d.ts +1 -1
- package/dist/runtime/create-scanner-module.d.ts.map +1 -1
- package/dist/runtime/create-scanner-module.js +1 -2
- package/dist/runtime/create-scanner-module.js.map +1 -1
- package/dist/runtime/load-runtime-config.d.ts +9 -0
- package/dist/runtime/load-runtime-config.d.ts.map +1 -1
- package/dist/runtime/load-runtime-config.js +41 -1
- package/dist/runtime/load-runtime-config.js.map +1 -1
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +3 -2
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime-schema.d.ts +182 -24
- package/dist/runtime/runtime-schema.d.ts.map +1 -1
- package/dist/runtime/runtime-schema.js +17 -1
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime.d.ts +15 -5
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +248 -273
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/scanners/engine/data-providers.d.ts +0 -2
- package/dist/scanners/engine/data-providers.d.ts.map +1 -1
- package/dist/scanners/engine/data-providers.js.map +1 -1
- package/dist/scanners/engine/engine.d.ts.map +1 -1
- package/dist/scanners/engine/engine.js +9 -68
- package/dist/scanners/engine/engine.js.map +1 -1
- package/dist/scanners/events.d.ts +6 -0
- package/dist/scanners/events.d.ts.map +1 -1
- package/dist/scanners/events.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts +0 -2
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +9 -2
- package/dist/scanners/runtime-module.js.map +1 -1
- package/dist/senpi/client.d.ts +2 -2
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +20 -120
- package/dist/senpi/client.js.map +1 -1
- package/dist/senpi/types.d.ts +1 -68
- package/dist/senpi/types.d.ts.map +1 -1
- package/dist/strategy/strategy-state.d.ts +1 -1
- package/dist/strategy/strategy-state.d.ts.map +1 -1
- package/dist/tracking/spans/plugin-span-tracker.d.ts.map +1 -1
- package/dist/tracking/spans/plugin-span-tracker.js +24 -4
- package/dist/tracking/spans/plugin-span-tracker.js.map +1 -1
- package/dist/tracking/spans/redact-pii.d.ts +0 -10
- package/dist/tracking/spans/redact-pii.d.ts.map +1 -1
- package/dist/tracking/spans/redact-pii.js +2 -80
- package/dist/tracking/spans/redact-pii.js.map +1 -1
- package/dist/types/runtime.d.ts +0 -3
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +2 -2
- package/dist/types/strategy.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/actions/otel-helpers.d.ts +0 -65
- package/dist/actions/otel-helpers.d.ts.map +0 -1
- package/dist/actions/otel-helpers.js +0 -122
- package/dist/actions/otel-helpers.js.map +0 -1
- package/dist/otel/context.d.ts +0 -24
- package/dist/otel/context.d.ts.map +0 -1
- package/dist/otel/context.js +0 -29
- package/dist/otel/context.js.map +0 -1
- package/dist/otel/emitter.d.ts +0 -73
- package/dist/otel/emitter.d.ts.map +0 -1
- package/dist/otel/emitter.js +0 -248
- package/dist/otel/emitter.js.map +0 -1
- package/dist/otel/encode.d.ts +0 -48
- package/dist/otel/encode.d.ts.map +0 -1
- package/dist/otel/encode.js +0 -100
- package/dist/otel/encode.js.map +0 -1
- package/dist/otel/index.d.ts +0 -13
- package/dist/otel/index.d.ts.map +0 -1
- package/dist/otel/index.js +0 -10
- package/dist/otel/index.js.map +0 -1
- package/dist/otel/transport.d.ts +0 -57
- package/dist/otel/transport.d.ts.map +0 -1
- package/dist/otel/transport.js +0 -208
- package/dist/otel/transport.js.map +0 -1
- package/dist/otel/types.d.ts +0 -62
- package/dist/otel/types.d.ts.map +0 -1
- package/dist/otel/types.js +0 -2
- package/dist/otel/types.js.map +0 -1
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mapper: `RecordingRecord → TraceRow[] | LogRow[]`. Pure functions given their deps (identity,
|
|
3
|
+
* an injected {@link IdGenerator}, scope) — that is what makes the golden `record → row` tests
|
|
4
|
+
* deterministic. No `@opentelemetry/*`: this builds wire rows, it is not a span SDK.
|
|
5
|
+
*
|
|
6
|
+
* Per-record key maps and the trace-vs-log routing are pinned in {@link ./constants} and appended
|
|
7
|
+
* to the Task 2 brief. Order within a row: redact (typed-field) → flatten → cap.
|
|
8
|
+
*/
|
|
9
|
+
import { AttrBuilder, durationNs, msToNs } from "./attributes.js";
|
|
10
|
+
import { EXCEPTION_EVENT_NAME, eventNameFor, ROUTING, severityFor, SPAN_NAME, TRACE_FLAGS_SAMPLED, } from "./constants.js";
|
|
11
|
+
import { redactRuntimeError, redactRuntimeState, redactSignalEvaluated, } from "./redaction.js";
|
|
12
|
+
import { createLogger } from "../../utils/logger.js";
|
|
13
|
+
const logger = createLogger("[recording][otel][mapper]");
|
|
14
|
+
/**
|
|
15
|
+
* Identity → `ResourceAttributes` (server-required `service.name` included) + the derived `address`.
|
|
16
|
+
* Built once per emitter and shared (frozen) across every row it produces. `address` is derived from
|
|
17
|
+
* `identity.strategyAddress` directly — not read back from the attribute map — so a future attr-budget
|
|
18
|
+
* edge can never silently empty the ownership/keying field.
|
|
19
|
+
*/
|
|
20
|
+
export function buildResource(identity) {
|
|
21
|
+
const resourceAttributes = new AttrBuilder()
|
|
22
|
+
.put("service.name", identity.service)
|
|
23
|
+
.put("strategy.address", identity.strategyAddress)
|
|
24
|
+
.put("recipe", identity.recipe)
|
|
25
|
+
.put("recipe.version", identity.recipeVersion)
|
|
26
|
+
.put("runtime", identity.runtime)
|
|
27
|
+
.put("boot.id", identity.bootId)
|
|
28
|
+
.put("config.hash", identity.configHash)
|
|
29
|
+
.build();
|
|
30
|
+
// Frozen: the single resource object is shared by reference across all of an emitter's rows, so
|
|
31
|
+
// any accidental mutation would corrupt every row at once.
|
|
32
|
+
Object.freeze(resourceAttributes);
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
resourceAttributes,
|
|
35
|
+
address: (identity.strategyAddress ?? "").toLowerCase(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function spanKindFor(type) {
|
|
39
|
+
const route = ROUTING[type];
|
|
40
|
+
return route.kind === "trace" ? route.spanKind : "Internal";
|
|
41
|
+
}
|
|
42
|
+
function makeTraceRow(deps, f) {
|
|
43
|
+
return {
|
|
44
|
+
Timestamp: msToNs(f.timestampMs),
|
|
45
|
+
TraceId: f.traceId,
|
|
46
|
+
SpanId: f.spanId,
|
|
47
|
+
ParentSpanId: f.parentSpanId ?? "",
|
|
48
|
+
TraceState: "",
|
|
49
|
+
SpanName: f.spanName,
|
|
50
|
+
SpanKind: f.spanKind,
|
|
51
|
+
ServiceName: deps.identity.service,
|
|
52
|
+
Duration: durationNs(f.startedAt, f.endedAt),
|
|
53
|
+
StatusCode: f.statusCode,
|
|
54
|
+
StatusMessage: f.statusMessage ?? "",
|
|
55
|
+
SpanAttributes: f.attrs,
|
|
56
|
+
ResourceAttributes: deps.resource.resourceAttributes,
|
|
57
|
+
Events: f.events ?? [],
|
|
58
|
+
ScopeName: deps.scopeName,
|
|
59
|
+
ScopeVersion: deps.scopeVersion,
|
|
60
|
+
TraceFlags: TRACE_FLAGS_SAMPLED,
|
|
61
|
+
address: deps.resource.address,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build the single log row for a record: `Timestamp`/severity/event-name are all derived from the
|
|
66
|
+
* record, so each log mapper only supplies its `Body` and flattened attrs. Each log gets fresh,
|
|
67
|
+
* self-rooted ids (minimal per-record correlation; cross-record threading is deferred).
|
|
68
|
+
*/
|
|
69
|
+
function logRowFor(deps, record, body, attrs) {
|
|
70
|
+
const severity = severityFor(record);
|
|
71
|
+
return {
|
|
72
|
+
Timestamp: msToNs(record.occurredAt),
|
|
73
|
+
TraceId: deps.ids.traceId(),
|
|
74
|
+
SpanId: deps.ids.spanId(),
|
|
75
|
+
TraceFlags: TRACE_FLAGS_SAMPLED,
|
|
76
|
+
SeverityText: severity.text,
|
|
77
|
+
SeverityNumber: severity.number,
|
|
78
|
+
ServiceName: deps.identity.service,
|
|
79
|
+
Body: body,
|
|
80
|
+
ResourceAttributes: deps.resource.resourceAttributes,
|
|
81
|
+
ScopeName: deps.scopeName,
|
|
82
|
+
ScopeVersion: deps.scopeVersion,
|
|
83
|
+
LogAttributes: attrs,
|
|
84
|
+
EventName: eventNameFor(record),
|
|
85
|
+
address: deps.resource.address,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** OTEL `exception` span event — the idiomatic home for the error-grouping key on a span. */
|
|
89
|
+
function exceptionEvent(timestampMs, errorName, message) {
|
|
90
|
+
const attrs = new AttrBuilder()
|
|
91
|
+
.put("exception.type", errorName)
|
|
92
|
+
.put("exception.message", message)
|
|
93
|
+
.build();
|
|
94
|
+
return { Timestamp: msToNs(timestampMs), Name: EXCEPTION_EVENT_NAME, Attributes: attrs };
|
|
95
|
+
}
|
|
96
|
+
// ── scanner_run → one span ─────────────────────────────────────────────────────
|
|
97
|
+
export function mapScannerRun(record, deps) {
|
|
98
|
+
// Individual `signals[]` are omitted here — counts + summary capture the run's shape, and
|
|
99
|
+
// per-signal detail lives on `signal_evaluated` children (avoids re-flattening signal meta).
|
|
100
|
+
const attrs = new AttrBuilder()
|
|
101
|
+
.put("scanner.id", record.scannerId)
|
|
102
|
+
.put("scanner.outcome", record.outcome)
|
|
103
|
+
.put("scanner.status_detail", record.statusDetail)
|
|
104
|
+
.put("scanner.scanned_count", record.scannedCount)
|
|
105
|
+
.put("scanner.actionable_count", record.actionableCount)
|
|
106
|
+
.put("scanner.signal_count", record.signalCount)
|
|
107
|
+
.put("scanner.reason", record.reason)
|
|
108
|
+
.put("scanner.error", record.error)
|
|
109
|
+
.put("scanner.error_name", record.errorName)
|
|
110
|
+
.putBag("scanner.summary", record.summary)
|
|
111
|
+
.build();
|
|
112
|
+
const isError = record.outcome === "error";
|
|
113
|
+
return [
|
|
114
|
+
makeTraceRow(deps, {
|
|
115
|
+
timestampMs: record.startedAt,
|
|
116
|
+
traceId: deps.ids.traceId(),
|
|
117
|
+
spanId: deps.ids.spanId(),
|
|
118
|
+
spanName: SPAN_NAME.scannerRun,
|
|
119
|
+
spanKind: spanKindFor("scanner_run"),
|
|
120
|
+
startedAt: record.startedAt,
|
|
121
|
+
endedAt: record.endedAt,
|
|
122
|
+
statusCode: isError ? "Error" : "Ok",
|
|
123
|
+
statusMessage: isError ? (record.error ?? "") : "",
|
|
124
|
+
attrs,
|
|
125
|
+
events: isError ? [exceptionEvent(record.endedAt, record.errorName, record.error)] : [],
|
|
126
|
+
}),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
// ── signal_evaluated → pass-span root + one child span per evaluation ────────────
|
|
130
|
+
export function mapSignalEvaluated(record, deps) {
|
|
131
|
+
const red = redactSignalEvaluated(record);
|
|
132
|
+
const traceId = deps.ids.traceId();
|
|
133
|
+
const rootSpanId = deps.ids.spanId();
|
|
134
|
+
const rootAttrs = new AttrBuilder()
|
|
135
|
+
.put("scanner.id", red.scannerId)
|
|
136
|
+
.put("signal.evaluation_count", red.evaluations.length);
|
|
137
|
+
const d = red.decision;
|
|
138
|
+
if (d) {
|
|
139
|
+
rootAttrs
|
|
140
|
+
.put("decision.execute", d.execute)
|
|
141
|
+
.put("decision.action_type", d.actionType)
|
|
142
|
+
.put("decision.action_name", d.actionName)
|
|
143
|
+
.put("decision.mode", d.mode)
|
|
144
|
+
.put("decision.confidence", d.confidence)
|
|
145
|
+
.put("decision.confidence_threshold", d.confidenceThreshold)
|
|
146
|
+
.put("decision.reasoning", d.reasoning) // kept (length-capped) — high-value agent rationale
|
|
147
|
+
.put("decision.model", d.model)
|
|
148
|
+
.put("decision.tokens_used", d.tokensUsed)
|
|
149
|
+
.put("decision.duration_ms", d.durationMs);
|
|
150
|
+
// decision.payload is NOT flattened: raw LLM JSON (free-text + arbitrary keys + nested scanner
|
|
151
|
+
// meta). Its bounded content is already on the per-signal child spans.
|
|
152
|
+
}
|
|
153
|
+
const rows = [
|
|
154
|
+
makeTraceRow(deps, {
|
|
155
|
+
timestampMs: red.startedAt,
|
|
156
|
+
traceId,
|
|
157
|
+
spanId: rootSpanId,
|
|
158
|
+
spanName: SPAN_NAME.signalPass,
|
|
159
|
+
spanKind: spanKindFor("signal_evaluated"),
|
|
160
|
+
startedAt: red.startedAt,
|
|
161
|
+
endedAt: red.endedAt,
|
|
162
|
+
statusCode: "Ok",
|
|
163
|
+
attrs: rootAttrs.build(),
|
|
164
|
+
}),
|
|
165
|
+
];
|
|
166
|
+
// One child span per evaluation, sharing the root's TraceId (intra-record parenting). Each child
|
|
167
|
+
// is mapped defensively: a single bad evaluation must not sink the pass span or its siblings.
|
|
168
|
+
for (const ev of red.evaluations) {
|
|
169
|
+
try {
|
|
170
|
+
rows.push(mapEvaluationChild(ev, deps, traceId, rootSpanId, red.startedAt));
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
logger.warn("dropping signal evaluation child (mapping error)", {
|
|
174
|
+
err: err instanceof Error ? err.message : String(err),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return rows;
|
|
179
|
+
}
|
|
180
|
+
function mapEvaluationChild(ev, deps, traceId, parentSpanId,
|
|
181
|
+
// No per-evaluation timestamps exist; each child is point-in-time at the pass start, Duration 0.
|
|
182
|
+
passStartedAt) {
|
|
183
|
+
const { signal, outcome } = ev;
|
|
184
|
+
const attrs = new AttrBuilder()
|
|
185
|
+
.put("signal.type", signal.signalType)
|
|
186
|
+
.put("signal.asset", signal.asset)
|
|
187
|
+
.put("signal.direction", signal.direction)
|
|
188
|
+
.put("signal.score", signal.score)
|
|
189
|
+
.put("signal.timestamp", signal.timestamp)
|
|
190
|
+
.putFactors("signal.factor", signal.factors)
|
|
191
|
+
// signal.meta is dropped by redaction upstream.
|
|
192
|
+
.put("outcome.result", outcome.result)
|
|
193
|
+
.put("outcome.summary", outcome.summary)
|
|
194
|
+
.put("outcome.reason_code", outcome.reasonCode)
|
|
195
|
+
.put("outcome.reason", outcome.reason)
|
|
196
|
+
.put("outcome.error", outcome.error)
|
|
197
|
+
.put("outcome.error_name", outcome.errorName)
|
|
198
|
+
.put("outcome.leverage", outcome.leverage)
|
|
199
|
+
.put("outcome.margin_amount", outcome.marginAmount)
|
|
200
|
+
.put("outcome.notional_value", outcome.notionalValue)
|
|
201
|
+
.put("outcome.order_id", outcome.orderId)
|
|
202
|
+
.put("outcome.entry_price", outcome.entryPrice)
|
|
203
|
+
.put("outcome.size", outcome.size)
|
|
204
|
+
.put("outcome.filled", outcome.filled)
|
|
205
|
+
.put("outcome.execution_as_maker", outcome.executionAsMaker)
|
|
206
|
+
.put("outcome.required_margin_amount", outcome.requiredMarginAmount)
|
|
207
|
+
.put("outcome.available_margin_amount", outcome.availableMarginAmount)
|
|
208
|
+
.build();
|
|
209
|
+
const isError = outcome.result === "error";
|
|
210
|
+
return makeTraceRow(deps, {
|
|
211
|
+
timestampMs: passStartedAt,
|
|
212
|
+
traceId,
|
|
213
|
+
spanId: deps.ids.spanId(),
|
|
214
|
+
parentSpanId,
|
|
215
|
+
spanName: SPAN_NAME.signalEvaluation,
|
|
216
|
+
spanKind: spanKindFor("signal_evaluated"),
|
|
217
|
+
startedAt: passStartedAt,
|
|
218
|
+
endedAt: passStartedAt,
|
|
219
|
+
statusCode: isError ? "Error" : "Ok",
|
|
220
|
+
statusMessage: isError ? (outcome.error ?? "") : "",
|
|
221
|
+
attrs,
|
|
222
|
+
events: isError ? [exceptionEvent(passStartedAt, outcome.errorName, outcome.error)] : [],
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// ── position_lifecycle → one log ─────────────────────────────────────────────────
|
|
226
|
+
export function mapPositionLifecycle(record, deps) {
|
|
227
|
+
// No bag/PII to scrub here: `reasoning` is kept (length-capped) as high-value agent rationale.
|
|
228
|
+
const attrs = new AttrBuilder()
|
|
229
|
+
.put("position.event", record.event)
|
|
230
|
+
.put("position.asset", record.asset)
|
|
231
|
+
.put("position.dex", record.dex)
|
|
232
|
+
.put("position.direction", record.direction)
|
|
233
|
+
.put("position.entry_price", record.entryPrice)
|
|
234
|
+
.put("position.size", record.size)
|
|
235
|
+
.put("position.leverage", record.leverage)
|
|
236
|
+
.put("position.leverage_type", record.leverageType)
|
|
237
|
+
.put("position.margin", record.margin)
|
|
238
|
+
.put("position.unrealized_pnl", record.unrealizedPnl)
|
|
239
|
+
.put("position.roe", record.roe)
|
|
240
|
+
.put("position.liquidation_price", record.liquidationPrice)
|
|
241
|
+
.put("position.reason", record.reason)
|
|
242
|
+
.put("position.close_reason", record.closeReason)
|
|
243
|
+
.put("position.closed_price", record.closedPrice)
|
|
244
|
+
.put("position.closed_size", record.closedSize)
|
|
245
|
+
.put("position.execution_as_maker", record.executionAsMaker)
|
|
246
|
+
.put("position.previous_entry_price", record.previousEntryPrice)
|
|
247
|
+
.put("position.previous_size", record.previousSize)
|
|
248
|
+
.put("position.size_delta", record.sizeDelta)
|
|
249
|
+
.put("position.new_asset", record.newAsset)
|
|
250
|
+
.put("position.order_id", record.orderId)
|
|
251
|
+
.put("position.order_type", record.orderType)
|
|
252
|
+
.put("position.margin_amount", record.marginAmount)
|
|
253
|
+
.put("position.filled", record.filled)
|
|
254
|
+
.put("position.reasoning", record.reasoning) // kept (length-capped)
|
|
255
|
+
.build();
|
|
256
|
+
const dir = record.direction ? ` ${record.direction}` : "";
|
|
257
|
+
return [logRowFor(deps, record, `position ${record.event} ${record.asset}${dir}`, attrs)];
|
|
258
|
+
}
|
|
259
|
+
// ── dsl_transition → one log ─────────────────────────────────────────────────────
|
|
260
|
+
export function mapDslTransition(record, deps) {
|
|
261
|
+
const attrs = new AttrBuilder()
|
|
262
|
+
.put("dsl.transition", record.transition)
|
|
263
|
+
.put("dsl.asset", record.asset)
|
|
264
|
+
.put("dsl.dex", record.dex)
|
|
265
|
+
.put("dsl.trigger_reason", record.triggerReason)
|
|
266
|
+
.put("dsl.preset", record.preset)
|
|
267
|
+
.putJson("dsl.tiers", record.tiers)
|
|
268
|
+
.put("dsl.direction", record.direction)
|
|
269
|
+
.put("dsl.entry_price", record.entryPrice)
|
|
270
|
+
.put("dsl.leverage", record.leverage)
|
|
271
|
+
.put("dsl.margin", record.margin)
|
|
272
|
+
.put("dsl.size", record.size)
|
|
273
|
+
.put("dsl.floor_price", record.floorPrice)
|
|
274
|
+
.put("dsl.new_floor_price", record.newFloorPrice)
|
|
275
|
+
.put("dsl.phase", record.phase)
|
|
276
|
+
.put("dsl.tier_index", record.tierIndex)
|
|
277
|
+
.put("dsl.lock_hw_pct", record.lockHwPct)
|
|
278
|
+
.put("dsl.trigger_pct", record.triggerPct)
|
|
279
|
+
.put("dsl.locked_profit_pct", record.lockedProfitPct)
|
|
280
|
+
.put("dsl.new_sl_price", record.newSLPrice)
|
|
281
|
+
.put("dsl.sl_order_id", record.slOrderId)
|
|
282
|
+
.put("dsl.reason", record.reason)
|
|
283
|
+
.put("dsl.close_reason", record.closeReason)
|
|
284
|
+
.put("dsl.created_at", record.createdAt)
|
|
285
|
+
.put("dsl.current_roe", record.currentROE)
|
|
286
|
+
.put("dsl.high_water_roe", record.highWaterRoe)
|
|
287
|
+
.put("dsl.high_water_price", record.highWaterPrice)
|
|
288
|
+
.put("dsl.peak_roe", record.peakROE)
|
|
289
|
+
.put("dsl.last_price", record.lastPrice)
|
|
290
|
+
.put("dsl.attempt", record.attempt)
|
|
291
|
+
.putJson("dsl.updated", record.updated)
|
|
292
|
+
.put("dsl.backend_dsl_position_id", record.backendDslPositionId)
|
|
293
|
+
.build();
|
|
294
|
+
return [logRowFor(deps, record, `dsl ${record.transition} ${record.asset}`, attrs)];
|
|
295
|
+
}
|
|
296
|
+
// ── runtime_error → one log ───────────────────────────────────────────────────────
|
|
297
|
+
export function mapRuntimeError(record, deps) {
|
|
298
|
+
const red = redactRuntimeError(record);
|
|
299
|
+
const attrs = new AttrBuilder()
|
|
300
|
+
.put("runtime.phase", red.phase)
|
|
301
|
+
.put("runtime.message", red.message)
|
|
302
|
+
.put("runtime.error_name", red.errorName)
|
|
303
|
+
.put("runtime.asset", red.asset)
|
|
304
|
+
.put("runtime.scanner_id", red.scannerId)
|
|
305
|
+
.put("runtime.stack", red.stack)
|
|
306
|
+
.build();
|
|
307
|
+
return [logRowFor(deps, red, `${red.phase}: ${red.message}`, attrs)];
|
|
308
|
+
}
|
|
309
|
+
// ── runtime_lifecycle → one log ───────────────────────────────────────────────────
|
|
310
|
+
export function mapRuntimeLifecycle(record, deps) {
|
|
311
|
+
const attrs = new AttrBuilder()
|
|
312
|
+
.put("runtime.phase", record.phase)
|
|
313
|
+
.put("runtime.version", record.runtimeVersion)
|
|
314
|
+
.put("runtime.has_dsl", record.hasDsl)
|
|
315
|
+
.put("runtime.scanner_count", record.scannerCount)
|
|
316
|
+
.put("runtime.action_count", record.actionCount)
|
|
317
|
+
.put("runtime.uptime_ms", record.uptimeMs)
|
|
318
|
+
// Unresolved config blob: single JSON key, size-capped, never flattened (no secrets to scrub).
|
|
319
|
+
.putConfig("runtime.config", record.config)
|
|
320
|
+
.build();
|
|
321
|
+
return [logRowFor(deps, record, `runtime ${record.phase}`, attrs)];
|
|
322
|
+
}
|
|
323
|
+
// ── runtime_state → one log ───────────────────────────────────────────────────────
|
|
324
|
+
export function mapRuntimeState(record, deps) {
|
|
325
|
+
const red = redactRuntimeState(record);
|
|
326
|
+
const attrs = new AttrBuilder()
|
|
327
|
+
.put("runtime.phase", red.phase)
|
|
328
|
+
.put("runtime.gate_id", red.gateId)
|
|
329
|
+
.put("runtime.gate_name", red.gateName)
|
|
330
|
+
.put("runtime.source", red.source)
|
|
331
|
+
.put("runtime.reason", red.reason)
|
|
332
|
+
// runtime.metrics dropped by redaction upstream.
|
|
333
|
+
.build();
|
|
334
|
+
// `|| gateId` (not `??`): an empty-string gateName must still fall back to the stable id.
|
|
335
|
+
return [logRowFor(deps, red, `trading ${red.phase}: ${red.gateName || red.gateId}`, attrs)];
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappers.js","sourceRoot":"","sources":["../../../src/recording/otel/mappers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,OAAO,EACP,WAAW,EACX,SAAS,EACT,mBAAmB,GAEpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,GAAG,YAAY,CAAC,2BAA2B,CAAC,CAAC;AAoBzD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAA0B;IACtD,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE;SACzC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,OAAO,CAAC;SACrC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,eAAe,CAAC;SACjD,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;SAC9B,GAAG,CAAC,gBAAgB,EAAE,QAAQ,CAAC,aAAa,CAAC;SAC7C,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC;SAChC,GAAG,CAAC,S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,EAAE,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,MAA0B,EAAE,IAAgB;IAC1E,MAAM,GAAG,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE;SAC5B,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC;SAC/B,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC;SAClC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,QAAQ,CAAC;SACtC,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC;SACjC,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC;QAClC,iDAAiD;SAChD,KAAK,EAAE,CAAC;IAEX,0FAA0F;IAC1F,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `OtelEmitter` — the {@link RecordingEmitter} that turns domain records into HyperDX rows and hands
|
|
3
|
+
* them to the {@link TelemetryBatcher}. It holds the identity envelope, owns the injected id seam,
|
|
4
|
+
* and dispatches each record to its mapper.
|
|
5
|
+
*
|
|
6
|
+
* Never throws (Rule 3): a mapping error is swallowed and logged so telemetry can never alter,
|
|
7
|
+
* block, or throw into trading behavior. For the multi-row `signal_evaluated` record, child mapping
|
|
8
|
+
* is already defensive (one bad child cannot sink the pass span or its siblings — see the mapper).
|
|
9
|
+
*/
|
|
10
|
+
import type { RecordingEmitter } from "../emitter.js";
|
|
11
|
+
import type { IdentityEnvelope } from "../identity.js";
|
|
12
|
+
import type { DslTransitionRecord, PositionLifecycleRecord, RuntimeErrorRecord, RuntimeLifecycleRecord, RuntimeStateRecord, ScannerRunRecord, SignalEvaluatedRecord } from "../records.js";
|
|
13
|
+
import type { TelemetryBatcher } from "../transport/index.js";
|
|
14
|
+
import { type IdGenerator } from "./ids.js";
|
|
15
|
+
export interface OtelEmitterOptions {
|
|
16
|
+
/** Id generator seam — defaults to {@link cryptoIdGenerator}; tests inject a deterministic stub. */
|
|
17
|
+
readonly ids?: IdGenerator;
|
|
18
|
+
readonly scopeName?: string;
|
|
19
|
+
/** Defaults to {@link SCOPE_VERSION}; Task 4 wiring can pass the real package version. */
|
|
20
|
+
readonly scopeVersion?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class OtelEmitter implements RecordingEmitter {
|
|
23
|
+
private readonly batcher;
|
|
24
|
+
private readonly deps;
|
|
25
|
+
constructor(identity: IdentityEnvelope, batcher: TelemetryBatcher, options?: OtelEmitterOptions);
|
|
26
|
+
recordScannerRun(record: ScannerRunRecord): void;
|
|
27
|
+
recordSignalEvaluated(record: SignalEvaluatedRecord): void;
|
|
28
|
+
recordPositionLifecycle(record: PositionLifecycleRecord): void;
|
|
29
|
+
recordDslTransition(record: DslTransitionRecord): void;
|
|
30
|
+
recordError(record: RuntimeErrorRecord): void;
|
|
31
|
+
recordRuntimeLifecycle(record: RuntimeLifecycleRecord): void;
|
|
32
|
+
recordRuntimeState(record: RuntimeStateRecord): void;
|
|
33
|
+
private emitTraces;
|
|
34
|
+
private emitLogs;
|
|
35
|
+
private swallow;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=otel-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-emitter.d.ts","sourceRoot":"","sources":["../../../src/recording/otel/otel-emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;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rows and hands
|
|
3
|
+
* them to the {@link TelemetryBatcher}. It holds the identity envelope, owns the injected id seam,
|
|
4
|
+
* and dispatches each record to its mapper.
|
|
5
|
+
*
|
|
6
|
+
* Never throws (Rule 3): a mapping error is swallowed and logged so telemetry can never alter,
|
|
7
|
+
* block, or throw into trading behavior. For the multi-row `signal_evaluated` record, child mapping
|
|
8
|
+
* is already defensive (one bad child cannot sink the pass span or its siblings — see the mapper).
|
|
9
|
+
*/
|
|
10
|
+
import { SCOPE_NAME, SCOPE_VERSION } from "./constants.js";
|
|
11
|
+
import { cryptoIdGenerator } from "./ids.js";
|
|
12
|
+
import { buildResource, mapDslTransition, mapPositionLifecycle, mapRuntimeError, mapRuntimeLifecycle, mapRuntimeState, mapScannerRun, mapSignalEvaluated, } from "./mappers.js";
|
|
13
|
+
import { createLogger } from "../../utils/logger.js";
|
|
14
|
+
const logger = createLogger("[recording][otel][emitter]");
|
|
15
|
+
export class OtelEmitter {
|
|
16
|
+
batcher;
|
|
17
|
+
deps;
|
|
18
|
+
constructor(identity, batcher, options = {}) {
|
|
19
|
+
this.batcher = batcher;
|
|
20
|
+
this.deps = {
|
|
21
|
+
identity,
|
|
22
|
+
// Identity is immutable for the emitter's lifetime — build the resource (attrs + address) once.
|
|
23
|
+
resource: buildResource(identity),
|
|
24
|
+
ids: options.ids ?? cryptoIdGenerator,
|
|
25
|
+
scopeName: options.scopeName ?? SCOPE_NAME,
|
|
26
|
+
scopeVersion: options.scopeVersion ?? SCOPE_VERSION,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
recordScannerRun(record) {
|
|
30
|
+
this.emitTraces("recordScannerRun", () => mapScannerRun(record, this.deps));
|
|
31
|
+
}
|
|
32
|
+
recordSignalEvaluated(record) {
|
|
33
|
+
this.emitTraces("recordSignalEvaluated", () => mapSignalEvaluated(record, this.deps));
|
|
34
|
+
}
|
|
35
|
+
recordPositionLifecycle(record) {
|
|
36
|
+
this.emitLogs("recordPositionLifecycle", () => mapPositionLifecycle(record, this.deps));
|
|
37
|
+
}
|
|
38
|
+
recordDslTransition(record) {
|
|
39
|
+
this.emitLogs("recordDslTransition", () => mapDslTransition(record, this.deps));
|
|
40
|
+
}
|
|
41
|
+
recordError(record) {
|
|
42
|
+
this.emitLogs("recordError", () => mapRuntimeError(record, this.deps));
|
|
43
|
+
}
|
|
44
|
+
recordRuntimeLifecycle(record) {
|
|
45
|
+
this.emitLogs("recordRuntimeLifecycle", () => mapRuntimeLifecycle(record, this.deps));
|
|
46
|
+
}
|
|
47
|
+
recordRuntimeState(record) {
|
|
48
|
+
this.emitLogs("recordRuntimeState", () => mapRuntimeState(record, this.deps));
|
|
49
|
+
}
|
|
50
|
+
emitTraces(label, map) {
|
|
51
|
+
try {
|
|
52
|
+
for (const row of map())
|
|
53
|
+
this.batcher.enqueueTrace(row);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
this.swallow(label, err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
emitLogs(label, map) {
|
|
60
|
+
try {
|
|
61
|
+
for (const row of map())
|
|
62
|
+
this.batcher.enqueueLog(row);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
this.swallow(label, err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
swallow(label, err) {
|
|
69
|
+
logger.warn("recording emit failed; swallowed (telemetry must never throw into trading)", {
|
|
70
|
+
method: label,
|
|
71
|
+
err: err instanceof Error ? err.message : String(err),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=otel-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-emitter.js","sourceRoot":"","sources":["../../../src/recording/otel/otel-emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAoB,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,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;SACtD,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction (Rule 6) — the only place sensitive data is scrubbed. It runs on **typed fields by
|
|
3
|
+
* name, before flattening**: the sensitive fields are enumerable, so this is deterministic and
|
|
4
|
+
* testable, more robust than scrubbing flattened keys after the fact.
|
|
5
|
+
*
|
|
6
|
+
* Policy (value-vs-risk, confirmed against the real producers):
|
|
7
|
+
* - **Drop the two genuinely-open bags wholesale.** `SignalSummary.meta` is bounded only for the
|
|
8
|
+
* scanners we ship, but the runtime exists to host arbitrary scanner implementations, so its
|
|
9
|
+
* contents can't be vouched for. `SignalDecision.payload` is raw LLM JSON validated only as "an
|
|
10
|
+
* object" (free-text + arbitrary keys + a nested scanner-meta passthrough). Neither ships; the
|
|
11
|
+
* high-value bounded data they'd carry is already on typed scalars / the per-signal child spans.
|
|
12
|
+
* - **Mask `RuntimeErrorRecord.stack`** (it can embed file paths / secrets) with {@link REDACT_MARKER}.
|
|
13
|
+
* - **Kept (NOT redacted), only length-capped at flatten time:** `SignalDecision.reasoning` and
|
|
14
|
+
* `PositionLifecycleRecord.reasoning` (high-value agent rationale — paired with the child spans
|
|
15
|
+
* they let you audit whether the reasoning matched the decision), and `RuntimeStateRecord.reason`
|
|
16
|
+
* (code-templated "why trading paused" string with live numbers, no user/LLM input).
|
|
17
|
+
* - `RuntimeStateRecord.metrics` is dropped — provably numeric/boolean, but not requested for now.
|
|
18
|
+
* - `RuntimeLifecycleRecord.config` is the *unresolved* config (placeholders intact, no inlined
|
|
19
|
+
* secrets), so it is only size-capped, never redacted.
|
|
20
|
+
*
|
|
21
|
+
* `decision.payload` is dropped by simply not flattening it in the mapper; this module clears the
|
|
22
|
+
* fields that must not survive even if a future mapper change tries to read them.
|
|
23
|
+
*/
|
|
24
|
+
import type { RuntimeErrorRecord, RuntimeStateRecord, SignalEvaluatedRecord } from "../records.js";
|
|
25
|
+
/** Drop `signal.meta` (open bag, arbitrary scanner contents). `reasoning` is kept (length-capped). */
|
|
26
|
+
export declare function redactSignalEvaluated(record: SignalEvaluatedRecord): SignalEvaluatedRecord;
|
|
27
|
+
/** Mask `stack` (may embed paths/secrets). The `message` is kept — it is the grouping context. */
|
|
28
|
+
export declare function redactRuntimeError(record: RuntimeErrorRecord): RuntimeErrorRecord;
|
|
29
|
+
/** Drop the `metrics` bag (not surfaced for now). `reason` is kept (code-templated, length-capped). */
|
|
30
|
+
export declare function redactRuntimeState(record: RuntimeStateRecord): RuntimeStateRecord;
|
|
31
|
+
//# sourceMappingURL=redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../../../src/recording/otel/redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AAEvB,sGAAsG;AACtG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,qBAAqB,CAK1F;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAGjF;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAEjF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction (Rule 6) — the only place sensitive data is scrubbed. It runs on **typed fields by
|
|
3
|
+
* name, before flattening**: the sensitive fields are enumerable, so this is deterministic and
|
|
4
|
+
* testable, more robust than scrubbing flattened keys after the fact.
|
|
5
|
+
*
|
|
6
|
+
* Policy (value-vs-risk, confirmed against the real producers):
|
|
7
|
+
* - **Drop the two genuinely-open bags wholesale.** `SignalSummary.meta` is bounded only for the
|
|
8
|
+
* scanners we ship, but the runtime exists to host arbitrary scanner implementations, so its
|
|
9
|
+
* contents can't be vouched for. `SignalDecision.payload` is raw LLM JSON validated only as "an
|
|
10
|
+
* object" (free-text + arbitrary keys + a nested scanner-meta passthrough). Neither ships; the
|
|
11
|
+
* high-value bounded data they'd carry is already on typed scalars / the per-signal child spans.
|
|
12
|
+
* - **Mask `RuntimeErrorRecord.stack`** (it can embed file paths / secrets) with {@link REDACT_MARKER}.
|
|
13
|
+
* - **Kept (NOT redacted), only length-capped at flatten time:** `SignalDecision.reasoning` and
|
|
14
|
+
* `PositionLifecycleRecord.reasoning` (high-value agent rationale — paired with the child spans
|
|
15
|
+
* they let you audit whether the reasoning matched the decision), and `RuntimeStateRecord.reason`
|
|
16
|
+
* (code-templated "why trading paused" string with live numbers, no user/LLM input).
|
|
17
|
+
* - `RuntimeStateRecord.metrics` is dropped — provably numeric/boolean, but not requested for now.
|
|
18
|
+
* - `RuntimeLifecycleRecord.config` is the *unresolved* config (placeholders intact, no inlined
|
|
19
|
+
* secrets), so it is only size-capped, never redacted.
|
|
20
|
+
*
|
|
21
|
+
* `decision.payload` is dropped by simply not flattening it in the mapper; this module clears the
|
|
22
|
+
* fields that must not survive even if a future mapper change tries to read them.
|
|
23
|
+
*/
|
|
24
|
+
import { REDACT_MARKER } from "./constants.js";
|
|
25
|
+
/** Drop `signal.meta` (open bag, arbitrary scanner contents). `reasoning` is kept (length-capped). */
|
|
26
|
+
export function redactSignalEvaluated(record) {
|
|
27
|
+
const evaluations = record.evaluations.map((ev) => ev.signal.meta === undefined ? ev : { ...ev, signal: { ...ev.signal, meta: undefined } });
|
|
28
|
+
return { ...record, evaluations };
|
|
29
|
+
}
|
|
30
|
+
/** Mask `stack` (may embed paths/secrets). The `message` is kept — it is the grouping context. */
|
|
31
|
+
export function redactRuntimeError(record) {
|
|
32
|
+
if (!record.stack)
|
|
33
|
+
return record;
|
|
34
|
+
return { ...record, stack: REDACT_MARKER };
|
|
35
|
+
}
|
|
36
|
+
/** Drop the `metrics` bag (not surfaced for now). `reason` is kept (code-templated, length-capped). */
|
|
37
|
+
export function redactRuntimeState(record) {
|
|
38
|
+
return { ...record, metrics: null };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../../src/recording/otel/redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQ/C,sGAAsG;AACtG,MAAM,UAAU,qBAAqB,CAAC,MAA6B;IACjE,MAAM,WAAW,GAAuB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACpE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CACzF,CAAC;IACF,OAAO,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,CAAC;AACpC,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IAC3D,IAAI,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC;IACjC,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAC7C,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IAC3D,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACtC,CAAC"}
|