GithubHelp home page GithubHelp logo

jayeve / java-jdbc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opentracing-contrib/java-jdbc

0.0 1.0 0.0 301 KB

OpenTracing Instrumentation for JDBC

License: Apache License 2.0

Java 96.06% Shell 3.94%

java-jdbc's Introduction

Build Status Coverage Status Released Version Apache-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 tracer
Tracer tracer = ...

// Register tracer with GlobalTracer
GlobalTracer.register(tracer);

Hibernate

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

JPA

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

Spring

For dbcp2:

<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp2.BasicDataSource">
    <property name="driverClassName" value="io.opentracing.contrib.jdbc.TracingDriver"/>
    <property name="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.

java-jdbc's People

Contributors

apemost avatar backjo avatar bhs avatar dleischnig avatar jpkrohling avatar malafeev avatar pikkapikkachu avatar wcarmon avatar will-gtv avatar wuyupengwoaini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.