{"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":"exception","errorClass":"anyhow::Error","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/telemetry/lib.rs#L1242-L1278","documentation":"When reading OTEL_EXPORTER_OTLP_PROTOCOL, Deno distinguishes two failure modes: the variable being absent (VarError::NotPresent, treated as default) and every other std::env::VarError — practically only VarError::NotUnicode, i.e. the environment variable holds bytes that are not valid UTF-8. Since Rust env vars are OsString-backed, a non-UTF-8 value aborts telemetry init with this wrapped error.","triggerScenarios":"A process whose environment contains OTEL_EXPORTER_OTLP_PROTOCOL encoded in a non-UTF-8 codepage (e.g. Latin-1 bytes from a legacy Windows shell) or binary garbage injected by a misconfigured secrets agent or CI variable-passing mechanism.","commonSituations":"Windows CMD/PowerShell writing env vars with legacy encodings; Docker env_file saved with a non-UTF-8 editor; Kubernetes secrets created from binary data instead of stringData; shell scripts sourced from files with broken encoding.","solutions":["Re-set the variable with a plain ASCII value: OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf","Unset it entirely (absent is handled as the default, only invalid bytes are fatal)","Recreate the env_file / secret as UTF-8 text (use stringData rather than data in Kubernetes secrets)"],"exampleFix":"# before (env file saved as Latin-1 with BOM-like bytes)\ndocker run --env-file .env deno --otel app.ts\n\n# after: rewrite file as UTF-8 with a clean value\nprintf 'OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf\\n' > .env\ndocker run --env-file .env deno --otel app.ts","handlingStrategy":"validation","validationCode":"# Fail fast in the launch script if the var holds non-UTF-8 bytes\nif [ \"${OTEL_EXPORTER_OTLP_PROTOCOL+x}\" != \"x\" ]; then\n  unset OTEL_EXPORTER_OTLP_PROTOCOL\nelif ! printf '%s' \"$OTEL_EXPORTER_OTLP_PROTOCOL\" | LC_ALL=C grep -qP '^[\\x00-\\x7F]*$'; then\n  echo \"OTEL_EXPORTER_OTLP_PROTOCOL is not valid UTF-8/ASCII; resetting\" >&2\n  export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create env files and Kubernetes secrets as UTF-8 text (stringData, not binary data)","Avoid passing env through legacy Windows codepages; set vars from a UTF-8 shell or script","When in doubt, re-export the variable explicitly right before launching deno"],"tags":["otel","env-var","encoding","unicode","startup","configuration"],"backgroundTag":"env-var-not-unicode","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}