Example application using Exposed instrumented with OpenTracing using Exposed-OpenTracing. Contains a simple user database.
-
Start an all-in-one Jaeger backend with in-memory storage.
docker run -d --name jaeger \ -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \ -p 5775:5775/udp \ -p 6831:6831/udp \ -p 6832:6832/udp \ -p 5778:5778 \ -p 16686:16686 \ -p 14268:14268 \ -p 14250:14250 \ -p 9411:9411 \ jaegertracing/all-in-one:1.20
-
Start the application.
./gradlew run
-
Send some requests.
$curl --location --request POST 'http://localhost:8080/user' \ --header 'Content-Type: application/json' \ --data-raw '{ "username" : "el_franfran", "age" : 25, "password" : "DJK2LKJnnl2jnn!1234" }' $curl localhost:8080/user/el_franfran { "username" : "el_franfran", "age" : 25, "password" : "DJK2LKJnnl2jnn!1234" }
-
See traces in Jaeger.
-
Stop the Jaeger docker container.
docker ps docker stop <containerId>
-
Import Exposed-OpenTracing (commit).
implementation "com.github.fstien:exposed-opentracing:0.1.1"
-
Instantiate a tracer and register it in GlobalTracer (commit).
val tracer = Configuration("tracing-example") .withSampler(Configuration.SamplerConfiguration.fromEnv() .withType(ConstSampler.TYPE) .withParam(1)) .withReporter(Configuration.ReporterConfiguration.fromEnv() .withLogSpans(true) .withSender( Configuration.SenderConfiguration() .withAgentHost("localhost") .withAgentPort(6831))).tracerBuilder .withScopeManager(ThreadContextElementScopeManager()) .build() GlobalTracer.registerIfAbsent(tracer)
-
Connect to an in-memory H2 database and create a Users table (commit).
init { Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;", driver = "org.h2.Driver") tracedTransaction(contains = NoPII) { SchemaUtils.create(Users) } }
-
Replace calls to
transaction
withtracedTransaction
(commit).tracedTransaction(contains = PII, user.username, user.password) {