|
| 1 | +--- |
| 2 | +mapped_pages: |
| 3 | + - https://www.elastic.co/guide/en/observability/current/apm-open-telemetry-resource-attributes.html |
| 4 | + - https://www.elastic.co/guide/en/serverless/current/observability-apm-agents-opentelemetry-resource-attributes.html |
| 5 | +applies_to: |
| 6 | + stack: |
| 7 | + serverless: |
| 8 | +--- |
| 9 | + |
| 10 | +# Attributes and labels [apm-open-telemetry-resource-attributes] |
| 11 | + |
| 12 | +In OpenTelemetry, an attribute is a key-value pair. Attributes are similar to [labels](/solutions/observability/apm/metadata.md#apm-data-model-labels) in that they add metadata to transactions, spans, and other entities. |
| 13 | + |
| 14 | +Resource attributes are a type of attribute that contains information about the entities that produce telemetry. Resource attributes map to Elastic Common Schema (ECS) fields like `service.*`, `cloud.*`, `process.*`, and so on. These fields describe the service and its environment. |
| 15 | + |
| 16 | +For example, Elastic APM maps the OpenTelemetry `deployment.environment` field to the ECS `service.environment` field on ingestion. |
| 17 | + |
| 18 | +## Setting resource attributes |
| 19 | + |
| 20 | +You can set resource attributes through environment variables or by editing the configuration of the resource processor of the OpenTelemetry Collector. |
| 21 | + |
| 22 | +### OpenTelemetry agent |
| 23 | + |
| 24 | +Use the `OTEL_RESOURCE_ATTRIBUTES` environment variable to pass resource attributes at process invocation. For example: |
| 25 | + |
| 26 | +```bash |
| 27 | +export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production |
| 28 | +``` |
| 29 | + |
| 30 | +### OpenTelemetry Collector |
| 31 | + |
| 32 | +Use the [resource processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourceprocessor) to set or apply changes to resource attributes when using the OTel Collector. |
| 33 | + |
| 34 | +```yaml |
| 35 | +... |
| 36 | +processors: |
| 37 | + resource: |
| 38 | + attributes: |
| 39 | + - key: deployment.environment |
| 40 | + action: insert |
| 41 | + value: production |
| 42 | +... |
| 43 | +``` |
| 44 | + |
| 45 | +## Handling of unmapped attributes |
| 46 | + |
| 47 | +When sending telemetry to Elastic APM, only a subset of OpenTelemetry attributes are directly mapped to Elastic APM document fields, such as ECS fields. If an attribute doesn't have a predefined mapping, the system stores it under `labels.*`, with dots replaced by underscores. |
| 48 | + |
| 49 | +Unmapped resource attributes are treated as global labels in Elastic APM, meaning they apply to all telemetry data from the resource. In contrast, unmapped record-level attributes, such as those specific to a log record, span, or data point, are stored as normal labels associated only with that specific record. |
| 50 | + |
| 51 | +For example, if an OpenTelemetry resource contains: |
| 52 | + |
| 53 | +```json |
| 54 | +{ |
| 55 | + "service.name": "user-service", |
| 56 | + "deployment.environment": "production", |
| 57 | + "otel.library.name": "my-lib", |
| 58 | + "custom.attribute.with.dots": "value" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +Elastic APM stores the following: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "service.name": "user-service", |
| 67 | + "service.environment": "production", |
| 68 | + "labels": { |
| 69 | + "otel_library_name": "my-lib", |
| 70 | + "custom_attribute_with_dots": "value" |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## Scope attributes translation |
| 76 | + |
| 77 | +Scope attributes are translated as follows: |
| 78 | + |
| 79 | +| OpenTelemetry attribute | Elastic APM field | |
| 80 | +|-------------------------|-------------------| |
| 81 | +| scope.name | service.framework.name | |
| 82 | +| scope.version | service.framework.version | |
| 83 | + |
| 84 | +Unmapped scope attributes are ignored. |
0 commit comments