{"record":{"id":"fc615971faaea356","repo":"denoland/deno","slug":"failed-to-read-env-var-otel-exporter-otlp-protocol","errorCode":null,"errorMessage":"Failed to read env var OTEL_EXPORTER_OTLP_PROTOCOL: {}","messagePattern":"Failed to read env var OTEL_EXPORTER_OTLP_PROTOCOL: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ext/telemetry/lib.rs","lineNumber":1260,"sourceCode":"  // `protocol` value is only ever the HTTP variant passed to the OTLP HTTP\n  // exporter builder.\n  let protocol_var = sys.env_var(\"OTEL_EXPORTER_OTLP_PROTOCOL\");\n  let (use_console_exporter, use_grpc, protocol) = match protocol_var.as_deref()\n  {\n    Ok(\"console\") => (true, false, Protocol::HttpBinary),\n    Ok(\"http/protobuf\") | Ok(\"\") | Err(std::env::VarError::NotPresent) => {\n      (false, false, Protocol::HttpBinary)\n    }\n    Ok(\"http/json\") => (false, false, Protocol::HttpJson),\n    Ok(\"grpc\") => (false, true, Protocol::HttpBinary),\n    Ok(protocol) => {\n      return Err(deno_core::anyhow::anyhow!(\n        \"Env var OTEL_EXPORTER_OTLP_PROTOCOL specifies an unsupported protocol: {}\",\n        protocol\n      ));\n    }\n    Err(err) => {\n      return Err(deno_core::anyhow::anyhow!(\n        \"Failed to read env var OTEL_EXPORTER_OTLP_PROTOCOL: {}\",\n        err\n      ));\n    }\n  };\n\n  // Define the resource attributes that will be attached to all log records.\n  // These attributes are sourced as follows (in order of precedence):\n  //   * The `service.name` attribute from the `OTEL_SERVICE_NAME` env var.\n  //   * Additional attributes from the `OTEL_RESOURCE_ATTRIBUTES` env var.\n  //   * Default attribute values defined here.\n  // TODO(piscisaureus): add more default attributes (e.g. script path).\n  // The base resource picks up `service.name`, the `telemetry.sdk.*`\n  // attributes and any `OTEL_RESOURCE_ATTRIBUTES`/`OTEL_SERVICE_NAME` values.\n  let base_resource = Resource::builder().build();\n  let sdk_language = base_resource\n    .get(&Key::new(TELEMETRY_SDK_LANGUAGE))\n    .unwrap();","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/telemetry/lib.rs#L1242-L1278","documentation":"Startup reads OTEL_EXPORTER_OTLP_PROTOCOL through std::env::var; only VarError::NotPresent is treated as unset (defaulting to http/protobuf). Any other VarError — in practice NotUnicode, a value with invalid UTF-8 bytes — produces this message together with the underlying error text.","triggerScenarios":"The process environment contains OTEL_EXPORTER_OTLP_PROTOCOL with non-UTF-8 bytes: written by a buggy script, a mis-encoded CI secret, or an exec call passing raw byte environments.","commonSituations":"CI secret stores that saved the value with a BOM or binary encoding; container images built with broken locale handling; wrapper processes forwarding env bytes unvalidated.","solutions":["Re-export the variable with a clean ASCII/UTF-8 value: `export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`","Find and fix the writer that produced the non-UTF-8 value (CI secret definitions, Dockerfile ENV lines, .env encodings)","As a stopgap, unset the variable to fall back to the default http/protobuf protocol"],"exampleFix":"# before — value inherited with non-UTF-8 bytes, startup fails\ndeno run --unstable-otel main.ts\n\n# after — normalize to clean ASCII before starting\nexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf\ndeno run --unstable-otel main.ts","handlingStrategy":"validation","validationCode":"# normalize instead of trusting inherited environments\nexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf\ndeno run --unstable-otel main.ts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-export OTEL settings in the entrypoint script rather than inheriting them","Do not store OTLP settings in binary-encoded CI secrets","Suspect encoding when the error text after the colon mentions invalid Unicode"],"tags":["telemetry","otel","env-vars","encoding","startup"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}