Skip to content

BarbieCue/dapr-distributed-tracing-service-invocation

Repository files navigation

dapr example - distributed tracing (service invocation)

dapr

The following scenario is implemented here.

scenario

We want to trace a sample transaction that spans over four service. It starts at service A, passes B and C, and ends at service D. As the trace starts at service A, the dapr sidecar of A creates the Trace ID and appends it as request header (called traceparent) when requesting service B. Then, service B has to manually forward this header when requesting service C. C also has to forward this header manually when requesting service D. This is propagating sequential service calls.

All tracing operations like creation and reporting to Jaeger via Zipkin collector are done by dapr, which is explicitly configured to do distributed tracing using the tracing-config.yaml.

Prerequisites

  • dapr CLI
  • Java (Version >=17)
  • A running Jaeger instance
    docker run \
    -e COLLECTOR_ZIPKIN_HOST_PORT=:9412 \
    -p 16686:16686 \
    -p 9412:9412 \
    jaegertracing/all-in-one

Get started

1. Build all services

./gradlew buildAllServices

2. Run each service alongside a dapr sidecar

dapr run --app-id a-service --app-port 8080 --app-protocol http --dapr-http-port 3500 --config tracing-config.yaml -- java -cp a/build/libs/fat.jar org.example.AKt
dapr run --app-id b-service --app-port 8081 --app-protocol http --dapr-http-port 3501 --config tracing-config.yaml -- java -cp b/build/libs/fat.jar org.example.BKt
dapr run --app-id c-service --app-port 8082 --app-protocol http --dapr-http-port 3502 --config tracing-config.yaml -- java -cp c/build/libs/fat.jar org.example.CKt
dapr run --app-id d-service --app-port 8083 --app-protocol http --dapr-http-port 3503 --config tracing-config.yaml -- java -cp d/build/libs/fat.jar org.example.DKt

As you can see, the dapr CLI is used to start up both, the dapr sidecar and the service.

3. Be the client - make a call to trigger tracing

curl http://localhost:8080/

4. View the traces in Jaeger UI

Visit http://localhost:16686/

trace_example

References

Releases

No releases published

Packages

No packages published

Languages