Elastic Agent doesn’t propagate client metadata
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. Elastic Agent can run in OpenTelemetry mode to retrieve traces, metrics, and logs from your infrastructure and applications, and forward them to Elastic Observability. Availability This functionality is generally available and ready for production usage. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless Observability
Generally available
Stack
Generally available
Elastic Agent
Generally available
By default, the Collector only propagates transport-level metadata. If you want the Elastic Agent to propagate metadata like project_id, tenant, or environment, you need a specific SDK instrumentation.
In the context of Elastic OpenTelemetry, client metadata refers to gRPC metadata or HTTP headers that accompany telemetry data sent by clients (usually SDKs) to the Collector.
For example:
- Authorization headers
- Trace propagation headers
user-agentstrings sent by HTTP clients or EDOT SDKs
This is transport-level metadata, and not application-level context.
In this context, client metadata does not include:
- Custom attributes like
project_id,tenant, orenvironment - Application business logic fields
- Resource attributes
Expected labels do not appear in Elastic APM or metric data.
Your collector configuration file, for example otel-config.yaml, looks similar to this:
receivers:
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318"
processors:
resource:
attributes:
- key: project.id
from_context: client_metadata
action: insert
This will not work, as the Collector doesn't automatically extract such values from headers.
If you want to propagate customer IDs or project names into spans or metrics, you must instrument this in your code using one of the SDKs. For SDK-specific troubleshooting guidance, refer to EDOT SDKs troubleshooting.
Use span.set_attribute in your application code, where OpenTelemetry spans are created. For example:
from opentelemetry import trace
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("handle_request") as span:
span.set_attribute("project.id", get_project_id_from_context())