Configure Dapr to send distributed tracing data

Configure Dapr to send distributed tracing data

It is recommended to run Dapr with tracing enabled for any production scenario. You can configure Dapr to send tracing and telemetry data to many backends based on your environment, whether it is running in the cloud or on-premises.

Tracing configuration

Configuration sepc下的 tracing 部分包含以下属性:

  1. spec:
  2. tracing:
  3. samplingRate: "1"
  4. zipkin:
  5. endpointAddress: "https://..."

下面的表格给出了调用链追踪功能可配置的属性

属性数据类型说明
samplingRatestring设置采样率,可以用来控制追踪功能是否开启。
zipkin.endpointAddressstring设置 Zipkin 服务器地址。

Zipkin in self hosted mode

The following steps show you how to configure Dapr to send distributed tracing data to Zipkin running as a container on your local machine and view them.

For self hosted mode, create a Dapr configuration file locally and reference it with the Dapr CLI.

  1. Create the following config.yaml YAML file:

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Configuration
    3. metadata:
    4. name: zipkin
    5. namespace: default
    6. spec:
    7. tracing:
    8. samplingRate: "1"
    9. zipkin:
    10. endpointAddress: "http://localhost:9411/api/v2/spans"
  2. Launch Zipkin using Docker:

    1. docker run -d -p 9411:9411 openzipkin/zipkin
  3. Launch Dapr with the --config param with the path for where the config.yaml is saved :

    1. dapr run --app-id mynode --app-port 3000 --config ./config.yaml node app.js

Zipkin in Kubernetes mode

The following steps show you how to configure Dapr to send distributed tracing data to Zipkin running as a container in your Kubernetes cluster, and how to view them.

设置

First, deploy Zipkin:

  1. kubectl create deployment zipkin --image openzipkin/zipkin

Create a Kubernetes Service for the Zipkin pod:

  1. kubectl expose deployment zipkin --type ClusterIP --port 9411

接下来,在本地创建以下YAML文件:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Configuration
  3. metadata:
  4. name: zipkin
  5. namespace: default
  6. spec:
  7. tracing:
  8. samplingRate: "1"
  9. zipkin:
  10. endpointAddress: "http://zipkin.default.svc.cluster.local:9411/api/v2/spans"

Finally, deploy the Dapr configuration:

  1. kubectl apply -f config.yaml

为了启用您的 Dapr sidecar 的配置,请在您的pod spec模板中添加以下注释:

  1. annotations:
  2. dapr.io/config: "zipkin"

就这么简单! Your sidecar is now configured for use with Zipkin.

查看追踪数据

To view traces, connect to the Zipkin service and open the UI:

  1. kubectl port-forward svc/zipkin 9411:9411

On your browser, go to http://localhost:9411 and you should see the Zipkin UI.

zipkin

参考资料