Skip to content

Commit

Permalink
Added opentracing-jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
whiskeysierra committed Nov 25, 2019
1 parent 3e2199b commit f587563
Show file tree
Hide file tree
Showing 124 changed files with 1,529 additions and 25 deletions.
4 changes: 2 additions & 2 deletions opentracing-flowid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Add the following dependency to your project:
<dependency>
<groupId>org.zalando</groupId>
<artifactId>opentracing-flowid</artifactId>
<version>${opentracing-toolbox.version}</version>
<version>${opentracing-flowid.version}</version>
</dependency>
```

Expand All @@ -59,7 +59,7 @@ Alternatively, you can import our *bill of materials*...
<dependency>
<groupId>org.zalando</groupId>
<artifactId>opentracing-flowid-bom</artifactId>
<version>${opentracing-toolbox.version}</version>
<version>${opentracing-flowid.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</parent>
<artifactId>opentracing-flowid-bom</artifactId>
<packaging>pom</packaging>
<description>Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid-httpclient</artifactId>
<description>HTTP Client interceptor for Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid-okhttp</artifactId>
<description>HTTP Client interceptor for Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid-servlet</artifactId>
<description>Servlet 3 filter for tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid-spring-boot-autoconfigure</artifactId>
<description>Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid-spring-boot-starter</artifactId>
<description>Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-flowid</artifactId>
<description>Tracing requests through a distributed system.</description>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
Expand Down
14 changes: 7 additions & 7 deletions opentracing-flowid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<artifactId>opentracing-flowid-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>bom</module>
<module>core</module>
<module>httpclient</module>
<module>okhttp</module>
<module>servlet</module>
<module>spring-boot-autoconfigure</module>
<module>spring-boot-starter</module>
<module>opentracing-flowid</module>
<module>opentracing-flowid-bom</module>
<module>opentracing-flowid-httpclient</module>
<module>opentracing-flowid-okhttp</module>
<module>opentracing-flowid-servlet</module>
<module>opentracing-flowid-spring-boot-autoconfigure</module>
<module>opentracing-flowid-spring-boot-starter</module>
</modules>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
Expand Down
110 changes: 110 additions & 0 deletions opentracing-jdbc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# OpenTracing: JDBC

[![Stability: Active](https://masterminds.github.io/stability/active.svg)](https://masterminds.github.io/stability/active.html)

_OpenTracing JDBC_ is a library that instruments any `javax.sql.DataSource` with OpenTracing.

- **Technology stack**: Java 8+, OpenTracing, JDBC
- **Status**: 0.x

## Why not [opentracing-contrib/java-jdbc](https://github.com/opentracing-contrib/java-jdbc):question:

- operation name not customizable
- span tags not customizable
- `java.sql.Driver` approach requires `GlobalTracer`
- no support for `javax.sql.DataSource`

## Example

```java
DataSource dataSource = new DataSourceTracer(tracer)
.trace(originalDataSource);
```

## Features

- OpenTracing instrumentation for any `DataSource`
- Customizable operation name
- Customizable span tags/logs
- Convention over configuration (i.e. meaningful default values)

## Dependencies

- Java 8 or higher
- [OpenTracing](https://github.com/opentracing/opentracing-java)
- [datasource-proxy](https://github.com/ttddyy/datasource-proxy)

## Installation

Add the following dependency to your project:

```xml
<dependency>
<groupId>org.zalando</groupId>
<artifactId>opentracing-jdbc</artifactId>
<version>${opentracing-jdbc.version}</version>
</dependency>
```

## Configuration

```java
new DataSourceTracer(tracer)
.withOperationName(new CustomOperationName())
.withAdditionalSpanDecorator(new CustomSpanDecorator());
```

A new span will be started for each statement.

The following tags/logs are supported out of the box:

| Tag/Log Field | Decorator | Example |
|----------------------|----------------------------------|-----------------------------------|
| `component` | `ComponentSpanDecorator` | `JDBC` |
| `db.instance` | `DatabaseInstanceSpanDecorator` | `jdbc:postgres://localhost/db` |
| `db.statement` | `DatabaseStatementSpanDecorator` | `SELECT * FROM user WHERE id = ?` |
| `db.type` | `DatabaseTypeSpanDecorator` | `sql` |
| `db.user` | `DatabaseUserSpanDecorator` | `root` |
| `peer.address` | `PeerSpanDecorator` | `postgres://localhost` |
| `peer.hostname` | `PeerSpanDecorator` | `localhost` |
| `peer.ipv4` | `PeerSpanDecorator` | `127.0.0.1` |
| `peer.ipv6` | `PeerSpanDecorator` | `::1` |
| `peer.port` | `PeerSpanDecorator` | `5432` |
| `span.kind` | `SpanKindSpanDecorator` | `client` |
| `error` | `ErrorSpanDecorator` | `true` |
| `error.kind` (log) | `ErrorSpanDecorator` | `SocketTimeoutException` |
| `error.object` (log) | `ErrorSpanDecorator` | (exception instance) |
| `message` (log) | `ErrorMessageSpanDecorator` | `Connection timed out` |
| `stack` (log) | `ErrorStackSpanDecorator` | `SocketTimeoutException at [...]` |

Custom `SpanDecorator` implementations that are registered using [Java's Service Provider Interface](https://docs.oracle.com/javase/tutorial/ext/basics/spi.html) mechanism will be picked up automatically by default.

### Operation Name

The operation name, by default, is derived from the `Statement`'s method that was used to execute it. Usually one of `execute`, `update`, `executeQuery`, `executeUpdate`, `executeBatch`, etc.

The `OperationName` interface can be implemented in order to customize the operation name:

```java
new DataSourceTracer(tracer)
.withOperationName((method, queries) ->
toSnakeCase(method.getName()));
```

Another alternative that is built-in is the `StoredProcedureOperationName` that
looks for queries with the format `SELECT * FROM my_function(..)` and will
extract the name of the function as the operation name.

```java
new DataSourceTracer(tracer)
.withOperationName(new StoredProcedureOperationName());
```

## Getting Help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's [Issue Tracker](../../issues).

## Getting Involved/Contributing

To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change. For
more details, check the [contribution guidelines](.github/CONTRIBUTING.md).
109 changes: 109 additions & 0 deletions opentracing-jdbc/opentracing-jdbc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.zalando</groupId>
<artifactId>opentracing-jdbc-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>opentracing-jdbc</artifactId>
<scm>
<url>https://github.com/zalando/opentracing-toolbox</url>
<connection>scm:git:[email protected]:zalando/opentracing-toolbox.git</connection>
<developerConnection>scm:git:[email protected]:zalando/opentracing-toolbox.git</developerConnection>
</scm>
<properties>
<slf4j.version>1.7.26</slf4j.version>
<junit-jupiter.version>5.5.1</junit-jupiter.version>
</properties>
<dependencies>
<!-- Common -->
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gag</groupId>
<artifactId>gag</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Functionally important -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
<version>0.33.0</version>
</dependency>
<dependency>
<groupId>net.ttddyy</groupId>
<artifactId>datasource-proxy</artifactId>
<version>1.5.1</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<version>0.33.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit f587563

Please sign in to comment.