Skip to content

Commit 6516d83

Browse files
Kiran Magicbek91
authored andcommitted
fix(config): reject unsupported diagnostics otel grpc
1 parent 05dc73b commit 6516d83

26 files changed

Lines changed: 803 additions & 44 deletions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
16942839f6254e337308a87e434c295edb1b0b499f796c4dd0b27a7c596c1751 config-baseline.json
2-
aa1b3a3733b7129728c66d138fa2e8e691b14ba7afe43d78fc134549fcac5b45 config-baseline.core.json
3-
e9a81ee89ff032033012413e161316e4d07e8f6b206382a25fed2f8485151b5e config-baseline.channel.json
1+
1315dd0d8e904da70f5e26f6f055e493c1ddbc4b2ca0ad02bc8608f694e0d89f config-baseline.json
2+
a99b96985ee0409f06f356e538eb3a68c0d0e2c7862a242e00ee919681582165 config-baseline.core.json
3+
292a907b48f9fd7273f12947c8001077ab69978d29985cb287a71a33e837339a config-baseline.channel.json
44
5d5fe4c95346cb1e7555395d40a6244967e6595b30f13912ae7754209944b734 config-baseline.plugin.json

‎docs/gateway/configuration-reference.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ writer is best-effort, not a lossless compliance archive.
12991299
tracesEndpoint: "https://traces.example.com/v1/traces",
13001300
metricsEndpoint: "https://metrics.example.com/v1/metrics",
13011301
logsEndpoint: "https://logs.example.com/v1/logs",
1302-
protocol: "http/protobuf", // http/protobuf | grpc
1302+
protocol: "http/protobuf",
13031303
headers: { "x-tenant-id": "my-org" },
13041304
serviceName: "openclaw-gateway",
13051305
traces: true,
@@ -1323,8 +1323,8 @@ writer is best-effort, not a lossless compliance archive.
13231323
- `otel.enabled`: enables the OpenTelemetry export pipeline (default: `false`). For the full configuration, signal catalog, and privacy model, see [OpenTelemetry export](/gateway/opentelemetry).
13241324
- `otel.endpoint`: collector URL for OTel export.
13251325
- `otel.tracesEndpoint` / `otel.metricsEndpoint` / `otel.logsEndpoint`: optional signal-specific OTLP endpoints. When set, they override `otel.endpoint` for that signal only.
1326-
- `otel.protocol`: `"http/protobuf"` (default) or `"grpc"`.
1327-
- `otel.headers`: extra HTTP/gRPC metadata headers sent with OTel export requests.
1326+
- `otel.protocol`: `"http/protobuf"` (default). gRPC export is retired; run [`openclaw doctor --fix`](/cli/doctor) to repair a persisted legacy value or get source-specific manual-edit guidance.
1327+
- `otel.headers`: extra HTTP request headers sent with OTel export requests.
13281328
- `otel.serviceName`: service name for resource attributes.
13291329
- `otel.traces` / `otel.metrics` / `otel.logs`: enable trace, metrics, or log export.
13301330
- `otel.logsExporter`: log export sink: `"otlp"` (default), `"stdout"` for one JSON object per stdout line, or `"both"`.
@@ -1334,6 +1334,7 @@ writer is best-effort, not a lossless compliance archive.
13341334
- `OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental`: environment toggle for latest experimental GenAI inference span shape, including `{gen_ai.operation.name} {gen_ai.request.model}` span names, `CLIENT` span kind, and `gen_ai.provider.name` instead of legacy `gen_ai.system`. By default spans keep `openclaw.model.call` and `gen_ai.system` for compatibility; GenAI metrics use bounded semantic attributes.
13351335
- `OPENCLAW_OTEL_PRELOADED=1`: environment toggle for hosts that already registered a global OpenTelemetry SDK. OpenClaw then skips plugin-owned SDK startup/shutdown while keeping diagnostic listeners active.
13361336
- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`: signal-specific endpoint env vars used when the matching config key is unset.
1337+
- `OTEL_EXPORTER_OTLP_PROTOCOL`: protocol fallback used only when `otel.protocol` is unset. Set it to `http/protobuf` or leave it unset; unsupported values are rejected when an OTLP signal is enabled and are not rewritten by Doctor.
13371338
- `cacheTrace.enabled`: log cache trace snapshots for embedded runs (default: `false`).
13381339

13391340
---

‎docs/gateway/opentelemetry.md‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ openclaw plugins install clawhub:@openclaw/diagnostics-otel
5959
Or enable the plugin from the CLI: `openclaw plugins enable diagnostics-otel`.
6060

6161
<Note>
62-
`protocol` supports `http/protobuf` only. Since `traces` and `metrics` default to enabled, any other value (including `grpc`) aborts the entire diagnostics-otel subscription with an `unsupported protocol` warning - this also stops stdout log export. Explicitly set `traces: false` and `metrics: false` if you only want `logsExporter: "stdout"` with a non-OTLP protocol value.
62+
`diagnostics.otel.protocol` accepts only `http/protobuf`. If a persisted config,
63+
including a value supplied through `${VAR}` interpolation, still resolves this
64+
field to the retired `grpc` value, run
65+
[`openclaw doctor --fix`](/cli/doctor). Doctor repairs directly authored values
66+
and a sole internal single-file include that owns the top-level `diagnostics`
67+
section. For root or array includes, nested include chains, sibling overrides,
68+
external include targets, or another ambiguous source, Doctor leaves the files
69+
unchanged and lists the candidate source file or files to edit manually.
70+
71+
`OTEL_EXPORTER_OTLP_PROTOCOL` is a process-environment fallback used only when
72+
`diagnostics.otel.protocol` is unset. Doctor does not rewrite process
73+
environment variables. An unsupported fallback is rejected at runtime when an
74+
OTLP signal is enabled; set it to `http/protobuf` or unset it. A stdout-only log
75+
configuration does not use the OTLP transport and continues to work.
6376
</Note>
6477

6578
## Signals exported
@@ -109,7 +122,7 @@ stdout, or `both` for both.
109122
tracesEndpoint: "http://otel-collector:4318/v1/traces",
110123
metricsEndpoint: "http://otel-collector:4318/v1/metrics",
111124
logsEndpoint: "http://otel-collector:4318/v1/logs",
112-
protocol: "http/protobuf", // grpc disables OTLP export
125+
protocol: "http/protobuf",
113126
serviceName: "openclaw-gateway", // unset falls back to OTEL_SERVICE_NAME, then "openclaw"
114127
metricNamePrefix: "acme.", // optional; include the separator
115128
headers: { "x-collector-token": "..." },
@@ -144,7 +157,7 @@ dashboards, alerts, and recording rules that query the old names.
144157
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Fallback for `diagnostics.otel.endpoint` when the config key is unset. |
145158
| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` / `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` / `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Signal-specific endpoint fallbacks used when the matching `diagnostics.otel.*Endpoint` config key is unset. Signal-specific config wins over signal-specific env, which wins over the shared endpoint. |
146159
| `OTEL_SERVICE_NAME` | Fallback for `diagnostics.otel.serviceName` when the config key is unset. Default service name is `openclaw`. |
147-
| `OTEL_EXPORTER_OTLP_PROTOCOL` | Fallback for the wire protocol when `diagnostics.otel.protocol` is unset. Only `http/protobuf` enables export. |
160+
| `OTEL_EXPORTER_OTLP_PROTOCOL` | Process-environment fallback used only when `diagnostics.otel.protocol` is unset. Only `http/protobuf` enables OTLP export; unsupported values are rejected when an OTLP signal is enabled and are not rewritten by Doctor. |
148161
| `OTEL_SEMCONV_STABILITY_OPT_IN` | Set to `gen_ai_latest_experimental` to emit the latest GenAI inference span shape: `{gen_ai.operation.name} {gen_ai.request.model}` span names, `CLIENT` span kind, and `gen_ai.provider.name` instead of the legacy `gen_ai.system`. GenAI metrics always use bounded, low-cardinality attributes regardless. |
149162
| `OPENCLAW_OTEL_PRELOADED` | Set to `1` when another preload or host process already registered the global OpenTelemetry SDK. The plugin then skips its own NodeSDK lifecycle but still wires diagnostic listeners and honors `traces`/`metrics`/`logs`. |
150163

‎extensions/diagnostics-otel/src/service.test.ts‎

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ import {
195195
logMessageProcessed,
196196
runWithDiagnosticTraceContext,
197197
} from "openclaw/plugin-sdk/plugin-test-runtime";
198-
import { emitDiagnosticEvent } from "../api.js";
198+
import { emitDiagnosticEvent, type DiagnosticEventPayload } from "../api.js";
199199
import { MAX_RETAINED_TRUSTED_SPAN_CONTEXTS } from "./service-constants.js";
200200
import { createDiagnosticsOtelService } from "./service.js";
201201
import {
@@ -224,6 +224,7 @@ function numberedSpanId(index: number) {
224224
const LATE_CHILD_ELAPSED_MS = 30 * 60_000 + 1_000;
225225
const PROTO_KEY = "__proto__";
226226
const MAX_TEST_OTEL_CONTENT_ATTRIBUTE_CHARS = 128 * 1024;
227+
type TelemetryExporterEvent = Extract<DiagnosticEventPayload, { type: "telemetry.exporter" }>;
227228
const OTEL_TRUNCATED_SUFFIX_MAX_CHARS = 20;
228229
const OTEL_TEST_USERINFO = ["operator", "example-fixture"].join(":");
229230
const ORIGINAL_OPENCLAW_OTEL_PRELOADED = process.env.OPENCLAW_OTEL_PRELOADED;
@@ -1108,7 +1109,7 @@ describe("diagnostics-otel service", () => {
11081109
});
11091110

11101111
test("emits and records bounded telemetry exporter health events", async () => {
1111-
const events: Array<Parameters<Parameters<typeof onInternalDiagnosticEvent>[0]>[0]> = [];
1112+
const events: TelemetryExporterEvent[] = [];
11121113
const unsubscribe = onInternalDiagnosticEvent((event) => {
11131114
if (event.type === "telemetry.exporter") {
11141115
events.push(event);
@@ -1236,13 +1237,87 @@ describe("diagnostics-otel service", () => {
12361237
expect(logEmit).not.toHaveBeenCalled();
12371238
});
12381239

1239-
test("starts stdout-only logs when OTLP protocol is unsupported", async () => {
1240+
test("keeps explicit HTTP exporters canonical when ambient protocol is gRPC", async () => {
1241+
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = "grpc";
1242+
const { ctx } = await startOtelService({
1243+
protocol: "http/protobuf",
1244+
traces: true,
1245+
metrics: true,
1246+
logs: true,
1247+
});
1248+
1249+
expect(sdkCtor).toHaveBeenCalledTimes(1);
1250+
expect(mockCallArg(sdkCtor, 0)).toMatchObject({ logRecordProcessors: [] });
1251+
expect(traceExporterCtor).toHaveBeenCalledTimes(1);
1252+
expect(metricExporterCtor).toHaveBeenCalledTimes(1);
1253+
expect(logExporterCtor).toHaveBeenCalledTimes(1);
1254+
expect(firstExporterOptions(traceExporterCtor).url).toBe(
1255+
"http://otel-collector:4318/v1/traces",
1256+
);
1257+
expect(firstExporterOptions(metricExporterCtor).url).toBe(
1258+
"http://otel-collector:4318/v1/metrics",
1259+
);
1260+
expect(firstExporterOptions(logExporterCtor).url).toBe("http://otel-collector:4318/v1/logs");
1261+
expect(sdkStart).toHaveBeenCalledTimes(1);
1262+
expect(ctx.logger.warn).not.toHaveBeenCalledWith("diagnostics-otel: unsupported protocol grpc");
1263+
1264+
emitDiagnosticEvent({
1265+
type: "log.record",
1266+
level: "INFO",
1267+
message: "OpenClaw-owned OTLP log",
1268+
});
1269+
await flushDiagnosticEvents();
1270+
1271+
expect(logEmit).toHaveBeenCalledTimes(1);
1272+
});
1273+
1274+
test("rejects unsupported protocol env override before exporter startup", async () => {
1275+
const events: TelemetryExporterEvent[] = [];
1276+
const unsubscribe = onInternalDiagnosticEvent((event) => {
1277+
if (event.type === "telemetry.exporter") {
1278+
events.push(event);
1279+
}
1280+
});
1281+
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = "grpc";
1282+
const { ctx } = await startOtelService({
1283+
traces: true,
1284+
metrics: true,
1285+
logs: true,
1286+
configure: (context) => {
1287+
delete context.config.diagnostics?.otel?.protocol;
1288+
},
1289+
});
1290+
1291+
expect(
1292+
events.map((event) => ({
1293+
signal: event.signal,
1294+
status: event.status,
1295+
reason: event.reason,
1296+
})),
1297+
).toEqual([
1298+
{ signal: "traces", status: "failure", reason: "unsupported_protocol" },
1299+
{ signal: "metrics", status: "failure", reason: "unsupported_protocol" },
1300+
{ signal: "logs", status: "failure", reason: "unsupported_protocol" },
1301+
]);
1302+
expect(ctx.logger.warn).toHaveBeenCalledWith("diagnostics-otel: unsupported protocol grpc");
1303+
expect(traceExporterCtor).not.toHaveBeenCalled();
1304+
expect(metricExporterCtor).not.toHaveBeenCalled();
1305+
expect(logExporterCtor).not.toHaveBeenCalled();
1306+
expect(sdkStart).not.toHaveBeenCalled();
1307+
1308+
unsubscribe();
1309+
});
1310+
1311+
test("starts stdout-only logs when OTLP protocol env override is unsupported", async () => {
1312+
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = "grpc";
12401313
const { ctx } = await startOtelService({
12411314
traces: false,
12421315
metrics: false,
12431316
logs: true,
1244-
protocol: "grpc",
12451317
logsExporter: "stdout",
1318+
configure: (context) => {
1319+
delete context.config.diagnostics?.otel?.protocol;
1320+
},
12461321
});
12471322
const capture = captureStdoutWrites();
12481323
try {
@@ -1423,7 +1498,7 @@ describe("diagnostics-otel service", () => {
14231498
});
14241499

14251500
test("reports log exporter emit failures without exporting raw error text", async () => {
1426-
const events: Array<Parameters<Parameters<typeof onInternalDiagnosticEvent>[0]>[0]> = [];
1501+
const events: TelemetryExporterEvent[] = [];
14271502
const unsubscribe = onInternalDiagnosticEvent((event) => {
14281503
if (event.type === "telemetry.exporter") {
14291504
events.push(event);
@@ -1839,6 +1914,7 @@ describe("diagnostics-otel service", () => {
18391914
] as const)(
18401915
"keeps NodeSDK exporter ownership explicit for $enabledSignal",
18411916
async ({ flags, metricReaderCount, tracesDisabled }) => {
1917+
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = "grpc";
18421918
await startOtelService(flags);
18431919

18441920
const options = mockCallArg(sdkCtor, 0) as {

‎extensions/diagnostics-otel/src/service.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ export function createDiagnosticsOtelService(): OpenClawPluginService {
231231

232232
sdk = new NodeSDK({
233233
resource,
234+
// Explicit empty arrays keep NodeSDK from restoring disabled exporters
235+
// from ambient OTEL_* settings; OpenClaw owns every signal exporter.
234236
...(spanProcessors
235237
? { spanProcessors }
236238
: traceExporter

‎src/commands/doctor-config-flow.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export async function loadAndMaybeMigrateDoctorConfig(params: {
197197
});
198198
state = legacyStep.state;
199199
const legacyMigrationPartiallyValid = legacyStep.partiallyValid === true;
200+
const legacyMigrationBlocksWrite = legacyStep.blocksWrite === true;
200201
const rosterMigrationNeeded = [snapshot.sourceConfigBeforeMigrations, snapshot.parsed].some(
201202
(source) => source !== undefined && migratePersistedImplicitMainRoster(source).changed,
202203
);
@@ -474,8 +475,9 @@ export async function loadAndMaybeMigrateDoctorConfig(params: {
474475
note,
475476
});
476477
const cfg = finalized.cfg;
478+
const shouldWriteConfig = finalized.shouldWriteConfig && !legacyMigrationBlocksWrite;
477479
const singleTopLevelIncludeWrite =
478-
finalized.shouldWriteConfig &&
480+
shouldWriteConfig &&
479481
isSingleTopLevelIncludeMigration({
480482
parsed: snapshot.parsed,
481483
sourceConfig: snapshot.sourceConfig,
@@ -505,11 +507,11 @@ export async function loadAndMaybeMigrateDoctorConfig(params: {
505507
return {
506508
cfg,
507509
path: snapshot.path ?? CONFIG_PATH,
508-
shouldWriteConfig: finalized.shouldWriteConfig,
510+
shouldWriteConfig,
509511
sourceConfigValid: snapshot.valid,
510512
...(sourceLastTouchedVersion ? { sourceLastTouchedVersion } : {}),
511513
...(legacyMigrationPartiallyValid ? { skipPluginValidationOnWrite: true } : {}),
512-
...(finalized.shouldWriteConfig && explicitSetPaths.length > 0 ? { explicitSetPaths } : {}),
514+
...(shouldWriteConfig && explicitSetPaths.length > 0 ? { explicitSetPaths } : {}),
513515
...(singleTopLevelIncludeWrite ? { skipWizardMetadataForIncludeWrite: true } : {}),
514516
...(shouldRepairCronCodexModelRefsAfterConfigWrite
515517
? { shouldRepairCronCodexModelRefsAfterConfigWrite: true }

‎src/commands/doctor-config-preflight.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,59 @@ describe("runDoctorConfigPreflight", () => {
180180
});
181181
});
182182

183+
it("reports persisted literal and interpolated OTel grpc as legacy config", async () => {
184+
await withTempHome(async (home) => {
185+
await writeOpenClawConfig(home, {
186+
diagnostics: { otel: { enabled: false, protocol: "grpc" } },
187+
});
188+
189+
const literal = await runDoctorConfigPreflight({
190+
migrateState: false,
191+
migrateLegacyConfig: false,
192+
invalidConfigNote: false,
193+
});
194+
expect(literal.snapshot.legacyIssues).toContainEqual(
195+
expect.objectContaining({ path: "diagnostics.otel.protocol" }),
196+
);
197+
198+
const configPath = literal.snapshot.path;
199+
await fs.writeFile(
200+
configPath,
201+
'{ diagnostics: { otel: { enabled: false, protocol: "${OTEL_PROTOCOL}" } } }\n',
202+
"utf-8",
203+
);
204+
await withEnvOverride({ OTEL_PROTOCOL: "grpc" }, async () => {
205+
const interpolated = await runDoctorConfigPreflight({
206+
migrateState: false,
207+
migrateLegacyConfig: false,
208+
invalidConfigNote: false,
209+
});
210+
expect(interpolated.snapshot.legacyIssues).toContainEqual(
211+
expect.objectContaining({ path: "diagnostics.otel.protocol" }),
212+
);
213+
});
214+
});
215+
});
216+
217+
it("does not treat the process-only OTel protocol fallback as persisted config", async () => {
218+
await withTempHome(async (home) => {
219+
await writeOpenClawConfig(home, {
220+
diagnostics: { otel: { enabled: false } },
221+
});
222+
223+
await withEnvOverride({ OTEL_EXPORTER_OTLP_PROTOCOL: "grpc" }, async () => {
224+
const preflight = await runDoctorConfigPreflight({
225+
migrateState: false,
226+
migrateLegacyConfig: false,
227+
invalidConfigNote: false,
228+
});
229+
expect(preflight.snapshot.legacyIssues).not.toContainEqual(
230+
expect.objectContaining({ path: "diagnostics.otel.protocol" }),
231+
);
232+
});
233+
});
234+
});
235+
183236
it("restores invalid config from last-known-good only during repair preflight", async () => {
184237
await withTempHome(async (home) => {
185238
const configPath = await writeOpenClawConfig(home, {

0 commit comments

Comments
 (0)