MicroProfile OpenTracing
"The MicroProfile OpenTracing specification defines behaviors and an API for accessing an OpenTracing compliant Tracer object within your JAX-RS application. The behaviors specify how incoming and outgoing requests will have OpenTracing Spans automatically created." [https://microprofile.io/project/eclipse/microprofile-opentracing]
JBoss EAP 7.2
"SmallRye OpenTracing component and is provided by the microprofile-opentracing-smallrye subsystem."
"This subsystem implements Microprofile 1.1, which includes support for tracing requests to JAX-RS endpoints and CDI beans and is included in the default JBoss EAP 7.2 configuration."
"The microprofile-opentracing-smallrye subsystem ships with the Jaeger Java Client as the default tracer"
"Each individual WAR deployed to the JBoss EAP server automatically has its own Tracer instance."
"Instead, you configure the Jaeger Client by setting system properties or environment variables. See the Jaeger documentation [1] for information about how to configure the Jaeger Client. See Configuration via Environment [2] in the Jaeger documentation for the list of valid system properties."
"Because this feature is provided as Technology Preview, the current configuration options, particularly those related to configuring the Jaeger Java Client tracer using system properties and environment variables, might change in incompatible ways in future releases."
[JBoss EAP 7.2 Configuration Guide Eclipse Microprofile OpenTracing]
The microprofile-opentracing-smallrye subsystem does not offer any configuration in JBoss EAP 7.2
/subsystem=microprofile-opentracing-smallrye:read-resource-description(recursive=true)
{
"outcome" => "success",
"result" => {
"description" => "Wildfly Extension for Eclipse MicroProfile OpenTracing With SmallRye",
"attributes" => {},
"operations" => undefined,
"notifications" => undefined,
"children" => {}
}
}
Jaeger
See https://www.jaegertracing.io/.
Jaeger Openshift Template
See https://github.com/jaegertracing/jaeger-openshift. To run, run below command.
$ oc process -f https://raw.githubusercontent.com/jaegertracing/jaeger-openshift/master/all-in-one/jaeger-all-in-one-template.yml | oc create -f -
Jaeger Docker Image
But we are going to run the all-in-one docker image, see https://hub.docker.com/r/jaegertracing/all-in-one
To install Docker, see http://magnus-k-karlsson.blogspot.com/2019/08/install-docker-community-edition-ce-on.html.
Source code (Dockerfile) https://github.com/jaegertracing/jaeger/blob/master/cmd/all-in-one/Dockerfile
To run
$ docker run -d -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 14268:14268 -p 14250:14250 -p 16686:16686 jaegertracing/all-in-one
Web Application
Now we are going to write our application, use Java EE 8 and Eclipse Microprofile 1.4 from http://magnus-k-karlsson.blogspot.com/2019/10/eclipse-microprofile-and-java-ee-8-with.html.
Now lets write a @Traced JAX-RS endpoint and a CDI bean.
package se.magnuskkarlsson.example.microprofile.boundary;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.opentracing.Traced;
import se.magnuskkarlsson.example.microprofile.control.PersonService;
@Traced
@Path("/persons")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class PersonResource {
@Inject
protected PersonService personService;
@GET
public Response hello() {
JsonObject json = Json.createObjectBuilder().add("message", personService.getMessage()).build();
return Response.ok(json.toString()).build();
}
}
package se.magnuskkarlsson.example.microprofile.control;
import org.eclipse.microprofile.opentracing.Traced;
@Traced
public class PersonService {
public String getMessage() {
return "HELLO " + System.currentTimeMillis();
}
}
Also see JBoss EAP 7.2 Development Guide Eclipse Microprofile OpenTracing
Now we need Jaeger client configuration, configuration.properties
JAEGER_SERVICE_NAME=magnuskkarlsson
JAEGER_ENDPOINT=http://127.0.0.1:14268/api/traces
JAEGER_SAMPLER_TYPE=const
JAEGER_SAMPLER_PARAM=1
Build, deploy and start JBoss EAP 7.2 with above configuration file.
$ ./standalone.sh -P /home/magnuskkarlsson/eclipse-workspace/javaee8-microprofile1.4-example/configuration.properties
...
20:06:17,308 DEBUG [io.jaegertracing.thrift.internal.senders.ThriftSenderFactory] (ServerService Thread Pool -- 72) Using the HTTP Sender to send spans directly to the endpoint.
20:06:17,409 DEBUG [io.jaegertracing.internal.senders.SenderResolver] (ServerService Thread Pool -- 72) Using sender HttpSender()
20:06:17,417 INFO [io.jaegertracing.Configuration] (ServerService Thread Pool -- 72) Initialized tracer=JaegerTracer(version=Java-0.30.6.redhat-00001, serviceName=magnuskkarlsson, reporter=RemoteReporter(sender=HttpSender(), closeEnqueueTimeout=1000), sampler=ConstSampler(decision=true, tags={sampler.type=const, sampler.param=true}), tags={hostname=localhost.localdomain, jaeger.version=Java-0.30.6.redhat-00001, ip=127.0.0.1}, zipkinSharedRpcSpan=false, expandExceptionLogs=false)
...
Now open web application and make a few requests http://localhost:8080/javaee8-microprofile1.4-example/rest/persons.
Now lets see if those traces are sent to Jaeger, open http://127.0.0.1:16686/search