opentelemetry-java-instrume.../dd-trace-examples/spring-boot-jdbc
renaudboutet c5dd057312 [maven-release-plugin] prepare release v0.0.5 2017-06-07 19:04:55 +02:00
..
.mvn/wrapper Refactoring project skel 2017-05-23 14:08:55 +02:00
src/main Refactoring project skel 2017-05-23 14:08:55 +02:00
README.md fix version deps 2017-05-31 15:37:06 +02:00
apm.png Refactoring project skel 2017-05-23 14:08:55 +02:00
mvnw Refactoring project skel 2017-05-23 14:08:55 +02:00
mvnw.cmd Refactoring project skel 2017-05-23 14:08:55 +02:00
pom.xml [maven-release-plugin] prepare release v0.0.5 2017-06-07 19:04:55 +02:00

README.md

Spring-boot + JDBC (MySQL) example

Purpose

This project aims at demonstrating how to instrument legacy code based on the SpringBoot framework and a MySQL JDBC connection.

Along with the opentracing agent we use 2 Opentracing contributions:

  • The JDBC contrib, that intercepts and trace all the calls to the DB
  • The Spring-Boot contrib, which intercepts and trace all incoming HTTP calls

Each contribution hides the complexity to the developers.

Run the demo

Prerequisites

  1. Please make sure that you read and executed the prerequisites provided on this page
  2. Make also sure that you have a MySQL DB running (and an access to it). Then Update your settings here.

Run the application

If you want to enable tracing you have to launch the application with the datadog java agent.

That can be done by providing the following JVM argument (assuming the M2_REPO env variable is set and we run version {version}): -javaagent:${M2_REPO}/com/datadoghq/dd-java-agent/{version}/dd-java-agent-{version}.jar.

There are 2 ways to test it:

  • Either with Maven: mvn spring-boot:run -Djavaagent:${M2_REPO}/com/datadoghq/dd-java-agent/{version}/dd-java-agent-{version}.jar
  • Or if you prefer with your IDE providing the java agent command

Generate traces

Once the application runs. Go to the following url:

  • http://localhost:8080/demo/add?name=foo&email=bar
  • http://localhost:8080/demo/all

Then, you will able to see traces directly to the DataDog UI.

Datadog APM

How did we instrument this project?

If you want to instrument your own code (Spring-boot and JDBC based), here is how you should do it.

Dependencies

Auto-instrumentation with the dd-trace-agent

The instrumentation is entirely done by the datadog agent which embed a set of rules that automatically recognizes & instruments:

  • The java servlet filters

The datadog agent embeds the open tracing java agent.

JDBC is not automatically instrumented yet by the agent. So you should follow the instructions on the next section.

JDBC tracing configuration

Just edit your application.properties file and add :tracing right after the jdbc string as shown below.

spring.datasource.url= jdbc:tracing:mysql://localhost:3306/springdb