Resourcedetection Processor
contrib, k8s
Maintainers: @Aneurysm9, @dashpole
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
The resource detection processor can be used to detect resource information from the host, in a format that conforms to the OpenTelemetry resource semantic conventions, and append or override the resource value in telemetry data with this information.Note If a configured resource detector fails, the error will propagate and stop the collector from starting.
Supported detectors
Environment Variable
Reads resource information from theOTEL_RESOURCE_ATTRIBUTES environment
variable. This is expected to be in the format <key1>=<value1>,<key2>=<value2>,..., the
details of which are currently pending confirmation in the OpenTelemetry specification.
Example:
System metadata
Note: use the Docker detector (see below) if running the Collector as a Docker container. Queries the host machine to retrieve the system related resource attributes. The list of the populated resource attributes can be found at System Detector Resource Attributes. By defaulthost.name is being set to FQDN if possible, and a hostname provided by OS used as fallback.
This logic can be changed with hostname_sources configuration which is set to ["dns", "os"] by default.
Use the following config to avoid getting FQDN and apply hostname provided by OS only:
- all valid options for
hostname_sources:- “dns”
- “os”
- “cname”
- “lookup”
Hostname Sources
dns
The “dns” hostname source uses multiple sources to get the fully qualified domain name. First, it looks up the host name in the local machine’shosts file. If that fails, it looks up the CNAME. Lastly, if that fails,
it does a reverse DNS query. Note: this hostname source may produce unreliable results on Windows. To produce
a FQDN, Windows hosts might have better results using the “lookup” hostname source, which is mentioned below.
os
The “os” hostname source provides the hostname provided by the local machine’s kernel.cname
The “cname” hostname source provides the canonical name, as provided by net.LookupCNAME in the Go standard library. Note: this hostname source may produce unreliable results on Windows.lookup
The “lookup” hostname source does a reverse DNS lookup of the current host’s IP address.Docker metadata
Queries the Docker daemon to retrieve resource attributes from the host machine. The list of the populated resource attributes can be found at Docker Detector Resource Attributes. You need to mount the Docker socket (/var/run/docker.sock on Linux) to contact the Docker daemon.
Docker detection does not work on macOS.
Example:
Docker Socket Permissions
Since version 0.40.0, official OpenTelemetry Collector images run as a non-root user. To access the Docker socket, you need to configure appropriate permissions:- Linux: Grant access to the
dockergroup (e.g.,--group-add <docker-gid>or setrunAsGroupin Kubernetes) - Windows: Ensure appropriate named pipe permissions
Heroku metadata
When Heroku dyno metadata is active, Heroku applications publish information through environment variables. We map these environment variables to resource attributes as follows:| Dyno metadata environment variable | Resource attribute |
|---|---|
HEROKU_APP_ID | heroku.app.id |
HEROKU_APP_NAME | service.name |
HEROKU_DYNO_ID | service.instance.id |
HEROKU_RELEASE_CREATED_AT | heroku.release.creation_timestamp |
HEROKU_RELEASE_VERSION | service.version |
HEROKU_SLUG_COMMIT | heroku.release.commit |
GCP Metadata
Uses the Google Cloud Client Libraries for Go to read resource information from the metadata server and environment variables to detect which GCP platform the application is running on, and detect the appropriate attributes for that platform. Regardless of the GCP platform the application is running on, use the gcp detector: It also can optionally gather labels for the GCE instance that the collector is running on. Note that in order to fetch GCE labels, the service account assigned to the GCE instance must have theroles/compute.viewer role.
Example:
GCE Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_compute_engine”)
- cloud.account.id (project id)
- cloud.region (e.g. us-central1)
- cloud.availability_zone (e.g. us-central1-c)
- host.id (instance id)
- host.name (instance name)
- host.type (machine type)
- (optional) gcp.gce.instance.hostname
- (optional) gcp.gce.instance.name
GKE Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_kubernetes_engine”)
- cloud.account.id (project id)
- cloud.region (only for regional GKE clusters; e.g. “us-central1”)
- cloud.availability_zone (only for zonal GKE clusters; e.g. “us-central1-c”)
- k8s.cluster.name
- host.id (instance id)
- host.name (instance name; only when workload identity is disabled)
host.name. In that case, users are encouraged to set host.name from either:
node.namethrough the downward API with theenvdetector- obtaining the Kubernetes node name from the Kubernetes API (with
k8s.io/client-go)
Google Cloud Run Services Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_cloud_run”)
- cloud.account.id (project id)
- cloud.region (e.g. “us-central1”)
- faas.instance (instance id)
- faas.name (service name)
- faas.version (service revision)
Cloud Run Jobs Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_cloud_run”)
- cloud.account.id (project id)
- cloud.region (e.g. “us-central1”)
- faas.instance (instance id)
- faas.name (service name)
- gcp.cloud_run.job.execution (“my-service-ajg89”)
- gcp.cloud_run.job.task_index (“0”)
Google Cloud Functions Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_cloud_functions”)
- cloud.account.id (project id)
- cloud.region (e.g. “us-central1”)
- faas.instance (instance id)
- faas.name (function name)
- faas.version (function version)
Google App Engine Metadata
- cloud.provider (“gcp”)
- cloud.platform (“gcp_app_engine”)
- cloud.account.id (project id)
- cloud.region (e.g. “us-central1”)
- cloud.availability_zone (e.g. “us-central1-c”)
- faas.instance (instance id)
- faas.name (service name)
- faas.version (service version)
AWS EC2
Uses AWS SDK for Go to read resource information from the EC2 instance metadata API to retrieve related resource attributes: The list of the populated resource attributes can be found at EC2 Detector Resource Attributes. It also can optionally gather tags for the EC2 instance that the collector is running on. By default, tags are fetched via the EC2DescribeTags API,
which requires the IAM role assigned to the EC2 instance to include the ec2:DescribeTags permission.
Alternatively, tags can be fetched via the Instance Metadata Service (IMDS),
which does not require any IAM permissions but requires instance metadata tags to be enabled on the instance.
Tag retrieval behavior is controlled by the tags_from_imds configuration field:
false(default): tags are fetched via the EC2DescribeTagsAPI — requiresec2:DescribeTagsIAM permission.true: tags are fetched via IMDS — no IAM permissions needed, but requiresInstanceMetadataTags=enabledon the instance.
PARALLELCLUSTER_IMDS contains a rule that allows OTEL user to access 169.254.169.254/32
In some cases, you might need to change the behavior of the AWS metadata client from the standard retryer
By default, the client retries 3 times with a max backoff delay of 20s.
We offer a limited set of options to override those defaults specifically, such that you can set the client to retry 10 times, for up to 5 minutes, for example:
Amazon ECS
Queries the Task Metadata Endpoint (TMDE) to record information about the current ECS Task. Only TMDE V4 and V3 are supported. The list of the populated resource attributes can be found at ECS Detector Resource Attributes. Example:Amazon Elastic Beanstalk
Reads the AWS X-Ray configuration file available on all Beanstalk instances with X-Ray Enabled. The list of the populated resource attributes can be found at Elastic Beanstalk Detector Resource Attributes. Example:Amazon EKS
This detector reads resource information from the EC2 instance metadata service to retrieve related resource attributes. If IMDS is not available, (example: EKS-AutoMode and POD not on the hostnetwork), it falls back to a combination of Kubernetes API and EC2 API to retrieve related resource attributes. EC2 API requires theEC2:DescribeInstances permission to be granted to the IAM role. If IMDS is not accessible, ex: EKS-AutoMode, you can use POD Identity.
The list of the populated resource attributes can be found at EKS Detector Resource Attributes.
Example:
Cluster Name
Cluster name detection is disabled by default, and can be enabled with the following configuration:EC2:DescribeInstances action.
If you see an error with the message context deadline exceeded, please increase the timeout setting in your config.
Node Name Env Variable
When using the EC2 API and the Kubernetes API to retrieve resource attributes, the node name is needed. The node name is extracted from the env variable you define on the pod. The node name env variable that contains the node name value can be set using thenode_from_env_var option:
K8S_NODE_NAME will hold the actual node name and can be set in the pod spec using the downward API.
AWS Lambda
Uses the AWS Lambda runtime environment variables to retrieve related resource attributes. The list of the populated resource attributes can be found at Lambda Detector Resource Attributes. Example:Azure
Queries the Azure Instance Metadata Service to retrieve related attributes. The list of the populated resource attributes can be found at Azure Detector Resource Attributes. Example:- azure.tags.
<tag name>
Azure AKS
The list of the populated resource attributes can be found at AKS Detector Resource Attributes.Cluster Name
Cluster name detection is disabled by default, and can be enabled with the following configuration:MC_<resource group>_<cluster name>_<location>.
Example:
- Resource group: my-resource-group
- Cluster name: my-cluster
- Location: eastus
- Generated name: MC_my-resource-group_my-cluster_eastus
Consul
Queries a consul agent and reads its configuration endpoint to retrieve related resource attributes: The list of the populated resource attributes can be found at Consul Detector Resource Attributes. In addition to:- exploded consul metadata - reads all key:value pairs in consul metadata into label:labelvalue pairs.
Kubeadm Metadata
Queries the K8S API server to retrieve kubeadm resource attributes: The list of the populated resource attributes can be found at kubeadm Detector Resource Attributes.Oracle Cloud Infrastructure (OCI) metadata
The OCI detector implements a fast probe to the instance metadata service (IMDS) endpoint to quickly verify if the collector is running on OCI. If this probe fails, the detector returns an empty resource and no error. If the probe succeeds, it then fetches instance metadata; if this fetch fails, the detector logs and returns an error so that partial detection is not silently ignored. This behavior makes it possible to differentiate between the case where the collector is not running on OCI, vs it is running on OCI but the IMDS request failed. Queries the Oracle Cloud Infrastructure (OCI) metadata service to retrieve resource attributes related to the OCI instance environment. The list of the populated resource attributes can be found at OracleCloud Detector Resource Attributes. Example:cloud.providercloud.platformcloud.regioncloud.availability_zonehost.idhost.namehost.typek8s.cluster.name
The following permissions are required:
| Name | Type | Required | Default | Docs |
|---|---|---|---|---|
| auth_type | string | No | serviceAccount | How to authenticate to the K8s API server. This can be one of none (for no auth), serviceAccount (to use the standard service account token provided to the agent pod), or kubeConfig to use credentials from ~/.kube/config. |
K8S Node Metadata
Queries the K8S api server to retrieve node resource attributes. The list of the populated resource attributes can be found at k8snode Detector Resource Attributes. The following permissions are required:| Name | Type | Required | Default | Docs |
|---|---|---|---|---|
| auth_type | string | No | serviceAccount | How to authenticate to the K8s API server. This can be one of none (for no auth), serviceAccount (to use the standard service account token provided to the agent pod), or kubeConfig to use credentials from ~/.kube/config. |
| node_from_env_var | string | Yes | K8S_NODE_NAME | The environment variable name that holds the name of the node to retrieve metadata from. Default value is K8S_NODE_NAME. You can set the env dynamically on the workload definition using the downward API; see example |
Example using the default node_from_env_var option:
Example using a custom variable node_from_env_var option:
OpenShift
Queries the OpenShift and Kubernetes API to retrieve related resource attributes. The list of the populated resource attributes can be found at OpenShift Detector Resource Attributes. The following permissions are required:KUBERNETES_SERVICE_HOST, KUBERNETES_SERVICE_PORT and the service token is read from /var/run/secrets/kubernetes.io/serviceaccount/token.
If TLS is not explicit disabled and no ca_file is configured /var/run/secrets/kubernetes.io/serviceaccount/ca.crt is used.
The determination of the API address, ca_file and the service token is skipped if they are set in the configuration.
Example:
Dynatrace
Loads resource information from thedt_host_metadata.properties file which is located in
the /var/lib/dynatrace/enrichment (on *nix systems) or %ProgramData%\dynatrace\enrichment (on Windows) directories.
If present in the file, the following attributes will be added:
dt.entity.hosthost.namedt.smartscape.host
override: false configuration option, to prevent the detector from overwriting
existing resource attributes.
If the Dynatrace host entity identifier attribute dt.entity.host, host.name, or dt.smartscape.host are already present on incoming data as it is sent from
other sources to the collector, then these describe the monitored entity in the best way.
Overriding these with the collector’s own identifier would instead make the telemetry appear as if it was coming from the collector
or the collector’s host instead, which might be inaccurate.
Hetzner
Uses the Hetzner metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Hetzner Detector Resource Attributes. Hetzner custom configuration example:Akamai
Uses the Akamai metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Akamai Detector Resource Attributes. Akamai custom configuration example:Scaleway
Uses the Scaleway metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Scaleway Detector Resource Attributes. Scaleway custom configuration example:Upcloud
Uses the Upcloud metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Upcloud Detector Resource Attributes. Upcloud custom configuration example:Vultr
Uses the Vultr metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Vultr Detector Resource Attributes. Vultr custom configuration example:Digital Ocean
Uses the Digital Ocean metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Digital Ocean Detector Resource Attributes. Akamai custom configuration example:Openstack Nova
Uses the OpenStack Nova metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Nova Detector Resource Attributes. It can also optionally capture metadata keys from the"meta" section of meta_data.json as resource attributes, using regular expressions to match the keys you want.
Nova custom configuration example:
Alibaba Cloud ECS
Uses the Alibaba Cloud metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Alibaba Cloud ECS Detector Resource Attributes. Alibaba Cloud ECS custom configuration example:Tencent Cloud CVM
Uses the Tencent Cloud metadata API to read resource information from the instance metadata service and populate related resource attributes. The list of the populated resource attributes can be found at Tencent Cloud CVM Detector Resource Attributes. Tencent Cloud CVM custom configuration example:IBM Cloud VPC
Queries the IBM Cloud VPC Instance Metadata Service to retrieve resource attributes from the instance. The list of the populated resource attributes can be found at IBM Cloud VPC Detector Resource Attributes. By default, the detector queries the IBM Cloud VPC Instance Metadata Service athttp://api.metadata.cloud.ibm.com. Set protocol: https to use HTTPS instead.
Note TheExample:protocoloption must match the instance’s metadata service access mode. If the Secure access state is toggled while the collector is running, update theprotocolconfiguration value accordingly and restart the collector.
IBM Cloud Classic
Queries the IBM Cloud Classic (SoftLayer) Resource Metadata Service to retrieve resource attributes from the instance. The list of the populated resource attributes can be found at IBM Cloud Classic Detector Resource Attributes. Example:Configuration
resource_attributes option. An example of such a configuration is:
Using the refresh_interval parameter
The refresh_interval option allows resource attributes to be periodically refreshed without restarting the Collector.
Important considerations:
- Latency: Newly detected resource attributes will be applied after the next refresh cycle completes (up to
refresh_intervalduration). - Metric cardinality: Changes to resource attributes create new metric time series, which can significantly increase storage costs and query complexity.
- Performance impact: Each refresh re-runs all configured detectors. Values below 5 minutes can increase CPU and memory usage. There is no enforced minimum, but intervals below 1 minute are strongly discouraged.
Performance
Benchmark Tests
This component includes comprehensive benchmark tests for all stable signals. The benchmarks measure the performance of the processor under different configurations:- Traces:
BenchmarkConsumeTracesDefaultandBenchmarkConsumeTracesAll - Metrics:
BenchmarkConsumeMetricsDefaultandBenchmarkConsumeMetricsAll - Logs:
BenchmarkConsumeLogsDefaultandBenchmarkConsumeLogsAll
Ordering
Note that if multiple detectors are inserting the same attribute name, the first detector to insert wins. For example if you haddetectors: [eks, ec2] then cloud.platform will be aws_eks instead of ec2. The below ordering is recommended.
AWS
- lambda
- elastic_beanstalk
- eks
- ecs
- ec2
Configuration
config.yaml (testdata)
config.yaml (testdata)
Last generated: 2026-04-13