Oracle Kafka APIs and OpenTelemetry

Publish a message, save it in a relational table, and follow the trace from producer to consumer with Oracle Kafka APIs. In this article, we’ll combine events, transactions, relational data, and OpenTelemetry metrics, logs, and traces with a small Java app and Oracle AI Database Free.

You can run the entire lab on your laptop, provided you have a docker-compatible environment. Oracle AI Database Free is available at no cost under Oracle’s free use terms.

If you’d like to skip the article and jump to the lab, download the lab from GitHub, and give it a star if it was useful!

Oracle Kafka APIs

Oracle’s Kafka Java client, OKafka, uses familiar kafka-clients APIs to create topics, produce events, and consume events. Under the hood, it’s backed by Oracle AI Database Transactional Event Queues (TxEventQ), a high-throughput messaging system built into the database.

The really cool part about TxEventQ is the ability to combine messaging (pub/sub of events) with database transactions. E.g., a producer publishes an event and inserts a SQL row using the same database connection; both commit together.

Atomically commit messages and database operations.

Why is this useful? When events describe business data, failures must not leave events published while the corresponding SQL change is missing (or vice versa, and corollary to consumers).

Adding Observability with OpenTelemetry

If you’ve ever run a messaging system in production, you know it needs telemetry. We can monitor the database server side easily with the Oracle AI Database Metrics Exporter (which includes a TxEventQ addon), but what about the client side?

OpenTelemetry gives us three ways to see how data flows in the client:

SignalWhat it tells us
MetricsHow the clients behave over time: transaction timings, consumer throughput, and more.
LogsWhat happened: a reading was published, processed, or included in a batch that committed or rolled back.
TracesHow a reading moves from producer to consumer, with related spans and correlated logs.

In the lab, Spring Boot and Micrometer export all three through the OpenTelemetry Protocol (OTLP). Sender and receiver observations let Spring’s tracing handlers propagate context through Kafka record headers.

That said, let’s get started with the lab.

1. Download the sample

To run the sample, you’ll need Java 21, Maven, Git, and a running Docker-compatible environment with Docker Compose.

Download the sample from GitHub. The README contains the configuration reference and additional tests.

git clone https://github.com/anders-swanson/oracle-database-java-samples.git
cd oracle-database-java-samples/oracle-database-kafka-apis

2. Start Oracle AI Database Free and Grafana LGTM

docker compose up -d --wait

Compose starts an Oracle AI Database Free container and Grafana’s LGTM stack, which includes an OpenTelemetry Collector and backends for metrics, logs, and traces. 

During startup, a SQL script is automatically run to create the lab user, apply grants, and create tables. First-time startup will include image downloads.

Terminal output showing Docker container status for an Oracle database Kafka API setup, indicating healthy containers and active commands.
Starting the lab environment with Docker Compose

3. Run the Java application

From the same directory, run

mvn spring-boot:run

The application publishes an event every 500 milliseconds and continuously consumes events. Regular readings are inserted into the table; consumption updates their consumed_at timestamps. Occasionally, the producer publishes a failure marker. The consumer rolls back a batch containing that marker once, then processes it again and commits.

Watch for Published, Processed, Rolled back, and Committed messages. A Processed message describes work before the batch commits; the SQL table shows committed results.

Log output displaying scheduling and processing details for sensor readings, including metadata and consumed readings.
Processing events with Oracle OKafka. Notice the trace IDs present in the log messages.

4. Explore metrics, logs, and traces

Open Grafana  to view the OKafka Metrics Sample dashboard, which shows producer transaction timings, consumer throughput, polling activity, JVM memory, and CPU usage. 

Allow about a minute for panels to fully populate with metric data.

Dashboard displaying metrics for a Kafka service with statistics on producer commit time, consumer fetch throughput, producer transaction time, JVM memory usage, and application CPU usage.
Visualizing metrics from OKafka with a custom dashboard

Traces can be viewed in the Traces Drilldown. Each traces should propagate from the producer to consumer. You may also view logs in the Logs Drilldown.

Trace IDs are sent via headers, and populated in the producer and consumer logs.

You can also check Spring Boot Actuator for health and metrics data:

curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics

5. Stop and clean up

When you’re done, stop the Java process with Ctrl+C. Remove the lab containers with docker compose:

docker compose down

Articles and lab overview

Relevant lab files

Local endpoints — available while the lab is running

Leave a Reply