DEV Community

Cover image for OpenTelemetry attributes Dynatrace uses: service.name, enrichment and allow-list
Span Observer
Span Observer

Posted on Originally published at span.observer

OpenTelemetry attributes Dynatrace uses: service.name, enrichment and allow-list

Three services named unknown_service:python, traces you cannot tie to a pod, business attributes missing from queries: most disappointments after a first OTLP ingestion come down to attributes. Getting the OpenTelemetry attributes Dynatrace uses to build its entities right is the difference between a readable service map and a pile of orphan spans.

Goal: by the end of this tutorial, your OTel services carry the standard resource attributes, the Collector enriches them with Kubernetes and host context, and you know how to check which attributes are actually stored and queryable. It applies to Dynatrace SaaS (Grail, DQL) and Dynatrace Managed. Span attribute handling differs between the two: this is flagged in the relevant step.

For the Collector architecture, see the OpenTelemetry Collector on Kubernetes.

The problem: data without an identity

A span without a correct service.name attaches to no useful service. A span without Kubernetes attributes does not lead to the pod that crashed. During an incident, on-call loses minutes guessing « who » produced the data, and MTTR suffers. Resource attributes answer that question once and for all.

Prerequisites

  • Applications instrumented with an OpenTelemetry SDK (for example the OpenTelemetry Java agent).
  • An otelcol-contrib Collector or a distribution including k8sattributes, resourcedetection, resource and transform. In recent Collector contrib versions, k8sattributes and resourcedetection are named k8s_attributes and resource_detection; the old names, used below, remain accepted as deprecated aliases.
  • A Dynatrace token with the OTLP ingest scopes (traces, metrics, logs).

Resource or span: two levels of attributes

  • Resource attributes: describe the emitter and apply to all telemetry from a process. Examples: service.name, service.version, deployment.environment, k8s.pod.name, host.name.
  • Span attributes: describe an operation. Examples: http.request.method, db.system, order.id.

Simple rule: what does not change during the process lifetime belongs in the resource. Traces, metrics and logs then share the same keys, which makes correlation possible.

Configuring the OpenTelemetry attributes Dynatrace expects

Step 1: set resource attributes in the application

# excerpt from a Kubernetes Deployment
env:
  - name: OTEL_SERVICE_NAME
    value: "checkout"
  - name: POD_NAME
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
  - name: OTEL_RESOURCE_ATTRIBUTES
    value: "service.version=2.3.0,service.namespace=shop,deployment.environment=prod,k8s.pod.name=$(POD_NAME)"
Enter fullscreen mode Exit fullscreen mode

Critical lines: OTEL_SERVICE_NAME takes precedence over a service.name set in OTEL_RESOURCE_ATTRIBUTES. The $(POD_NAME) syntax is resolved by Kubernetes, provided the variable is declared earlier. Note: recent semantic conventions rename deployment.environment to deployment.environment.name; pick one key and use it everywhere.

Step 2: enrich in the Collector

The Collector adds what the application does not know: namespace, node, workload, cloud.

processors:
  k8sattributes:
    auth_type: serviceAccount
    passthrough: false
    extract:
      metadata:
        - k8s.namespace.name
        - k8s.deployment.name
        - k8s.pod.name
        - k8s.pod.uid
        - k8s.node.name
    pod_association:
      - sources:
          - from: resource_attribute
            name: k8s.pod.uid
      - sources:
          - from: connection
  resourcedetection:
    detectors: [env, system]
    timeout: 2s
    override: false
  resource:
    attributes:
      - key: k8s.cluster.name
        value: "prod-eu-1"
        action: upsert
Enter fullscreen mode Exit fullscreen mode

k8sattributes needs a ServiceAccount with get, list and watch rights on pods, namespaces and ReplicaSets. override: false stops detection from overwriting values already set by the application.

Step 3: Dynatrace enrichment on hosts running OneAgent

If OneAgent runs on the host, it can provide enrichment files containing attributes such as dt.entity.host, which tie OTel telemetry to the entities OneAgent discovered. The path and format of these files are described in the Dynatrace documentation (section on OpenTelemetry data enrichment): check them for your version rather than hard-coding them. Without OneAgent, identity relies solely on the attributes from steps 1 and 2.

Step 4: strip sensitive and useless attributes

Remove personal data and high-cardinality attributes before export:

processors:
  transform/clean:
    error_mode: ignore
    trace_statements:
      - context: span
        statements:
          - delete_key(attributes, "user.email")
          - replace_pattern(attributes["url.full"], "token=[^&]+", "token=***")
  batch: {}

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [k8sattributes, resourcedetection, resource, transform/clean, batch]
      exporters: [otlphttp/dynatrace]
Enter fullscreen mode Exit fullscreen mode

Step 5: understand the span attribute allow-list

Dynatrace does not handle all span attributes the same way depending on deployment:

  • Dynatrace Managed (and SaaS without span storage in Grail): custom span attributes must be explicitly allowed in the environment settings (an allow-list in the server-side service monitoring section; the exact label depends on the version). An attribute missing from the list is not kept. Masking options also exist.
  • Dynatrace SaaS with Grail: attributes are generally stored with spans and queryable in DQL, subject to the processing and masking rules you configure (OpenPipeline, privacy settings).

The exact behaviour evolves: check the Dynatrace documentation page on span attributes for your environment. Standard resource attributes, on the other hand, identify the service in both cases.

How to check that it works

  1. Collector side: temporarily add the debug exporter with verbosity: detailed and read the resource attributes in the Collector logs.
  2. Dynatrace SaaS: check that attributes are present in a notebook:

    fetch spans, from: now() - 30m
    | filter service.name == "checkout"
    | fields start_time, span.name, service.version, k8s.namespace.name, k8s.pod.name
    | limit 20
    

    An empty column means an attribute that was not set or not kept.

  3. Dynatrace Managed: open a distributed trace of the service and inspect the span attributes; a missing custom attribute must first be added to the allow-list.

  4. Service name: if unknown_service shows up, the process is not reading OTEL_SERVICE_NAME.

Best practices

  • One stable, unique service name per component; the version goes in service.version, never in the name.
  • The same resource attributes on traces, metrics and logs, so you can jump between signals (see OpenTelemetry logs with trace_id).
  • No user identifiers or high-cardinality values in resource attributes.
  • Filter your SLOs by deployment.environment so test and production never mix (see OpenTelemetry SLOs in DQL).
  • Document the team’s attribute convention: less toil for every new service.

Frequently asked questions

Why does my service appear twice?

Often because two service.name values coexist, or because OneAgent and the OTel SDK instrument the same process. Align the name and check for duplicates.

Should I prefix my business attributes?

Yes, a dedicated namespace (shop.order.id) avoids collisions with current and future semantic conventions.

Does the k8sattributes processor work outside Kubernetes?

No. Outside Kubernetes, use resourcedetection with the right detectors (system, cloud) and the resource processor.

Conclusion

Resource attributes are the identity of your telemetry. Set them in the application, enrich them in the Collector, clean them before export and check what Dynatrace keeps, on SaaS and Managed alike. References: the resource semantic conventions and the Dynatrace OpenTelemetry documentation.

span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of its owner.


Originally published on span.observer. French version: https://span.observer/fr/attributs-opentelemetry-dynatrace/.

Top comments (0)