Peek Inside Coherence with OpenTracing, Part 3

Tracing JPA and JDBC calls made easy

Ryan Lubke
Oracle Coherence
2 min readJan 8, 2021

--

In the previous articles of this series, we covered the basics of OpenTracing with Coherence followed by details on tracing with JAX-RS. This article will be the final installment of the series focusing on producing tracing spans for calls to the database.

Configuring OpenTracing JDBC

To get started, will need to add an additional dependency io.opentracing.contrib:opentracing-jdbc:0.2.12.
The java-jdbc library allows interception and tracing of JDBC calls.

Previously, the coherence-demo application didn’t use a database, so let’s assume that Coherence is already configured to use JPA and review what changes are needed to generate spans when JDBC is called:

  1. We specify the io.opentracing.contrib.jdbc.TracingDriver instead of Derby’s driver class.
  2. We add tracing to the JDBC URL, and add an additional parameter, traceWithActiveSpanOnly=true, which simply means the driver will only trace if a span is already active.

That’s it!

Analyzing Captured Traces with Jaeger UI

We can now re-run the demo application and verify we can see the calls going through to the database:

As we did in the previous article, we’re taking a look at ChartDataResource.getChartData again. This time, we drill down further and we can see getChartData calls through to Utilities.UpdatePrices which performs an update of the cache data. Later, the Coherence CacheStore API is invoked to store the changes in the database causing a span for a JDBC update to be generated. Let’s drill into the CacheStore and Update spans:

From the cachestore.store span, we can see the thread performing the write-behind and which CacheStore implementation is being used. Looking at the Update span, we can see the update being sent to Derby.

Summary

As you can see, the changes allowing the capture of JDBC spans are trivial — just a few lines of XML.

With this article, we now how visibility through the various layers of the demo application; the JAX-RS front-end, Coherence, and the database.

We did gloss over some of the details such as the UI changes, what changes were made for JPA, etc. I’d encourage interested readers to spend some time reviewing the Coherence Demo source. In addition to showcasing OpenTracing, it demonstrates many other features of Coherence that may be of interest.

--

--