|
| 1 | +--- |
| 2 | +type: docs |
| 3 | +title: "Using Dynatrace OpenTelemetry Collector to collect traces to send to Dynatrace" |
| 4 | +linkTitle: "Using the Dynatrace OpenTelemetry Collector" |
| 5 | +weight: 1000 |
| 6 | +description: "How to push trace events to Dynatrace, using the Dynatrace OpenTelemetry Collector." |
| 7 | +--- |
| 8 | + |
| 9 | +Dapr integrates with the [Dynatrace Collector](https://docs.dynatrace.com/docs/ingest-from/opentelemetry/collector) using the OpenTelemetry protocol (OTLP). This guide walks through an example using Dapr to push traces to Dynatrace, using the Dynatrace version of the OpenTelemetry Collector. |
| 10 | + |
| 11 | +{{% alert title="Note" color="primary" %}} |
| 12 | +This guide refers to the Dynatrace OpenTelemetry Collector, which uses the same Helm chart as the open-source collector but overridden with the Dynatrace-maintained image for better support and Dynatrace-specific features. |
| 13 | +{{% /alert %}} |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- [Install Dapr on Kubernetes]({{< ref kubernetes >}}) |
| 18 | +- Access to a Dynatrace tenant and an API token with `openTelemetryTrace.ingest`, `metrics.ingest`, and `logs.ingest` scopes |
| 19 | +- Helm |
| 20 | + |
| 21 | +## Set up Dynatrace OpenTelemetry Collector to push to your Dynatrace instance |
| 22 | + |
| 23 | +To push traces to your Dynatrace instance, install the Dynatrace OpenTelemetry Collector on your Kubernetes cluster. |
| 24 | + |
| 25 | +1. Create a Kubernetes secret with your Dynatrace credentials: |
| 26 | + |
| 27 | + ```sh |
| 28 | + kubectl create secret generic dynatrace-otelcol-dt-api-credentials \ |
| 29 | + --from-literal=DT_ENDPOINT=https://YOUR_TENANT.live.dynatrace.com/api/v2/otlp \ |
| 30 | + --from-literal=DT_API_TOKEN=dt0s01.YOUR_TOKEN_HERE |
| 31 | + ``` |
| 32 | + |
| 33 | + Replace `YOUR_TENANT` with your Dynatrace tenant ID and `YOUR_TOKEN_HERE` with your Dynatrace API token. |
| 34 | + |
| 35 | +1. Use the Dynatrace OpenTelemetry Collector distribution for better defaults and support than the open source version. Download and inspect the [`collector-helm-values.yaml`](https://github.com/Dynatrace/dynatrace-otel-collector/blob/main/config_examples/collector-helm-values.yaml) file. This is based on the [k8s enrichment demo](https://docs.dynatrace.com/docs/ingest-from/opentelemetry/collector/use-cases/kubernetes/k8s-enrich#demo-configuration) and includes Kubernetes metadata enrichment for proper pod/namespace/cluster context. |
| 36 | + |
| 37 | + |
| 38 | +1. Deploy the Dynatrace Collector with Helm. |
| 39 | + |
| 40 | + ```sh |
| 41 | + helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts |
| 42 | + helm repo update |
| 43 | + helm upgrade -i dynatrace-collector open-telemetry/opentelemetry-collector -f collector-helm-values.yaml |
| 44 | + ``` |
| 45 | + |
| 46 | +## Set up Dapr to send traces to the Dynatrace Collector |
| 47 | + |
| 48 | +Create a Dapr configuration file to enable tracing and send traces to the OpenTelemetry Collector via [OTLP](https://opentelemetry.io/docs/specs/otel/protocol/). |
| 49 | + |
| 50 | + |
| 51 | +1. Update the following file to ensure the `endpointAddress` points to your Dynatrace OpenTelemetry Collector service in your Kubernetes cluster. If deployed in the `default` namespace, it's typically `dynatrace-collector.default.svc.cluster.local`. |
| 52 | +
|
| 53 | + **Important:** Ensure the `endpointAddress` does NOT include the `http://` prefix to avoid URL encoding issues: |
| 54 | +
|
| 55 | + ```yaml |
| 56 | + apiVersion: dapr.io/v1alpha1 |
| 57 | + kind: Configuration |
| 58 | + metadata: |
| 59 | + name: tracing |
| 60 | + spec: |
| 61 | + tracing: |
| 62 | + samplingRate: "1" |
| 63 | + otel: |
| 64 | + endpointAddress: "dynatrace-collector.default.svc.cluster.local:4318" # Update with your collector's service address |
| 65 | + ``` |
| 66 | + |
| 67 | +1. Apply the configuration with: |
| 68 | + |
| 69 | + ```sh |
| 70 | + kubectl apply -f collector-config-otel.yaml |
| 71 | + ``` |
| 72 | + |
| 73 | +## Deploy your app with tracing |
| 74 | + |
| 75 | +Apply the `tracing` configuration by adding a `dapr.io/config` annotation to the Dapr applications that you want to include in distributed tracing, as shown in the following example: |
| 76 | + |
| 77 | +```yaml |
| 78 | +apiVersion: apps/v1 |
| 79 | +kind: Deployment |
| 80 | +metadata: |
| 81 | + ... |
| 82 | +spec: |
| 83 | + ... |
| 84 | + template: |
| 85 | + metadata: |
| 86 | + ... |
| 87 | + annotations: |
| 88 | + dapr.io/enabled: "true" |
| 89 | + dapr.io/app-id: "MyApp" |
| 90 | + dapr.io/app-port: "8080" |
| 91 | + dapr.io/config: "tracing" |
| 92 | +``` |
| 93 | + |
| 94 | +{{% alert title="Note" color="primary" %}} |
| 95 | +If you are using one of the Dapr tutorials, such as [distributed calculator](https://github.com/dapr/quickstarts/tree/master/tutorials/distributed-calculator), you will need to update the `appconfig` configuration to `tracing`. |
| 96 | +{{% /alert %}} |
| 97 | + |
| 98 | +You can register multiple tracing exporters at the same time, and the tracing logs are forwarded to all registered exporters. |
| 99 | + |
| 100 | +That's it! There's no need to include any SDKs or instrument your application code. Dapr automatically handles the distributed tracing for you. |
| 101 | + |
| 102 | +## View traces |
| 103 | + |
| 104 | +Deploy and run some applications. After a few minutes, you should see traces appearing in your Dynatrace tenant: |
| 105 | + |
| 106 | +1. Navigate to **Search > Distributed tracing** in your Dynatrace UI. |
| 107 | +2. Filter by service names to see your Dapr applications and their associated tracing spans. |
| 108 | + |
| 109 | +<img src="/images/open-telemetry-collector-dynatrace-traces.png" width=1200 alt="Dynatrace showing tracing data."> |
| 110 | + |
| 111 | +{{% alert title="Note" color="primary" %}} |
| 112 | +Only operations going through Dapr API exposed by Dapr sidecar (for example, service invocation or event publishing) are displayed in Dynatrace distributed traces. |
| 113 | +{{% /alert %}} |
| 114 | + |
| 115 | + |
| 116 | +{{% alert title="Disable OneAgent daprd monitoring" color="warning" %}} |
| 117 | +If you are running Dynatrace OneAgent in your cluster, you should exclude the `daprd` sidecar container from OneAgent monitoring to prevent interferences in this configuration. Excluding it prevents any automatic injection attempts that could break functionality or result in confusing traces. |
| 118 | + |
| 119 | + |
| 120 | +Add this annotation to your application deployments or globally in your dynakube configuration file: |
| 121 | + |
| 122 | +```yaml |
| 123 | +metadata: |
| 124 | + annotations: |
| 125 | + dapr.io/enabled: "true" |
| 126 | + dapr.io/app-id: "MyApp" |
| 127 | + dapr.io/app-port: "8080" |
| 128 | + dapr.io/config: "tracing" |
| 129 | + container.inject.dynatrace.com/daprd: "false" # Exclude dapr sidecar from being auto-monitored by OneAgent |
| 130 | +
|
| 131 | +``` |
| 132 | +{{% /alert %}} |
| 133 | + |
| 134 | +## Related links |
| 135 | +- Try out the [observability quickstart](https://github.com/dapr/quickstarts/tree/master/tutorials/observability/README.md) |
| 136 | +- Learn how to set [tracing configuration options]({{< ref "configuration-overview.md#tracing" >}}) |
| 137 | +- [Dynatrace OpenTelemetry documentation](https://docs.dynatrace.com/docs/ingest-from/opentelemetry) |
| 138 | +- Enrich OTLP telemetry data [with Kubernetes metadata |
| 139 | +](https://docs.dynatrace.com/docs/ingest-from/opentelemetry/collector/use-cases/kubernetes/k8s-enrich) |
0 commit comments