OpenTracing instrumentation of Exposed. Observe database transactions with spans tagged with query strings, table names and more. Logs execution start/ending, transaction commit and rollback. Santise queries to safeguard PII.
In an application with a tracer registered in GlobalTracer, replace your Exposed transaction
with a tracedTransaction
:
tracedTransaction(contains = NoPII) {
Cities.insert {
it[name] = "St. Petersburg"
}
}
The execution will be wrapped with a child span of the previously active span, which will be tagged with the SQL query. If your query contains PII that you do not want to leak to the tracing system, pass the sensitive strings to the call as follows:
tracedTransaction(contains = PII, name, password) {
Users.insert {
it[Users.username] = username
it[Users.name] = name
it[Users.password] = password
}
}
The name
and password
strings with be replaced with <REDACTED>
in the query tagged on the span.
If no strings are password with contains = PII
or if a string is passed with contains = NoPII
, a warn log will be written, and the transaction will execute without tracing.
The resulting ExposedTransaction
span looks as follows in Jaeger:
From Maven Central.
Add the following dependency to your pom.xml
:
<dependency>
<groupId>com.github.fstien</groupId>
<artifactId>exposed-opentracing</artifactId>
<version>VERSION_NUMBER</version>
</dependency>
Add the following to your dependencies in your build.gradle
:
implementation 'com.github.fstien:exposed-opentracing:VERSION_NUMBER'
For an example Ktor application, see Exposed-OpenTracing-example.