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.
@opentelemetry/api Diag: resource detection for EnvDetector or process
Failed to detect resource: connect ETIMEDOUT 169.254.169.254:80Common 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
- Provide
OTEL_SERVICE_NAME(orOTEL_RESOURCE_ATTRIBUTES) so identity does not depend on detection. - Disable cloud detectors in CI to avoid the metadata timeout.
- Keep detection on only where the metadata endpoint actually exists.
env:
OTEL_SERVICE_NAME: my-service
OTEL_NODE_RESOURCE_DETECTORS: env,host,os,processDisable the SDK entirely for unit tests
If tests do not assert on resources, turn the SDK off so no detector runs.
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.