2.6 Application Tracing (optional)
Optional Section
The following content is optional. If you have time, feel free to proceed.
OpenTracing with Jaeger Tracing
We use OpenTracing for the distributed tracing. Our tracing backend is Jaeger.
Dependencies
Our application includes the following dependencies in the pom.xml.
| GroupId | ArtifactId | Description | Detailed information |
|---|---|---|---|
io.quarkus | quarkus-smallrye-opentracing | MicroProfile OpenTracing implementation | MicroProfile OpenTracing |
io.opentracing.contrib | opentracing-jdbc | Provides traces for database queries. |
Configuration
The following configurations is required in the application.properties to setup the tracing:
| |
endpoint: defines where we will send our metricsservice-name: the name of the current servicesampler-type:constdefines a constant samplingsampler-param: percentage of request which are sampled.1defines that we want to sample all requests.
Further we have to use the tracing enabled database driver.
| |
Last we made the Quarkus log format to include the traceId and spanId in the logs. This is not necessary but will
help troubleshooting.
| |
Configuration
The configuration listed above may slightly differ from the one used in the solution repository. This is because some properties are overridden using environment variables in thedocker-compose.yaml file.full source application.properties
Application code
Using the configuration made is basically everything which is needed to get traces from our application. By default all requests to
RESTful endpoints are traced. Using the TracingDriver provides spans for all database queries.
If you want to customize the tracing you can annotate any class or method with the @Traced annotation. You may also
disable the default tracing with @Traced(false). Further you may inject the Tracer to your application code. Using
this tracer you can create custom spans in business methods or add tags to span.
This snipped is from class ShopOrderService.
| |
This will create a span for the method createOrder and name it accordingly. Using the injected Tracer we tag the span
with the just created order.id.
full source ShopOrderService.java
Task 2.6.1 - Inspect the application traces
Start up your environment if not already running and point your browser to the Jaeger UI at http://localhost:16686/
Issue requests as described in section 2.4
- Do you find traces for created orders? You may list all traces or use the tag filter
order.id=X - How do traces look like if the operationName is not set?
- Do you see the tag
order.idon the span? - What happens if you inject an exception as described in section 2.4?
Task Hint
Traces from application code with no explicit name are named by their class and method. If an exception is thrown, there
will be a tag error=true on the span. The Jaeger UI will flag such spans with an exclamation mark.