All Projects → opentracing-contrib → Java Jdbc

opentracing-contrib / Java Jdbc

Licence: apache-2.0
OpenTracing Instrumentation for JDBC

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Java Jdbc

Java Spring Cloud
Distributed tracing for Spring Boot, Cloud and other Spring projects
Stars: ✭ 326 (+443.33%)
Mutual labels:  jdbc, opentracing
Java Specialagent
Automatic instrumentation for 3rd-party libraries in Java applications with OpenTracing.
Stars: ✭ 156 (+160%)
Mutual labels:  jdbc, opentracing
Dd Opentracing Cpp
Datadog Opentracing C++ Client
Stars: ✭ 22 (-63.33%)
Mutual labels:  opentracing
Log4jdbc Spring Boot Starter
Starter for using Log4jdbc with Spring Boot
Stars: ✭ 49 (-18.33%)
Mutual labels:  jdbc
Core
Package core is a service container that elegantly bootstrap and coordinate twelve-factor apps in Go.
Stars: ✭ 34 (-43.33%)
Mutual labels:  opentracing
Pgjdbc
Postgresql JDBC Driver
Stars: ✭ 925 (+1441.67%)
Mutual labels:  jdbc
Elasticsearch Jdbc
A elasticsearch specified SQL interface on Java, no need to tweak your es instance.
Stars: ✭ 41 (-31.67%)
Mutual labels:  jdbc
Mycat2
MySQL Proxy using Java NIO based on Sharding SQL,Calcite ,simple and fast
Stars: ✭ 750 (+1150%)
Mutual labels:  jdbc
Jasync Sql
Java & Kotlin Async DataBase Driver for MySQL and PostgreSQL written in Kotlin
Stars: ✭ 1,092 (+1720%)
Mutual labels:  jdbc
E Marketplace For Buying And Reselling Products Web Project Using Jsp Servlet Jstl Security Jdbc
An 🛒online shopping system 🛍️ using J2EE ☕(Jsp, Servlet, Jdbc, Jstl), MySql, Bootstrap. This is like Olx 📲with an Unique name BechDo 💰and here is the latest version with final commit.
Stars: ✭ 33 (-45%)
Mutual labels:  jdbc
Jaeger Client Go
Jaeger Bindings for Go OpenTracing API.
Stars: ✭ 1,035 (+1625%)
Mutual labels:  opentracing
Cloud Based Sql Engine Using Spark
Cloud-based SQL engine using SPARK where data is accessible as JDBC/ODBC data source via Spark ThriftServer.
Stars: ✭ 30 (-50%)
Mutual labels:  jdbc
Sofa Tracer
SOFATracer is a component for the distributed system call trace. And through a unified traceId logging the logs of various network calls in the invoking link. These logs can be used for quick discovery of faults, service governance, etc.
Stars: ✭ 881 (+1368.33%)
Mutual labels:  opentracing
Schemacrawler
Free database schema discovery and comprehension tool
Stars: ✭ 1,021 (+1601.67%)
Mutual labels:  jdbc
Myjdbc Rainbow
jpa--轻量级orm模式对象与数据库映射api
Stars: ✭ 23 (-61.67%)
Mutual labels:  jdbc
Scala Db Codegen
Scala code/boilerplate generator from a db schema
Stars: ✭ 49 (-18.33%)
Mutual labels:  jdbc
Opentracing Php
MOVED TO https://github.com/opentracing/opentracing-php
Stars: ✭ 18 (-70%)
Mutual labels:  opentracing
Spark
Apache Spark - A unified analytics engine for large-scale data processing
Stars: ✭ 31,618 (+52596.67%)
Mutual labels:  jdbc
Csharp Grpc
OpenTracing Instrumentation for gRPC
Stars: ✭ 40 (-33.33%)
Mutual labels:  opentracing
Jaeger Client Ruby
OpenTracing Tracer implementation for Jaeger in Ruby
Stars: ✭ 59 (-1.67%)
Mutual labels:  opentracing

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

Non-interceptor

Tracing for JDBC connections of URLs starting with "jdbc:tracing:".

  1. Activate tracing for JDBC connections by adding tracing to the JDBC url:

    jdbc:tracing:h2:mem:test

    To trace calls with active Spans only, set property traceWithActiveSpanOnly=true.

    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 \.

    SELECT * FROM \"TEST\"
    The property can be repeated for multiple statements.

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

    Class.forName("io.opentracing.contrib.jdbc.TracingDriver");
    

    or

    io.opentracing.contrib.jdbc.TracingDriver.load();
    
  3. Instantiate tracer and register it with GlobalTracer.

    // Instantiate tracer
    Tracer tracer = ...
    
    // Register tracer with GlobalTracer
    GlobalTracer.register(tracer);
    
    

Interceptor

Tracing for all JDBC connections without modifying the URL.

In "interceptor mode", the TracingDriver will intercept calls to DriverManager.getConnection(url,...) for all URLs. The TracingDriver provides connections to the DriverManager that are instrumented. Please note that the TracingDriver must be registered before the underlying driver, It's recommended to turn on "interceptor mode" in the first place.

For standalone applications:

public static void main(String[] args) {
   io.opentracing.contrib.jdbc.TracingDriver.setInterceptorMode(true);
   // some jdbc operation here
}

For web applications:

public void contextInitialized(ServletContextEvent event) {
   io.opentracing.contrib.jdbc.TracingDriver.setInterceptorMode(true);
}

Or call TracingDriver.ensureRegisteredAsTheFirstDriver() along with TracingDriver.setInterceptorMode(true) at any place, Please note driver like Oracle JDBC may fail since it's destroyed forever after deregistration.

The withActiveSpanOnly and ignoreStatements properties for "interceptor mode" can be configured with the TracingDriver via:

// Set withActiveSpanOnly=true
TracingDriver.setInterceptorProperty(true);

and

// Set ignoreStatements={"CREATE TABLE ignored (id INTEGER, TEST VARCHAR)"}
TracingDriver.setInterceptorProperty(Collections.singleton("CREATE TABLE ignored (id INTEGER, TEST VARCHAR)"));

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>

Spring Boot 2

For Hikari (Postgresl):

### Spring JPA Datasource Connection
spring.datasource.username=postgres
spring.datasource.password=XXXXX
spring.datasource.hikari.driverClassName=io.opentracing.contrib.jdbc.TracingDriver
spring.datasource.hikari.jdbcUrl=jdbc:tracing:postgresql://localhost:5432/my_app_db

Configuration Bean:

@Component
public class OpenTracingConfig {

  @Bean
  public io.opentracing.Tracer jaegerTracer() {
    io.opentracing.contrib.jdbc.TracingDriver.load();
    return new Configuration("my_app").getTracer();
  }
}

Slow Query

Span is marked by tag slow=true if duration exceed slowQueryThresholdMs. slowQueryThresholdMs defaults to 0 which means disabled, can be enabled in two ways:

  1. Passing system property, E.g. -Dio.opentracing.contrib.jdbc.slowQueryThresholdMs=100
  2. Modify value by code, E.g. io.opentracing.contrib.jdbc.JdbcTracing.setSlowQueryThresholdMs(100)

Fast Query

Spans that complete faster than the optional excludeFastQueryThresholdMs flag will be not be reported. excludeFastQueryThresholdMs defaults to 0 which means disabled, can be enabled in two ways:

  1. Passing system property, E.g. -Dio.opentracing.contrib.jdbc.excludeFastQueryThresholdMs=100
  2. Modify value by code, E.g. io.opentracing.contrib.jdbc.JdbcTracing.setExcludeFastQueryThresholdMs(100)

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].