11/**
2- * Settings/env surface for opt-in OTEL export. Resolves whether an OTLP
3- * exporter may be enabled — no SDK, no network; PerfTrace stays independent.
4- * Fail closed: invalid endpoint/headers/attrs yield a stable error, never a
5- * half-enabled export. Secrets never enter privacy-strict dumps.
2+ * Settings/env surface for opt-in OTEL export — no SDK, no network;
3+ * PerfTrace stays independent. Fail closed: invalid endpoint/headers/attrs
4+ * yield a stable error, never a half-enabled export. Secrets never enter
5+ * privacy-strict dumps.
66 */
77
88import type { Settings } from "../config/settings.js" ;
@@ -23,13 +23,14 @@ export const OTEL_ENV = {
2323
2424/** Non-secret settings block for OTEL export (global settings only). */
2525export interface OtelSettings {
26- /** Explicit off switch. When false and no env endpoint, export stays disabled. */
26+ /** Explicit off switch. When false and no env endpoint, export stays
27+ * disabled. */
2728 enabled ?: boolean ;
2829 /** OTLP base URL (http/https). Env OTEL_EXPORTER_OTLP_ENDPOINT overrides. */
2930 endpoint ?: string ;
3031 /**
3132 * Extra OTLP headers (auth). Prefer the env var so secrets stay out of
32- * settings files; env fully replaces settings headers when set .
33+ * settings files.
3334 */
3435 headers ?: Record < string , string > ;
3536 /** Resource service.name. Env OTEL_SERVICE_NAME overrides. */
@@ -57,8 +58,8 @@ export type OtelExportConfig =
5758 | DisabledOtelExportConfig ;
5859
5960/**
60- * Dump-safe view: never includes header values or other secrets.
61- * Local privacy-strict dumps must only ever receive this shape.
61+ * Dump-safe view: no header values or other secrets. Privacy-strict
62+ * dumps must only ever receive this shape.
6263 */
6364export type OtelExportConfigDumpView =
6465 | { enabled : false }
@@ -94,8 +95,8 @@ function isNonEmptyString(value: unknown): value is string {
9495}
9596
9697/**
97- * Parse OTEL W3C-style `key=value,key2=value2` lists (headers / resource attrs).
98- * Values may be percent-encoded. Empty keys or malformed pairs fail closed.
98+ * Parse W3C-style `key=value,key2=value2` lists (headers / resource attrs).
99+ * Values may be percent-encoded; empty keys or malformed pairs fail closed.
99100 */
100101export function parseOtelKeyValueList (
101102 raw : string ,
@@ -178,7 +179,7 @@ function validateEndpoint(
178179 } ;
179180 }
180181
181- // Normalize: drop trailing slash so exporters can append /v1/traces consistently.
182+ // Drop trailing slash so exporters append /v1/traces consistently.
182183 const normalized = endpoint . replace ( / \/ + $ / , "" ) ;
183184 return { ok : true , endpoint : normalized } ;
184185}
@@ -207,16 +208,14 @@ function validateStringMap(
207208}
208209
209210/**
210- * Resolve OTEL export config from global settings + process env.
211- *
212- * Precedence:
211+ * Precedence (env over settings):
213212 * - endpoint: env > settings
214213 * - headers: env list fully replaces settings when set; else settings
215214 * - serviceName: env > settings.serviceName > attrs["service.name"] > default
216215 * - resourceAttributes: settings then env (env wins on conflict); after merge,
217- * attrs["service.name"] is always synced to the resolved serviceName
216+ * attrs["service.name"] is synced to the resolved serviceName
218217 *
219- * No endpoint → disabled (ok). Invalid or malformed config → not ok.
218+ * No endpoint → disabled (ok); invalid or malformed → not ok.
220219 */
221220export function resolveOtelExportConfig (
222221 settings ?: Settings | null ,
@@ -234,7 +233,7 @@ export function resolveOtelExportConfig(
234233 const endpointRaw =
235234 envEndpointRaw . length > 0 ? envEndpointRaw : settingsEndpoint ;
236235
237- // settings.otel.enabled === false forces off unless env explicitly sets an endpoint.
236+ // settings.otel.enabled === false forces off unless env sets an endpoint.
238237 if ( otel ?. enabled === false && envEndpointRaw . length === 0 ) {
239238 return { ok : true , config : { enabled : false } } ;
240239 }
@@ -319,8 +318,7 @@ export function resolveOtelExportConfig(
319318 resourceAttributes = { ...resourceAttributes , ...parsed . value } ;
320319 }
321320
322- // serviceName: env > settings > attrs["service.name"] > default; then sync
323- // attrs["service.name"] to it so the two never diverge.
321+ // Sync attrs["service.name"] to the resolved name so the two never diverge.
324322 const attrServiceName = trimOrEmpty ( resourceAttributes [ "service.name" ] ) ;
325323 const serviceName =
326324 envServiceNameRaw . length > 0
@@ -354,8 +352,8 @@ export function resolveOtelExportConfig(
354352}
355353
356354/**
357- * Resolve or throw. Callers that treat invalid config as a hard startup error
358- * use this; soft paths should call resolveOtelExportConfig and branch on ok.
355+ * Hard-startup callers use this; soft paths call resolveOtelExportConfig
356+ * and branch on ok.
359357 */
360358export function requireOtelExportConfig (
361359 settings ?: Settings | null ,
@@ -386,8 +384,7 @@ export function redactResourceAttributesForDump(
386384}
387385
388386/**
389- * Dump-safe view of an export config: header values stripped. Use this,
390- * never raw headers.
387+ * Header values stripped. Use this, never raw headers.
391388 */
392389export function otelConfigForDump (
393390 config : OtelExportConfig ,
0 commit comments