Skip to content

An example Spring Boot service instrumented with OpenTelemetry

Notifications You must be signed in to change notification settings

sbstnc/example-spring-otel

Repository files navigation

An example Spring Boot service with OpenTelemetry

Raison d'être:

This repository contains example code on how to integrate a basic Spring Boot todo application with OpenTelemetry. It also ships with a preconfigured stack of monitoring and tracing applications including:

The code presented here is merely for demonstration purposes, do not use it in production environments.

Running

To get everything running you first need to build the application Docker image and install the Docker Driver Client for Loki.

./gradlew jibDockerBuild

Afterwards you can start the system with

docker-compose up

Available endpoints

The service provides a reasonable REST API to manage todos. The following endpoints are available:

  • GET /api/todos: Get a list of todos.
  • POST /api/todos: Create a new todo.
  • GET /api/todos/{id}: Get todo with the given {id}.
  • PUT /api/todos/{id}: Update todo with the given {id}.
  • PUT /api/todos/{id}/pending: Set status of todo with {id} to 'pending'.
  • PUT /api/todos/{id}/in-progress: Set status of todo with {id} to 'in progress'.
  • PUT /api/todos/{id}/done: Set status of todo with {id} to 'done'.
  • DELETE /api/todos/{id}: Delete todo with the given {id}.

You may use HTTPie or a similar tool to make requests. The service API is available at port 8080 of your machine.

Tracing

Grafana

After you have made some requests take a look at the logs in Grafana. Select the preconfigured Loki datasource and filter for the log label {job=example-spring-otel}. You can then expand a log message and click on the Tempo button next to the detected TraceID field. A new view with all spans belonging to the same trace will be opened.

Jaeger

You can also lookup a trace ID using Jaeger.

Prometheus Metrics

Metrics can be viewed in Prometheus and Grafana .