From 458cdc1656644266b36b46311c83675163ca1c27 Mon Sep 17 00:00:00 2001 From: igoramf Date: Thu, 2 Jul 2026 13:24:04 -0300 Subject: [PATCH] feat(sdk): enable OTEL error promotion at 100% by default Flip DECO_OTEL_ERROR_PROMOTION default to true and DECO_OTEL_ERROR_PROMOTION_RATE default to 1 so error traces always ship to ClickHouse without callers having to opt in. Set DECO_OTEL_ERROR_PROMOTION=false to opt out. Co-Authored-By: Claude Opus 4.7 --- src/sdk/otel.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/sdk/otel.ts b/src/sdk/otel.ts index c3e0e814..00cd3634 100644 --- a/src/sdk/otel.ts +++ b/src/sdk/otel.ts @@ -219,29 +219,29 @@ export interface OtelOptions { */ otlpTracesSamplingRateEnvVar?: string; /** - * When `true` (or when `DECO_OTEL_ERROR_PROMOTION=true` is set), any - * `logger.error()` call with an active trace context marks that trace for - * export even if head sampling did not select it. Useful for ensuring + * When `true` (default) or when `DECO_OTEL_ERROR_PROMOTION=true` is set, + * any `logger.error()` call with an active trace context marks that trace + * for export even if head sampling did not select it. Useful for ensuring * errors always have a trace in ClickHouse without raising the global * sampling rate. * - * Disabled by default — enable via env var or this option once validated - * in production. Precedence: env var (`otlpTracesErrorPromotionEnvVar`, - * default `DECO_OTEL_ERROR_PROMOTION`) > this option > `false`. + * Enabled by default — set `DECO_OTEL_ERROR_PROMOTION=false` to opt out. + * Precedence: env var (`otlpTracesErrorPromotionEnvVar`, default + * `DECO_OTEL_ERROR_PROMOTION`) > this option > `true`. */ otlpTracesErrorPromotion?: boolean; /** * Env var name to read the error promotion flag from. Defaults to - * `"DECO_OTEL_ERROR_PROMOTION"`. Value must be `"true"` to enable. + * `"DECO_OTEL_ERROR_PROMOTION"`. Value must be `"true"` or `"false"`. */ otlpTracesErrorPromotionEnvVar?: string; /** - * Sampling rate applied to error-promoted traces, 0.0..1.0. Default `0.1` - * (promote 10% of error traces). Lower values cap ClickHouse volume when + * Sampling rate applied to error-promoted traces, 0.0..1.0. Default `1` + * (promote 100% of error traces). Lower values cap ClickHouse volume when * errors are frequent. Uses the same FNV-1a hash as head sampling. * * Precedence: env var (`otlpTracesErrorPromotionRateEnvVar`, default - * `DECO_OTEL_ERROR_PROMOTION_RATE`) > this option > `0.1`. + * `DECO_OTEL_ERROR_PROMOTION_RATE`) > this option > `1`. */ otlpTracesErrorPromotionRate?: number; /** @@ -733,9 +733,12 @@ function bootObservability(opts: OtelOptions, env: Record): voi const errorPromotionEnvVar = opts.otlpTracesErrorPromotionEnvVar ?? "DECO_OTEL_ERROR_PROMOTION"; + const errorPromotionEnvValue = env[errorPromotionEnvVar] as string | undefined; const errorPromotionEnabled = - (env[errorPromotionEnvVar] as string | undefined) === "true" || - (opts.otlpTracesErrorPromotion ?? false); + errorPromotionEnvValue === "false" + ? false + : errorPromotionEnvValue === "true" || + (opts.otlpTracesErrorPromotion ?? true); if (otlpLogsEnabled) { state.otlpLog = createOtlpHttpLogAdapter({ @@ -874,7 +877,7 @@ function bootObservability(opts: OtelOptions, env: Record): voi errorPromotionRateFromEnv >= 0 && errorPromotionRateFromEnv <= 1 ? errorPromotionRateFromEnv - : (opts.otlpTracesErrorPromotionRate ?? 0.1); + : (opts.otlpTracesErrorPromotionRate ?? 1); state.otlpTracer = createOtlpHttpTracerAdapter({ endpoint: otlpTracesEndpoint,