{"id":21153043,"url":"https://github.com/opentracing-contrib/java-jdbc","last_synced_at":"2025-04-05T00:06:09.075Z","repository":{"id":43537181,"uuid":"88128035","full_name":"opentracing-contrib/java-jdbc","owner":"opentracing-contrib","description":"OpenTracing Instrumentation for JDBC","archived":false,"fork":false,"pushed_at":"2022-02-09T23:21:37.000Z","size":522,"stargazers_count":82,"open_issues_count":12,"forks_count":56,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T23:04:12.396Z","etag":null,"topics":["java","jdbc","opentracing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentracing-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-13T05:24:35.000Z","updated_at":"2025-02-07T03:18:50.000Z","dependencies_parsed_at":"2022-08-30T19:02:04.056Z","dependency_job_id":null,"html_url":"https://github.com/opentracing-contrib/java-jdbc","commit_stats":null,"previous_names":[],"tags_count":74,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-jdbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-jdbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-jdbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-jdbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentracing-contrib","download_url":"https://codeload.github.com/opentracing-contrib/java-jdbc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266563,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jdbc","opentracing"],"created_at":"2024-11-20T10:48:16.636Z","updated_at":"2025-04-05T00:06:09.040Z","avatar_url":"https://github.com/opentracing-contrib.png","language":"Java","readme":"[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Released Version][maven-img]][maven] [![Apache-2.0 license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n# OpenTracing JDBC Instrumentation\n\nOpenTracing instrumentation for JDBC.\n\n## Installation\n\npom.xml\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.opentracing.contrib\u003c/groupId\u003e\n    \u003cartifactId\u003eopentracing-jdbc\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n### Non-interceptor\n\n\u003e Tracing for JDBC connections of URLs starting with `\"jdbc:tracing:\"`.\n\n1. Activate tracing for JDBC connections by adding `tracing` to the JDBC url:\n\n   _jdbc:**tracing**:h2:mem:test_\n\n   To trace calls with active `Span`s only, set property `traceWithActiveSpanOnly=true`.\n\n   _jdbc:**tracing**:h2:mem:test?**traceWithActiveSpanOnly=true**_\n\n   To ignore specific queries (such as health checks), use the\n   property `ignoreForTracing=\"SELECT 1\"`. Double quotes can be escaped with `\\`.\n\n   `SELECT * FROM \\\"TEST\\\"`\u003cbr\u003e\u003csup\u003eThe property can be repeated for multiple statements.\u003c/sup\u003e\n\n2. Set driver class to `io.opentracing.contrib.jdbc.TracingDriver`.\n\n   ```java\n   Class.forName(\"io.opentracing.contrib.jdbc.TracingDriver\");\n   ```\n\n   or\n\n   ```java\n   io.opentracing.contrib.jdbc.TracingDriver.load();\n   ```\n\n3. Instantiate tracer and register it with GlobalTracer.\n\n   ```java\n   // Instantiate tracer\n   Tracer tracer = ...\n\n   // Register tracer with GlobalTracer\n   GlobalTracer.register(tracer);\n\n   ```\n\n### Interceptor\n\n\u003e Tracing for all JDBC connections without modifying the URL.\n\nIn \"interceptor mode\", the `TracingDriver` will intercept calls\nto `DriverManager.getConnection(url,...)` for all URLs. The `TracingDriver` provides connections to\nthe `DriverManager` that are instrumented. Please note that the `TracingDriver` must be registered\nbefore the underlying driver, It's recommended to turn on \"interceptor mode\" in the first place.\n\nFor standalone applications:\n\n```java\npublic static void main(String[] args) {\n   io.opentracing.contrib.jdbc.TracingDriver.setInterceptorMode(true);\n   // some jdbc operation here\n}\n\n```\n\nFor web applications:\n\n```java\npublic void contextInitialized(ServletContextEvent event) {\n   io.opentracing.contrib.jdbc.TracingDriver.setInterceptorMode(true);\n}\n```\n\nOr call `TracingDriver.ensureRegisteredAsTheFirstDriver()` along\nwith `TracingDriver.setInterceptorMode(true)` at any place, Please note driver like Oracle JDBC may\nfail since it's destroyed forever after deregistration.\n\nThe `withActiveSpanOnly` and `ignoreStatements` properties for \"interceptor mode\" can be configured\nwith the `TracingDriver` via:\n\n```java\n// Set withActiveSpanOnly=true\nTracingDriver.setInterceptorProperty(true);\n```\n\nand\n\n```java\n// Set ignoreStatements={\"CREATE TABLE ignored (id INTEGER, TEST VARCHAR)\"}\nTracingDriver.setInterceptorProperty(Collections.singleton(\"CREATE TABLE ignored (id INTEGER, TEST VARCHAR)\"));\n```\n\n### Hibernate\n\n```xml\n\u003chibernate-configuration\u003e\n    \u003csession-factory\u003e\n        \u003cproperty name=\"hibernate.connection.driver_class\"\u003eio.opentracing.contrib.jdbc.TracingDriver\u003c/property\u003e\n        \u003cproperty name=\"hibernate.connection.url\"\u003ejdbc:tracing:mysql://localhost:3306/test\u003c/property\u003e\n        ...\n    \u003c/session-factory\u003e\n    ...\n\u003c/hibernate-configuration\u003e\n```\n\n### JPA\n\n```xml\n\u003cpersistence-unit name=\"jpa\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"javax.persistence.jdbc.driver\" value=\"io.opentracing.contrib.jdbc.TracingDriver\"/\u003e\n        \u003cproperty name=\"javax.persistence.jdbc.url\" value=\"jdbc:tracing:mysql://localhost:3306/test\"/\u003e\n        ...\n    \u003c/properties\u003e\n\u003c/persistence-unit\u003e\n```\n\n### Spring\n\nFor dbcp2:\n\n```xml\n\u003cbean id=\"dataSource\" destroy-method=\"close\" class=\"org.apache.commons.dbcp2.BasicDataSource\"\u003e\n    \u003cproperty name=\"driverClassName\" value=\"io.opentracing.contrib.jdbc.TracingDriver\"/\u003e\n    \u003cproperty name=\"url\" value=\"jdbc:tracing:mysql://localhost:3306/test\"/\u003e\n    ...\n\u003c/bean\u003e\n\n```\n\n### Spring Boot 2\n\nFor Hikari (Postgresl):\n\n```properties\n### Spring JPA Datasource Connection\nspring.datasource.username=postgres\nspring.datasource.password=XXXXX\nspring.datasource.hikari.driverClassName=io.opentracing.contrib.jdbc.TracingDriver\nspring.datasource.hikari.jdbcUrl=jdbc:tracing:postgresql://localhost:5432/my_app_db\n\n```\n\nConfiguration Bean:\n\n```java\n\n@Component\npublic class OpenTracingConfig {\n\n  @Bean\n  public io.opentracing.Tracer jaegerTracer() {\n    io.opentracing.contrib.jdbc.TracingDriver.load();\n    return new Configuration(\"my_app\").getTracer();\n  }\n}\n\n```\n\n## Slow Query\n\nSpan is marked by tag `slow=true` if duration exceed `slowQueryThresholdMs`.\n`slowQueryThresholdMs` defaults to `0` which means disabled, can be enabled in two ways:\n\n1. Passing system property, E.g. `-Dio.opentracing.contrib.jdbc.slowQueryThresholdMs=100`\n2. Modify value by code, E.g. `io.opentracing.contrib.jdbc.JdbcTracing.setSlowQueryThresholdMs(100)`\n\n## Fast Query\n\nSpans that complete faster than the optional `excludeFastQueryThresholdMs` flag will be not be\nreported.\n`excludeFastQueryThresholdMs` defaults to `0` which means disabled, can be enabled in two ways:\n\n1. Passing system property, E.g. `-Dio.opentracing.contrib.jdbc.excludeFastQueryThresholdMs=100`\n2. Modify value by code,\n   E.g. `io.opentracing.contrib.jdbc.JdbcTracing.setExcludeFastQueryThresholdMs(100)`\n\n## Troubleshooting\n\nIn case of _Unable to find a driver_ error the database driver should be registered before\nconfiguring the datasource. E.g. `Class.forName(\"com.mysql.jdbc.Driver\");`\n\n## License\n\n[Apache 2.0 License](./LICENSE).\n\n[ci-img]: https://travis-ci.org/opentracing-contrib/java-jdbc.svg?branch=master\n\n[ci]: https://travis-ci.org/opentracing-contrib/java-jdbc\n\n[cov-img]: https://coveralls.io/repos/github/opentracing-contrib/java-jdbc/badge.svg?branch=master\n\n[cov]: https://coveralls.io/github/opentracing-contrib/java-jdbc?branch=master\n\n[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/opentracing-jdbc.svg\n\n[maven]: http://search.maven.org/#search%7Cga%7C1%7Cio.opentracing.contrib%20opentracing-jdbc\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentracing-contrib%2Fjava-jdbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentracing-contrib%2Fjava-jdbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentracing-contrib%2Fjava-jdbc/lists"}