Skip to content
Latchkey

OpenTelemetry JS "resource detection failed" / no resource attributes in CI

An OTel resource detector (EC2, GCP, container) tries to read a cloud metadata endpoint that does not exist on a CI runner. The detector times out or logs a failure, and spans lack the expected service.name/host attributes.

What this error means

The diagnostic log shows "@opentelemetry/resource-detector-... Resource detection failed" or a several-second stall on startup, and exported spans have no cloud/host resource attributes.

node
@opentelemetry/api Diag: resource detection for EnvDetector or process
Failed to detect resource: connect ETIMEDOUT 169.254.169.254:80

Common causes

Cloud metadata endpoints are unreachable on runners

Detectors probe 169.254.169.254 (the link-local metadata IP). CI runners are not that cloud instance, so the request times out before the detector gives up.

No service.name provided as a fallback

When detection yields nothing and you never set OTEL_SERVICE_NAME, spans default to unknown_service, which is often mistaken for a detection bug.

How to fix it

Set resource attributes explicitly

  1. Provide OTEL_SERVICE_NAME (or OTEL_RESOURCE_ATTRIBUTES) so identity does not depend on detection.
  2. Disable cloud detectors in CI to avoid the metadata timeout.
  3. Keep detection on only where the metadata endpoint actually exists.
.github/workflows/ci.yml
env:
  OTEL_SERVICE_NAME: my-service
  OTEL_NODE_RESOURCE_DETECTORS: env,host,os,process

Disable the SDK entirely for unit tests

If tests do not assert on resources, turn the SDK off so no detector runs.

.github/workflows/ci.yml
env:
  OTEL_SDK_DISABLED: 'true'

How to prevent it

  • Always set OTEL_SERVICE_NAME so identity is deterministic.
  • Limit OTEL_NODE_RESOURCE_DETECTORS to detectors that work off-cloud.
  • Skip cloud detectors in environments without a metadata service.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →