Skip to content

Repository files navigation

Build StatusCoverage StatusReleased VersionApache-2.0 license

OpenTracing JDBC Instrumentation

OpenTracing instrumentation for JDBC.

Installation

pom.xml

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-jdbc</artifactId>
<version>VERSION</version>
</dependency>

Usage

  1. Add tracing to jdbc url. E.g. jdbc:tracing:h2:mem:test
    To trace calls only if there is an active Span use property traceWithActiveSpanOnly=true.
    E.g. jdbc:tracing:h2:mem:test?traceWithActiveSpanOnly=true To ignore specific queries (such as health checks) use the property ignoreForTracing="SELECT 1". Double quotes can be escaped with \ (i.e.) SELECT * FROM \"TEST\" and the property can be repeated for multiple statements.

  2. Set driver class to io.opentracing.contrib.jdbc.TracingDriver

  3. Instantiate tracer and register it with GlobalTracer

// Instantiate tracerTracertracer = ...
// Register tracer with GlobalTracerGlobalTracer.register(tracer);

Hibernate

<hibernate-configuration>
<session-factory>
<propertyname="hibernate.connection.driver_class">io.opentracing.contrib.jdbc.TracingDriver</property>
<propertyname="hibernate.connection.url">jdbc:tracing:mysql://localhost:3306/test</property>
...
</session-factory>
...
</hibernate-configuration>

JPA

<persistence-unitname="jpa">
<properties>
<propertyname="javax.persistence.jdbc.driver"value="io.opentracing.contrib.jdbc.TracingDriver"/>
<propertyname="javax.persistence.jdbc.url"value="jdbc:tracing:mysql://localhost:3306/test"/>
...
</properties>
</persistence-unit>

Spring

For dbcp2:

<beanid="dataSource"destroy-method="close"class="org.apache.commons.dbcp2.BasicDataSource">
<propertyname="driverClassName"value="io.opentracing.contrib.jdbc.TracingDriver"/>
<propertyname="url"value="jdbc:tracing:mysql://localhost:3306/test"/>
...
</bean> 

Troubleshooting

In case of Unable to find a driver error the database driver should be registered before configuring the datasource.
E.g. Class.forName("com.mysql.jdbc.Driver");

License

Apache 2.0 License.

About

OpenTracing Instrumentation for JDBC

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages