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.
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:
| Signal | What it tells us |
|---|---|
| Metrics | How the clients behave over time: transaction timings, consumer throughput, and more. |
| Logs | What happened: a reading was published, processed, or included in a batch that committed or rolled back. |
| Traces | How 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-apis2. Start Oracle AI Database Free and Grafana LGTM
docker compose up -d --waitCompose 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.

3. Run the Java application
From the same directory, run
mvn spring-boot:runThe 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.

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.

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.
You can also check Spring Boot Actuator for health and metrics data:
curl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics5. Stop and clean up
When you’re done, stop the Java process with Ctrl+C. Remove the lab containers with docker compose:
docker compose downArticles and lab overview
- Oracle AI Database Free
- Lab source code
- Lab instructions: OKafka metrics, tracing, and logs
- Lab video
- Authenticate to Oracle AI Database Like It’s a Kafka Cluster
- Pub/Sub in Your DB: Oracle AI Database TxEventQ
- Oracle AI Database Metrics Exporter
Relevant lab files
- MetricsSample.java — transactional producer, consumer, and trace propagation
- MetricsApplication.java — application startup, metric binders, and log export wiring
- MetricsClientConfiguration.java — OKafka producer and consumer configuration
- application.yaml — telemetry endpoints and trace sampling
- docker-compose.yml — Oracle AI Database Free and Grafana LGTM
- init.sql — database user and startup configuration
- Grafana dashboard JSON
- pom.xml — lab dependencies and build configuration
Local endpoints — available while the lab is running

Leave a Reply