@senpi/runtime 3.0.6-dev.runtime-phase-2.20260630134307 → 3.0.6-dev.runtime-phase-2.20260630134410
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 +1 -1
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +15 -14
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/event-derivation.d.ts +60 -0
- package/dist/actions/event-derivation.d.ts.map +1 -0
- package/dist/actions/event-derivation.js +179 -0
- package/dist/actions/event-derivation.js.map +1 -0
- package/dist/actions/llm-decision/anthropic-llm-decision.d.ts +5 -9
- package/dist/actions/llm-decision/anthropic-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/anthropic-llm-decision.js +6 -87
- package/dist/actions/llm-decision/anthropic-llm-decision.js.map +1 -1
- package/dist/actions/llm-decision/factory.d.ts +0 -6
- package/dist/actions/llm-decision/factory.d.ts.map +1 -1
- package/dist/actions/llm-decision/factory.js +0 -2
- package/dist/actions/llm-decision/factory.js.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +21 -2
- package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts +1 -1
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +28 -21
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +2 -4
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/actions/tracking-helpers.d.ts +41 -3
- package/dist/actions/tracking-helpers.d.ts.map +1 -1
- package/dist/actions/tracking-helpers.js +100 -11
- package/dist/actions/tracking-helpers.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +8 -0
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +36 -2
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/recording/otel/attributes.d.ts +2 -0
- package/dist/recording/otel/attributes.d.ts.map +1 -1
- package/dist/recording/otel/attributes.js +1 -1
- package/dist/recording/otel/attributes.js.map +1 -1
- package/dist/recording/otel/mappers.d.ts.map +1 -1
- package/dist/recording/otel/mappers.js +1 -0
- package/dist/recording/otel/mappers.js.map +1 -1
- package/dist/recording/records.d.ts +7 -1
- package/dist/recording/records.d.ts.map +1 -1
- package/dist/recording/wiring/emitter-factory.d.ts +0 -5
- package/dist/recording/wiring/emitter-factory.d.ts.map +1 -1
- package/dist/recording/wiring/emitter-factory.js +0 -18
- package/dist/recording/wiring/emitter-factory.js.map +1 -1
- package/dist/recording/wiring/index.d.ts +1 -1
- package/dist/recording/wiring/index.d.ts.map +1 -1
- package/dist/recording/wiring/index.js +1 -1
- package/dist/recording/wiring/index.js.map +1 -1
- package/dist/recording/wiring/record-builders.d.ts.map +1 -1
- package/dist/recording/wiring/record-builders.js +5 -2
- package/dist/recording/wiring/record-builders.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +2 -2
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/create-actions.d.ts.map +1 -1
- package/dist/runtime/create-actions.js +0 -10
- package/dist/runtime/create-actions.js.map +1 -1
- package/dist/runtime/domain-events.d.ts +43 -0
- package/dist/runtime/domain-events.d.ts.map +1 -0
- package/dist/runtime/domain-events.js +181 -0
- package/dist/runtime/domain-events.js.map +1 -0
- package/dist/runtime/lifecycle-events.d.ts +43 -0
- package/dist/runtime/lifecycle-events.d.ts.map +1 -0
- package/dist/runtime/lifecycle-events.js +139 -0
- package/dist/runtime/lifecycle-events.js.map +1 -0
- package/dist/runtime/notifications.js +2 -2
- package/dist/runtime/notifications.js.map +1 -1
- package/dist/runtime/runtime-schema.d.ts +124 -173
- package/dist/runtime/runtime-schema.d.ts.map +1 -1
- package/dist/runtime/runtime-schema.js +4 -4
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime.d.ts +1 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +62 -52
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategy-lifecycle.d.ts.map +1 -1
- package/dist/runtime/strategy-lifecycle.js +13 -1
- package/dist/runtime/strategy-lifecycle.js.map +1 -1
- package/dist/runtime-api/routes/signals.d.ts +1 -1
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +2 -8
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/senpi/client.d.ts +10 -0
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +71 -49
- package/dist/senpi/client.js.map +1 -1
- package/dist/skills-manager/coordinator.js +3 -3
- package/dist/skills-manager/coordinator.js.map +1 -1
- package/dist/telemetry/metrics.d.ts +47 -0
- package/dist/telemetry/metrics.d.ts.map +1 -0
- package/dist/telemetry/metrics.js +154 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/telemetry/otel-sdk.d.ts +23 -35
- package/dist/telemetry/otel-sdk.d.ts.map +1 -1
- package/dist/telemetry/otel-sdk.js +83 -54
- package/dist/telemetry/otel-sdk.js.map +1 -1
- package/dist/telemetry/trace-identity.d.ts +2 -1
- package/dist/telemetry/trace-identity.d.ts.map +1 -1
- package/dist/telemetry/trace-identity.js +2 -1
- package/dist/telemetry/trace-identity.js.map +1 -1
- package/dist/telemetry/tracing.d.ts +2 -1
- package/dist/telemetry/tracing.d.ts.map +1 -1
- package/dist/telemetry/tracing.js +1 -1
- package/dist/telemetry/tracing.js.map +1 -1
- package/dist/tracking/context.d.ts +6 -0
- package/dist/tracking/context.d.ts.map +1 -1
- package/dist/tracking/context.js.map +1 -1
- package/dist/tracking/spans/constants.d.ts +4 -11
- package/dist/tracking/spans/constants.d.ts.map +1 -1
- package/dist/tracking/spans/constants.js +4 -23
- package/dist/tracking/spans/constants.js.map +1 -1
- package/dist/tracking/spans/gen-ai.d.ts +70 -0
- package/dist/tracking/spans/gen-ai.d.ts.map +1 -0
- package/dist/tracking/spans/gen-ai.js +330 -0
- package/dist/tracking/spans/gen-ai.js.map +1 -0
- package/dist/tracking/spans/index.d.ts +6 -8
- package/dist/tracking/spans/index.d.ts.map +1 -1
- package/dist/tracking/spans/index.js +6 -11
- package/dist/tracking/spans/index.js.map +1 -1
- package/dist/tracking/spans/redact-pii.d.ts +19 -21
- package/dist/tracking/spans/redact-pii.d.ts.map +1 -1
- package/dist/tracking/spans/redact-pii.js +31 -31
- package/dist/tracking/spans/redact-pii.js.map +1 -1
- package/dist/tracking/spans/span-hooks.d.ts +0 -17
- package/dist/tracking/spans/span-hooks.d.ts.map +1 -1
- package/dist/tracking/spans/span-hooks.js +407 -207
- package/dist/tracking/spans/span-hooks.js.map +1 -1
- package/dist/utils/event-catalog.d.ts +269 -0
- package/dist/utils/event-catalog.d.ts.map +1 -0
- package/dist/utils/event-catalog.js +91 -0
- package/dist/utils/event-catalog.js.map +1 -0
- package/dist/utils/logger.d.ts +58 -5
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +359 -27
- package/dist/utils/logger.js.map +1 -1
- package/package.json +2 -1
- package/dist/tracking/spans/fan-out-span-transport.d.ts +0 -22
- package/dist/tracking/spans/fan-out-span-transport.d.ts.map +0 -1
- package/dist/tracking/spans/fan-out-span-transport.js +0 -49
- package/dist/tracking/spans/fan-out-span-transport.js.map +0 -1
- package/dist/tracking/spans/otel/fit-row-budget.d.ts +0 -22
- package/dist/tracking/spans/otel/fit-row-budget.d.ts.map +0 -1
- package/dist/tracking/spans/otel/fit-row-budget.js +0 -91
- package/dist/tracking/spans/otel/fit-row-budget.js.map +0 -1
- package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts +0 -16
- package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts.map +0 -1
- package/dist/tracking/spans/otel/map-span-to-trace-row.js +0 -227
- package/dist/tracking/spans/otel/map-span-to-trace-row.js.map +0 -1
- package/dist/tracking/spans/otel/recording-span-transport.d.ts +0 -43
- package/dist/tracking/spans/otel/recording-span-transport.d.ts.map +0 -1
- package/dist/tracking/spans/otel/recording-span-transport.js +0 -67
- package/dist/tracking/spans/otel/recording-span-transport.js.map +0 -1
- package/dist/tracking/spans/otel/span-ids.d.ts +0 -22
- package/dist/tracking/spans/otel/span-ids.d.ts.map +0 -1
- package/dist/tracking/spans/otel/span-ids.js +0 -32
- package/dist/tracking/spans/otel/span-ids.js.map +0 -1
- package/dist/tracking/spans/plugin-span-tracker.d.ts +0 -9
- package/dist/tracking/spans/plugin-span-tracker.d.ts.map +0 -1
- package/dist/tracking/spans/plugin-span-tracker.js +0 -115
- package/dist/tracking/spans/plugin-span-tracker.js.map +0 -1
- package/dist/tracking/spans/span-tracker.d.ts +0 -133
- package/dist/tracking/spans/span-tracker.d.ts.map +0 -1
- package/dist/tracking/spans/span-tracker.js +0 -721
- package/dist/tracking/spans/span-tracker.js.map +0 -1
- package/dist/tracking/spans/span-transport.d.ts +0 -71
- package/dist/tracking/spans/span-transport.d.ts.map +0 -1
- package/dist/tracking/spans/span-transport.js +0 -240
- package/dist/tracking/spans/span-transport.js.map +0 -1
- package/dist/tracking/spans/types.d.ts +0 -101
- package/dist/tracking/spans/types.d.ts.map +0 -1
- package/dist/tracking/spans/types.js +0 -6
- package/dist/tracking/spans/types.js.map +0 -1
|
@@ -1,34 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenTelemetry SDK stand-up:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* standardised resource-attribute set.
|
|
2
|
+
* OpenTelemetry SDK stand-up: HyperDX's OTel distribution (`@hyperdx/node-opentelemetry`)
|
|
3
|
+
* — auto-instrumentation + uncaught-exception capture — against a self-hosted OTLP collector,
|
|
4
|
+
* with a process-stable resource-attribute set.
|
|
6
5
|
*
|
|
7
|
-
* Init runs from `
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* On Node >= 22 the diagnostics_channel HTTP instrumentation hooks lazily, so
|
|
11
|
-
* deferring init still instruments outbound HTTP.
|
|
6
|
+
* Init runs from plugin `register()` (process scope): the agent hooks register there, before
|
|
7
|
+
* any runtime, and emit through this SDK's tracer. Only process-stable values ride the resource
|
|
8
|
+
* (`service.*`, `deployment.environment`, `user.id`), so init need not wait for a runtime.
|
|
12
9
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
10
|
+
* Gated by OTLP-config presence: inits iff an OTLP endpoint env is set (no enable flag, no
|
|
11
|
+
* localhost default). No endpoint ⇒ no SDK and the global tracer/logger no-op. If a non-noop
|
|
12
|
+
* global `TracerProvider` already exists (the gateway's `diagnostics-otel` owns it), we stand
|
|
13
|
+
* down and emit through the global API — one SDK per process, first writer wins.
|
|
17
14
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* OTEL_EXPORTER_OTLP_METRICS_ENDPOINT (.../v1/metrics)
|
|
24
|
-
* OTEL_EXPORTER_OTLP_HEADERS (e.g. Authorization=<collector-token>)
|
|
25
|
-
* See docs/runtime-docs/runtime-api.md (Tracing) for why each is required.
|
|
15
|
+
* The package is imported dynamically: it reads `OTEL_EXPORTER_OTLP_*` at module-load and
|
|
16
|
+
* exposes no init() option for them, so the env must be set first. Under openclaw the operator
|
|
17
|
+
* sets all of these (the SDK derives none):
|
|
18
|
+
* OTEL_EXPORTER_OTLP_ENDPOINT / _TRACES_ENDPOINT / _LOGS_ENDPOINT / _METRICS_ENDPOINT / _HEADERS
|
|
19
|
+
* See docs/runtime-docs/runtime-api.md (Tracing).
|
|
26
20
|
*/
|
|
27
21
|
import { randomUUID } from "node:crypto";
|
|
22
|
+
import { trace } from "@opentelemetry/api";
|
|
28
23
|
import { createLogger } from "../utils/logger.js";
|
|
29
24
|
const logger = createLogger("telemetry/otel-sdk");
|
|
30
|
-
/**
|
|
31
|
-
|
|
25
|
+
/** Per-signal OTLP endpoint env vars; presence of any (or the base) is the on-switch. */
|
|
26
|
+
const OTLP_ENDPOINT_ENV_VARS = [
|
|
27
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
28
|
+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
29
|
+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT",
|
|
30
|
+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT",
|
|
31
|
+
];
|
|
32
|
+
/** True when any OTLP endpoint env is set — the gate for standing up the plugin's SDK. */
|
|
33
|
+
export function isOtlpEndpointConfigured() {
|
|
34
|
+
return OTLP_ENDPOINT_ENV_VARS.some((name) => {
|
|
35
|
+
const value = process.env[name];
|
|
36
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* True when a real (non-noop) global `TracerProvider` is already registered — i.e.
|
|
41
|
+
* another SDK (the gateway's `diagnostics-otel`) owns the slot. The global API hands
|
|
42
|
+
* back a `ProxyTracerProvider` until `setGlobalTracerProvider` runs; before that its
|
|
43
|
+
* delegate is the no-op provider. We detect "real" by checking whether a delegate
|
|
44
|
+
* provider has been set: `getDelegate()` exists on the proxy and differs from the
|
|
45
|
+
* no-op. Best-effort — on any uncertainty we treat it as "not owned" and init our own.
|
|
46
|
+
*/
|
|
47
|
+
function globalTracerProviderIsReal() {
|
|
48
|
+
try {
|
|
49
|
+
const provider = trace.getTracerProvider();
|
|
50
|
+
if (typeof provider?.getDelegate !== "function") {
|
|
51
|
+
// Not a ProxyTracerProvider — a concrete provider is registered directly.
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const delegate = provider.getDelegate();
|
|
55
|
+
if (delegate == null)
|
|
56
|
+
return false;
|
|
57
|
+
// The proxy's default delegate is the NoopTracerProvider; anything else is real.
|
|
58
|
+
return delegate.constructor?.name !== "NoopTracerProvider";
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
32
64
|
/**
|
|
33
65
|
* Process-level instance id for `service.instance.id`. Distinct from the
|
|
34
66
|
* per-runtime `IdentityEnvelope.bootId`: resource attributes are process-global,
|
|
@@ -50,7 +82,7 @@ const PROCESS_INSTANCE_ID = randomUUID();
|
|
|
50
82
|
* Fix: enable our own `UndiciInstrumentation`; with no provider set it resolves the
|
|
51
83
|
* global one `init()` registered, and HyperDX's instance stays disabled (no double
|
|
52
84
|
* instrumentation). Best-effort — a failure must not fail boot. Also a prerequisite
|
|
53
|
-
* for the manual `mcp.*`/`dsl.*` spans
|
|
85
|
+
* for the manual `mcp.*`/`dsl.*` spans, which assume outbound `fetch` calls
|
|
54
86
|
* auto-nest as HTTP children.
|
|
55
87
|
*
|
|
56
88
|
* Seen with `@hyperdx/node-opentelemetry` 0.11 / `instrumentation-undici` 0.28, Node 24
|
|
@@ -131,8 +163,8 @@ export function decodeSenpiUserId(token) {
|
|
|
131
163
|
* The per-runtime keys (senpi.strategy.address, senpi.recipe, senpi.recipe.version,
|
|
132
164
|
* senpi.runtime, senpi.config.hash) are deliberately OMITTED — on a process-global
|
|
133
165
|
* resource they would stamp the first runtime's value onto every other runtime's
|
|
134
|
-
* telemetry. They
|
|
135
|
-
*
|
|
166
|
+
* telemetry. They ride per-trace via `setTraceAttributes` and per-log via the logger's
|
|
167
|
+
* emit-time identity stamp (both reading the same per-runtime identity context).
|
|
136
168
|
*/
|
|
137
169
|
export function buildOtelResourceAttributes(serviceName, extras) {
|
|
138
170
|
const pairs = [
|
|
@@ -147,38 +179,37 @@ export function buildOtelResourceAttributes(serviceName, extras) {
|
|
|
147
179
|
.map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
|
|
148
180
|
.join(",");
|
|
149
181
|
}
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
* {@link DEFAULT_OTLP_ENDPOINT}.
|
|
153
|
-
*/
|
|
154
|
-
export function resolveOtlpEndpoint() {
|
|
155
|
-
const envOverride = process.env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim();
|
|
156
|
-
if (envOverride)
|
|
157
|
-
return envOverride;
|
|
158
|
-
return DEFAULT_OTLP_ENDPOINT;
|
|
159
|
-
}
|
|
182
|
+
/** `service.name` for the plugin-owned resource; matches the tracer/logger scope. */
|
|
183
|
+
const SERVICE_NAME = "senpi-trading-runtime";
|
|
160
184
|
/**
|
|
161
185
|
* Initialise the OTel SDK. Idempotent, side-effecting, and never crashes boot:
|
|
162
|
-
* no-ops when
|
|
186
|
+
* no-ops when no OTLP endpoint is configured, when a real global TracerProvider
|
|
187
|
+
* already exists (the gateway owns it — we emit through the global API instead),
|
|
188
|
+
* when already initialised, or under test.
|
|
163
189
|
*/
|
|
164
190
|
export async function initOtelSdk(params) {
|
|
165
191
|
if (initialized)
|
|
166
192
|
return;
|
|
167
|
-
|
|
168
|
-
|
|
193
|
+
// Presence of OTLP config is the on-switch — no endpoint means telemetry off.
|
|
194
|
+
if (!isOtlpEndpointConfigured()) {
|
|
195
|
+
logger.debug("OTel SDK init skipped: no OTLP endpoint configured");
|
|
169
196
|
return;
|
|
170
197
|
}
|
|
171
|
-
//
|
|
172
|
-
//
|
|
198
|
+
// Stand down if another SDK (the gateway's diagnostics-otel) already owns the
|
|
199
|
+
// global provider — a second registration drops spans and splits resource identity.
|
|
200
|
+
if (globalTracerProviderIsReal()) {
|
|
201
|
+
logger.info("OTel SDK init skipped: a global TracerProvider already exists; emitting through the global API");
|
|
202
|
+
initialized = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
// Skip under test: the SDK would start exporters and patch core modules during vitest.
|
|
173
206
|
if (process.env.VITEST || process.env.NODE_ENV === "test") {
|
|
174
207
|
logger.debug("OTel SDK init skipped: running under test");
|
|
175
208
|
return;
|
|
176
209
|
}
|
|
177
210
|
try {
|
|
178
|
-
const identity = params.identity();
|
|
179
211
|
// Commit the guard before any fallible work: a failed init must not let a
|
|
180
|
-
// later
|
|
181
|
-
// identity() above threw before this, so env is still untouched on that path.
|
|
212
|
+
// later caller re-enter and double-append OTEL_RESOURCE_ATTRIBUTES.
|
|
182
213
|
initialized = true;
|
|
183
214
|
// Source the environment label from NODE_ENV (Node-standard). Pass the value
|
|
184
215
|
// through verbatim (so `staging`/custom envs are faithful), defaulting to
|
|
@@ -188,7 +219,7 @@ export async function initOtelSdk(params) {
|
|
|
188
219
|
const deploymentEnvironment = nodeEnv && nodeEnv.length > 0 ? nodeEnv : "development";
|
|
189
220
|
const userId = decodeSenpiUserId(params.userToken);
|
|
190
221
|
// Append to any host-set value rather than clobber operator attrs.
|
|
191
|
-
const ourAttrs = buildOtelResourceAttributes(
|
|
222
|
+
const ourAttrs = buildOtelResourceAttributes(SERVICE_NAME, {
|
|
192
223
|
serviceInstanceId: PROCESS_INSTANCE_ID,
|
|
193
224
|
serviceVersion: params.serviceVersion,
|
|
194
225
|
deploymentEnvironment,
|
|
@@ -198,20 +229,18 @@ export async function initOtelSdk(params) {
|
|
|
198
229
|
process.env.OTEL_RESOURCE_ATTRIBUTES = existingAttrs
|
|
199
230
|
? `${existingAttrs},${ourAttrs}`
|
|
200
231
|
: ourAttrs;
|
|
201
|
-
//
|
|
202
|
-
if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
|
|
203
|
-
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = resolveOtlpEndpoint();
|
|
204
|
-
}
|
|
205
|
-
// Dynamic import: loads only now, after the env var above is set.
|
|
232
|
+
// Dynamic import: loads only now, after the endpoint env is confirmed set.
|
|
206
233
|
const hyperdx = (await import("@hyperdx/node-opentelemetry"));
|
|
207
234
|
hyperdxModule = hyperdx;
|
|
208
235
|
hyperdx.init({
|
|
209
236
|
// No apiKey on init(): the exporter authenticates to the collector via the
|
|
210
237
|
// Authorization header in OTEL_EXPORTER_OTLP_HEADERS (read from env at
|
|
211
238
|
// module-load), not through the SDK's HyperDX apiKey field.
|
|
212
|
-
service:
|
|
213
|
-
//
|
|
214
|
-
|
|
239
|
+
service: SERVICE_NAME,
|
|
240
|
+
// Off: createLogger() emits structured LogRecords through the OTel Logs API directly,
|
|
241
|
+
// so capturing console.* would duplicate every log (flattened, lossy) into the collector.
|
|
242
|
+
// stdout is untouched — the local human line still prints.
|
|
243
|
+
consoleCapture: false,
|
|
215
244
|
experimentalExceptionCapture: true,
|
|
216
245
|
// Don't let HyperDX install its own SIGTERM/SIGINT handlers. Its default
|
|
217
246
|
// handler calls process.exit() once its own _shutdown() settles, without
|
|
@@ -226,7 +255,7 @@ export async function initOtelSdk(params) {
|
|
|
226
255
|
});
|
|
227
256
|
await reinstrumentUndici();
|
|
228
257
|
logger.info("OTel SDK initialised", {
|
|
229
|
-
service:
|
|
258
|
+
service: SERVICE_NAME,
|
|
230
259
|
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
231
260
|
deploymentEnvironment,
|
|
232
261
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-sdk.js","sourceRoot":"","sources":["../../src/telemetry/otel-sdk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"otel-sdk.js","sourceRoot":"","sources":["../../src/telemetry/otel-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAElD,yFAAyF;AACzF,MAAM,sBA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,2DAA2D,EAAE;YACvE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;SACtD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* The actual stamping is HyperDX's `setTraceAttributes` (rides every span in the trace),
|
|
8
8
|
* called at the root-span seams — NOT here: importing `@hyperdx/node-opentelemetry`
|
|
9
9
|
* captures its OTLP transport env at module-load, so it must stay behind code that runs
|
|
10
|
-
* only after `initOtelSdk()`.
|
|
10
|
+
* only after `initOtelSdk()`. It covers spans only; logs carry the same identity via the
|
|
11
|
+
* async-context bag the logger reads at emit time (see `trackingContext.identityAttributes`).
|
|
11
12
|
*/
|
|
12
13
|
import type { Attributes } from "@opentelemetry/api";
|
|
13
14
|
import type { IdentityEnvelope } from "../recording/identity.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-identity.d.ts","sourceRoot":"","sources":["../../src/telemetry/trace-identity.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"trace-identity.d.ts","sourceRoot":"","sources":["../../src/telemetry/trace-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAMjE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,UAAU,CAc9E;AAED;;;;;;;;;GASG;AACH,wBAAsB,0BAA0B,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1F"}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* The actual stamping is HyperDX's `setTraceAttributes` (rides every span in the trace),
|
|
8
8
|
* called at the root-span seams — NOT here: importing `@hyperdx/node-opentelemetry`
|
|
9
9
|
* captures its OTLP transport env at module-load, so it must stay behind code that runs
|
|
10
|
-
* only after `initOtelSdk()`.
|
|
10
|
+
* only after `initOtelSdk()`. It covers spans only; logs carry the same identity via the
|
|
11
|
+
* async-context bag the logger reads at emit time (see `trackingContext.identityAttributes`).
|
|
11
12
|
*/
|
|
12
13
|
import { isOtelInitialized } from "./otel-sdk.js";
|
|
13
14
|
import { createLogger } from "../utils/logger.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-identity.js","sourceRoot":"","sources":["../../src/telemetry/trace-identity.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"trace-identity.js","sourceRoot":"","sources":["../../src/telemetry/trace-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG,YAAY,CAAC,0BAA0B,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAA0B;IAChE,MAAM,UAAU,GAAe;QAC7B,wBAAwB,EAAE,QAAQ,CAAC,eAAe;QAClD,cAAc,EAAE,QAAQ,CAAC,MAAM;QAC/B,eAAe,EAAE,QAAQ,CAAC,OAAO;QACjC,eAAe,EAAE,QAAQ,CAAC,MAAM;KACjC,CAAC;IACF,IAAI,QAAQ,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACzC,UAAU,CAAC,sBAAsB,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACtC,UAAU,CAAC,mBAAmB,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC;IACxD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,QAA0B;IACzE,IAAI,CAAC,iBAAiB,EAAE;QAAE,OAAO;IACjC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAE3D,CAAC;QACF,OAAO,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,+CAA+C,EAAE;YAC3D,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;SACtD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* is not initialised (telemetry off, or under test) the API resolves a no-op tracer,
|
|
6
6
|
* so `withSpan` runs the callback with near-zero overhead — no `enabled` gate needed.
|
|
7
7
|
*/
|
|
8
|
-
import { type Span, type Attributes, type Tracer } from "@opentelemetry/api";
|
|
8
|
+
import { type Span, type SpanKind, type Attributes, type Tracer } from "@opentelemetry/api";
|
|
9
9
|
/** The single tracer for our manual spans. Resolves the no-op tracer pre-init. */
|
|
10
10
|
export declare function getTracer(): Tracer;
|
|
11
11
|
/**
|
|
@@ -28,5 +28,6 @@ export declare function getTracer(): Tracer;
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function withSpan<T>(name: string, attributes: Attributes, fn: (span: Span) => Promise<T>, options?: {
|
|
30
30
|
expected?: (err: unknown) => boolean;
|
|
31
|
+
kind?: SpanKind;
|
|
31
32
|
}): Promise<T>;
|
|
32
33
|
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/telemetry/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAK5B,kFAAkF;AAClF,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/telemetry/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAK5B,kFAAkF;AAClF,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,QAAQ,CAAA;CAAE,GAClE,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
|
|
@@ -31,7 +31,7 @@ export function getTracer() {
|
|
|
31
31
|
* error nor corrupt its result.
|
|
32
32
|
*/
|
|
33
33
|
export function withSpan(name, attributes, fn, options) {
|
|
34
|
-
return getTracer().startActiveSpan(name, { attributes }, async (span) => {
|
|
34
|
+
return getTracer().startActiveSpan(name, { attributes, kind: options?.kind }, async (span) => {
|
|
35
35
|
try {
|
|
36
36
|
return await fn(span);
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/telemetry/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,EACL,cAAc,
|
|
1
|
+
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/telemetry/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,EACL,cAAc,GAKf,MAAM,oBAAoB,CAAC;AAE5B,iEAAiE;AACjE,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C,kFAAkF;AAClF,MAAM,UAAU,SAAS;IACvB,OAAO,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAY,EACZ,UAAsB,EACtB,EAA8B,EAC9B,OAAmE;IAEnE,OAAO,SAAS,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC3F,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,QAAQ,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC;gBACH,QAAQ,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;YAC/C,CAAC;YAAC,MAAM,CAAC;gBACP,4EAA4E;YAC9E,CAAC;YACD,IAAI,QAAQ;gBAAE,MAAM,GAAG,CAAC;YACxB,IAAI,CAAC;gBACH,IAAI,CAAC,eAAe,CAAC,GAAY,CAAC,CAAC;gBACnC,IAAI,CAAC,SAAS,CAAC;oBACb,IAAI,EAAE,cAAc,CAAC,KAAK;oBAC1B,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;iBAC1D,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,wEAAwE;YAC1E,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC;gBACH,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;YAAC,MAAM,CAAC;gBACP,+DAA+D;YACjE,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -24,6 +24,12 @@ export interface TrackingContext {
|
|
|
24
24
|
runtimeVersion: string;
|
|
25
25
|
/** UUID generated once at runtime startup; lets you group direct-path spans per process. */
|
|
26
26
|
runtimeBootId: string;
|
|
27
|
+
/**
|
|
28
|
+
* The runtime's `senpi.*` identity as a precomputed attribute bag, stamped onto logs
|
|
29
|
+
* emitted within this flow. Same values the active span carries (built from one mapper),
|
|
30
|
+
* so logs and traces join cleanly. Optional: a flow may run before identity resolves.
|
|
31
|
+
*/
|
|
32
|
+
identityAttributes?: Record<string, string | number>;
|
|
27
33
|
}
|
|
28
34
|
export declare const trackingContext: AsyncLocalStorage<TrackingContext>;
|
|
29
35
|
/** Returns the current tracking context, or null when running outside any signal flow. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/tracking/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/tracking/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CACtD;AAED,eAAO,MAAM,eAAe,oCAA2C,CAAC;AAExE,0FAA0F;AAC1F,wBAAgB,kBAAkB,IAAI,eAAe,GAAG,IAAI,CAE3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/tracking/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/tracking/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAsBrD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAmB,CAAC;AAExE,0FAA0F;AAC1F,MAAM,UAAU,kBAAkB;IAChC,OAAO,eAAe,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,CAAC"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Span telemetry constants
|
|
2
|
+
* Span telemetry constants.
|
|
3
|
+
*
|
|
4
|
+
* Header names used to cross the runtime → OpenClaw HTTP boundary so the
|
|
5
|
+
* gateway-side hooks can stamp senpi identity onto the gen_ai spans.
|
|
3
6
|
*/
|
|
4
|
-
export declare const SPANS_API_PATH = "/api/v1/tracking/spans";
|
|
5
|
-
export declare const FLUSH_INTERVAL_MS = 10000;
|
|
6
|
-
export declare const FLUSH_THRESHOLD = 50;
|
|
7
|
-
export declare const MAX_BUFFER_SIZE = 500;
|
|
8
|
-
export declare const STALE_TIMEOUT_MS: number;
|
|
9
|
-
export declare const SWEEP_INTERVAL_MS = 60000;
|
|
10
|
-
export declare const MAX_BATCH_BYTES = 8000000;
|
|
11
|
-
export declare const MAX_SPAN_FIELD_BYTES = 2000000;
|
|
12
|
-
/** First N chars of each truncated value retained for debugging context. */
|
|
13
|
-
export declare const TRUNCATED_PREVIEW_BYTES = 2000;
|
|
14
7
|
export declare const HEADER_CORRELATION_ID = "x-senpi-correlation-id";
|
|
15
8
|
export declare const HEADER_ADDRESS = "x-senpi-address";
|
|
16
9
|
export declare const HEADER_RECIPE_NAME = "x-senpi-recipe-name";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/tracking/spans/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/tracking/spans/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAC9D,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AACxD,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AACtD,eAAO,MAAM,sBAAsB,4BAA4B,CAAC"}
|
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Span telemetry constants
|
|
2
|
+
* Span telemetry constants.
|
|
3
|
+
*
|
|
4
|
+
* Header names used to cross the runtime → OpenClaw HTTP boundary so the
|
|
5
|
+
* gateway-side hooks can stamp senpi identity onto the gen_ai spans.
|
|
3
6
|
*/
|
|
4
|
-
export const SPANS_API_PATH = "/api/v1/tracking/spans";
|
|
5
|
-
// Transport batching — mirrors the events transport defaults.
|
|
6
|
-
export const FLUSH_INTERVAL_MS = 10_000;
|
|
7
|
-
export const FLUSH_THRESHOLD = 50;
|
|
8
|
-
export const MAX_BUFFER_SIZE = 500;
|
|
9
|
-
// In-memory span lifecycle — sweep abandoned spans so they don't accumulate.
|
|
10
|
-
export const STALE_TIMEOUT_MS = 5 * 60_000;
|
|
11
|
-
export const SWEEP_INTERVAL_MS = 60_000;
|
|
12
|
-
// Per-batch byte budget. We pack spans into a request until adding the next
|
|
13
|
-
// one would push us over this, then flush. Sized to fit comfortably under the
|
|
14
|
-
// ingest server's 10MB Fastify bodyLimit (set in senpi-agent-telemetry).
|
|
15
|
-
export const MAX_BATCH_BYTES = 8_000_000;
|
|
16
|
-
// Per-field byte cap for span.data top-level values. Acts as a safety net for
|
|
17
|
-
// genuinely pathological outputs (e.g. an `exec` that printed a multi-MB log,
|
|
18
|
-
// or a tool that returned a raw binary blob). Real chat-history payloads flow
|
|
19
|
-
// through unchanged after sanitize-payload strips framework metadata.
|
|
20
|
-
// Combined with the ingest server's 10MB body limit, only truly oversized
|
|
21
|
-
// fields trip this.
|
|
22
|
-
export const MAX_SPAN_FIELD_BYTES = 2_000_000;
|
|
23
|
-
/** First N chars of each truncated value retained for debugging context. */
|
|
24
|
-
export const TRUNCATED_PREVIEW_BYTES = 2_000;
|
|
25
|
-
// Header names used to cross the runtime → OpenClaw HTTP boundary.
|
|
26
7
|
export const HEADER_CORRELATION_ID = "x-senpi-correlation-id";
|
|
27
8
|
export const HEADER_ADDRESS = "x-senpi-address";
|
|
28
9
|
export const HEADER_RECIPE_NAME = "x-senpi-recipe-name";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/tracking/spans/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/tracking/spans/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gen_ai / MCP span mapping — the one place that turns extracted hook content (or on-site
|
|
3
|
+
* MCP call data) into OpenTelemetry GenAI/MCP semantic-convention span attributes (the
|
|
4
|
+
* `GEN_AI` keys below). Standard keys only — no OpenClaw `openclaw.content.*` mirror, no
|
|
5
|
+
* OpenInference `input.value`/`output.value` aliases; `gen_ai.system_instructions` is the
|
|
6
|
+
* spec's underscore form.
|
|
7
|
+
*
|
|
8
|
+
* Content (messages, system instructions, tool args/result) is the highest-PII surface, so
|
|
9
|
+
* it is always redacted *before* stamping and capped *after* (sanitize → redact → cap) so a
|
|
10
|
+
* truncated value can't re-expose a partial secret. If the redactor fails to load, content is
|
|
11
|
+
* dropped rather than emitted unredacted.
|
|
12
|
+
*/
|
|
13
|
+
import type { Attributes, Span } from "@opentelemetry/api";
|
|
14
|
+
/**
|
|
15
|
+
* Max chars per content attribute value, applied after redaction. A transport-safety
|
|
16
|
+
* cap that sits far under the OTLP/HTTP request-body limit (~20 MiB), not a backend
|
|
17
|
+
* storage limit — content this size is rare and we'd rather truncate than risk a
|
|
18
|
+
* rejected export.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MAX_OTEL_CONTENT_ATTRIBUTE_CHARS: number;
|
|
21
|
+
/** Max items per message / tool-definition array, applied after redaction. */
|
|
22
|
+
export declare const MAX_OTEL_CONTENT_ARRAY_ITEMS = 200;
|
|
23
|
+
export declare const GEN_AI: {
|
|
24
|
+
readonly OPERATION_NAME: "gen_ai.operation.name";
|
|
25
|
+
readonly PROVIDER_NAME: "gen_ai.provider.name";
|
|
26
|
+
readonly REQUEST_MODEL: "gen_ai.request.model";
|
|
27
|
+
readonly REQUEST_TEMPERATURE: "gen_ai.request.temperature";
|
|
28
|
+
readonly REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens";
|
|
29
|
+
readonly RESPONSE_MODEL: "gen_ai.response.model";
|
|
30
|
+
readonly RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons";
|
|
31
|
+
readonly USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens";
|
|
32
|
+
readonly USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
|
|
33
|
+
readonly SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions";
|
|
34
|
+
readonly INPUT_MESSAGES: "gen_ai.input.messages";
|
|
35
|
+
readonly OUTPUT_MESSAGES: "gen_ai.output.messages";
|
|
36
|
+
readonly TOOL_DEFINITIONS: "gen_ai.tool.definitions";
|
|
37
|
+
readonly AGENT_NAME: "gen_ai.agent.name";
|
|
38
|
+
readonly TOOL_NAME: "gen_ai.tool.name";
|
|
39
|
+
readonly TOOL_CALL_ID: "gen_ai.tool.call.id";
|
|
40
|
+
readonly TOOL_CALL_ARGUMENTS: "gen_ai.tool.call.arguments";
|
|
41
|
+
readonly TOOL_CALL_RESULT: "gen_ai.tool.call.result";
|
|
42
|
+
};
|
|
43
|
+
/** Reset the cached redactor (tests only). */
|
|
44
|
+
export declare function __resetContentRedactorForTest(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Turn a content value into a capped JSON string with PII redacted: sanitize framework
|
|
47
|
+
* metadata, redact (when a redactor is available), then serialize within the caps.
|
|
48
|
+
* Array content keeps the newest items (dropping oldest with a visible elision marker,
|
|
49
|
+
* so the result stays valid JSON); non-array content is tail-truncated with a suffix.
|
|
50
|
+
* Returns `undefined` when the value is empty. Never throws — a failure drops the value.
|
|
51
|
+
*/
|
|
52
|
+
export declare function redactAndCapContent(value: unknown): Promise<string | undefined>;
|
|
53
|
+
/** Redact + cap a content value and stamp it onto the span (when capture is on and non-empty). */
|
|
54
|
+
export declare function setGenAiContentAttribute(span: Span, key: string, value: unknown): Promise<void>;
|
|
55
|
+
/** Set every defined value in `attrs` on the span, skipping undefined/null. Never throws. */
|
|
56
|
+
export declare function setDefinedAttributes(span: Span, attrs: Attributes): void;
|
|
57
|
+
/** Low-cardinality `error.type` for the spec: error.name, the string itself, else "_OTHER". */
|
|
58
|
+
export declare function errorTypeOf(error: unknown): string;
|
|
59
|
+
/**
|
|
60
|
+
* Mark a span as failed: record the exception, set ERROR status, and stamp the spec's
|
|
61
|
+
* low-cardinality `error.type`. Never throws.
|
|
62
|
+
*/
|
|
63
|
+
export declare function recordSpanError(span: Span, error: unknown): void;
|
|
64
|
+
/** First finite number among the candidates, else undefined. */
|
|
65
|
+
export declare function firstNumber(...values: unknown[]): number | undefined;
|
|
66
|
+
/** Normalize a finish-reason value to a string array (gen_ai.response.finish_reasons is an array). */
|
|
67
|
+
export declare function toFinishReasons(value: unknown): string[] | undefined;
|
|
68
|
+
/** Normalize a list of raw provider messages into spec `{ role, parts }` objects. */
|
|
69
|
+
export declare function normalizeGenAiMessages(value: unknown, fallbackRole: "user" | "assistant"): Array<Record<string, unknown>> | undefined;
|
|
70
|
+
//# sourceMappingURL=gen-ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen-ai.d.ts","sourceRoot":"","sources":["../../../src/tracking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