denoland/deno · error · anyhow::Error
no private key found in OTEL_EXPORTER_OTLP_CLIENT_KEY file
Error message
no private key found in OTEL_EXPORTER_OTLP_CLIENT_KEY file
What it means
For OpenTelemetry OTLP export with client-certificate mTLS, Deno reads the key file named by OTEL_EXPORTER_OTLP_CLIENT_KEY (when OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE is also set) and runs it through the rustls PEM private-key parser (ext/telemetry/lib.rs:841-846). If the file contains no recognizable `-----BEGIN ... PRIVATE KEY-----` block, the exporter setup fails with this error before any telemetry is sent.
Solutions
- Point OTEL_EXPORTER_OTLP_CLIENT_KEY at a PEM private key (PKCS#8/RSA/EC/SEC1 — a `-----BEGIN ... PRIVATE KEY-----` block) and keep the certificate in OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE.
- Verify the file parses: `openssl pkey -in <keyfile> -noout` (exit 0 means a readable key).
- Convert a DER key if needed: `openssl pkey -in key.der -inform DER -out key.pem`.
- Confirm the mounted secret is complete (non-empty, fully written) before the process starts.
Example fix
# before export OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE=/certs/client.pem export OTEL_EXPORTER_OTLP_CLIENT_KEY=/certs/client.pem # same file — no key block # error: no private key found in OTEL_EXPORTER_OTLP_CLIENT_KEY file # after openssl pkey -in /certs/client.key -noout && echo key ok export OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE=/certs/client.pem export OTEL_EXPORTER_OTLP_CLIENT_KEY=/certs/client.key
Defensive patterns
Strategy: validation
Validate before calling
# Verify the PEM key is readable and actually a key before exporting
openssl pkey -in "$OTEL_EXPORTER_OTLP_CLIENT_KEY" -noout \
|| { echo 'CLIENT_KEY file is not a readable PEM private key'; exit 1; }
openssl x509 -in "$OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE" -noout \
|| { echo 'CLIENT_CERTIFICATE file is not a certificate'; exit 1; } Prevention
- Name and mount key vs cert files distinctly so the two env vars cannot be swapped.
- Convert DER keys to PEM at provisioning time (openssl pkey -inform DER).
- Ensure secret sidecars finish writing the key file before the Deno process starts.
When it happens
Trigger: OTEL_EXPORTER_OTLP_CLIENT_KEY pointing at the certificate instead of the key, a CSR, an empty or truncated file, a DER (binary) key, or an encrypted PEM the parser cannot read; values swapped with OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE.
Common situations: Copy-paste of cert/key paths in container env config; keys generated in DER format by an internal CA; secret-injection sidecars writing the file late or partially; k8s secret mounts mixing up key/cert keys.
Related errors
- TracerProvider can not be constructed
- A key and certificate are required for `Deno.listenTls`
- Both 'cert' and 'key' must be provided to enable HTTPS
- Cannot convert a Symbol value to a string
- ContextManager can not be constructed
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/b23ec24e04ddf21b.
Report an issue: GitHub.
Appendix: source
Thrown at ext/telemetry/lib.rs:841
}
} else {
let ca_certs = match std::env::var("OTEL_EXPORTER_OTLP_CERTIFICATE") {
Ok(path) => vec![sys.fs_read(path)?.into_owned()],
_ => vec![],
};
let keys = match (
std::env::var("OTEL_EXPORTER_OTLP_CLIENT_KEY"),
std::env::var("OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE"),
) {
(Ok(key_path), Ok(cert_path)) => {
let key = sys.fs_read(key_path)?;
let cert = sys.fs_read(cert_path)?;
let certs = load_certs(&mut std::io::Cursor::new(cert))?;
let key =
load_private_keys(&key)?.into_iter().next().ok_or_else(|| {
deno_core::anyhow::anyhow!(
"no private key found in OTEL_EXPORTER_OTLP_CLIENT_KEY file"
)
})?;
TlsKeys::Static(TlsKey(certs, key))
}
_ => TlsKeys::Null,
};
let tls_config =
create_client_config(deno_tls::TlsClientConfigOptions {
root_cert_store: None,
ca_certs,
unsafely_ignore_certificate_errors: None,
unsafely_disable_hostname_verification: false,
cert_chain_and_key: keys,
socket_use: SocketUse::Http,
})?;View on GitHub (pinned to 9ad36f7a2c)