OpenCensus is a toolkit for collecting application performance and behavior data. Opencensus is a single distribution of libraries that automatically collects traces and metrics from your app, displays them locally, and sends them to any analysis tool.
Although OpenCensus records stats or traces, in this example we will only export traces and propagate context between 2 services.
Opencensus includes exporters for storage and analysis tools. Right now the list includes Zipkin, Prometheus, Jaeger, Stackdriver, and SignalFx. In this example will use the Jaeger exporter using the all-in-one docker image.
In this example we are running 2 services:
- hello-service
- greetings-service
Hello service This service will run on port 8888 and exposes the enpoint /hello. This endpoint returns the String "Hello from Service"
Greetings service This service will run on port 8080 and exposes the enpoint /greetings/hello. When calling this endpoint, this service calls the hello-service and returns the String received in the response.
When a request is process, traces are sent to Jaeger tool where you will get a detailed view of the operation. You can access at http://localhost:16686/
Example can be run with docker-compose. Build:
docker-compose build
Run:
docker-compose up
Call endpoint: http://localhost:8080/greetings/hello