Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added opentracing-jdbc #332

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# OpenTracing Toolbox

![Build Status](https://github.com/zalando/opentracing-toolbox/workflows/Test/badge.svg)
[![Stability: Active](https://masterminds.github.io/stability/active.svg)](https://masterminds.github.io/stability/active.html)
![Build Status](https://github.com/zalando/opentracing-toolbox/workflows/Test/badge.svg)
[![Coverage Status](https://img.shields.io/coveralls/zalando/opentracing-toolbox/master.svg)](https://coveralls.io/r/zalando/opentracing-toolbox)
[![Code Quality](https://img.shields.io/codacy/grade/213bb62c41b34a32951929e37a2d20ac/master.svg)](https://www.codacy.com/app/whiskeysierra/opentracing-toolbox)
[![Code Quality](https://img.shields.io/codacy/grade/69e173024eec403797466e147a2051a3/master.svg)](https://www.codacy.com/app/whiskeysierra/opentracing-toolbox)
[![Release](https://img.shields.io/github/release/zalando/opentracing-toolbox.svg)](https://github.com/zalando/opentracing-toolbox/releases)
[![Maven Central](https://img.shields.io/maven-central/v/org.zalando/opentracing-toolbox.svg)](https://maven-badges.herokuapp.com/maven-central/org.zalando/opentracing-toolbox)
[![OpenTracing](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
Expand All @@ -21,9 +21,21 @@

## Modules

### OpenTracing Proxy

The `opentracing-proxy` module is a direct competitor to [opentracing-contrib/java-api-extensions](https://github.com/opentracing-contrib/java-api-extensions).

Go checkout out its [README](opentracing-proxy) for details.

### OpenTracing JDBC

The `opentracing-jdbc` module is a direct competitor to [opentracing-contrib/java-jdbc](https://github.com/opentracing-contrib/java-jdbc).

Go checkout out its [README](opentracing-jdbc) for details.

### Opentracing FlowID

The *opentracing-flowid* module replaces the former [`zalando/tracer`](https://github.com/zalando/tracer) library by providing support for the `X-Flow-ID` header propagation on top of OpenTracing.
The `opentracing-flowid` module replaces the former [`zalando/tracer`](https://github.com/zalando/tracer) library by providing support for the `X-Flow-ID` header propagation on top of OpenTracing.

Go checkout out its [README](opentracing-flowid) for details.

Expand Down
14 changes: 7 additions & 7 deletions opentracing-flowid/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# OpenTracing FlowID

[![Stability: Active](https://masterminds.github.io/stability/active.svg)](https://masterminds.github.io/stability/active.html)
![Build Status](https://github.com/zalando/opentracing-toolbox/workflows/Test/badge.svg)
[![Coverage Status](https://img.shields.io/coveralls/zalando/opentracing-toolbox/master.svg)](https://coveralls.io/r/zalando/opentracing-toolbox)
[![Code Quality](https://img.shields.io/codacy/grade/213bb62c41b34a32951929e37a2d20ac/master.svg)](https://www.codacy.com/app/whiskeysierra/opentracing-toolbox)
[![Code Quality](https://img.shields.io/codacy/grade/69e173024eec403797466e147a2051a3/master.svg)](https://www.codacy.com/app/whiskeysierra/opentracing-toolbox)
[![Javadoc](http://javadoc.io/badge/org.zalando/opentracing-flowid.svg)](http://www.javadoc.io/doc/org.zalando/opentracing-flowid)
[![Release](https://img.shields.io/github/release/zalando/opentracing-toolbox.svg)](https://github.com/zalando/opentracing-toolbox/releases)
[![Maven Central](https://img.shields.io/maven-central/v/org.zalando/opentracing-toolbox.svg)](https://maven-badges.herokuapp.com/maven-central/org.zalando/opentracing-toolbox)
[![Maven Central](https://img.shields.io/maven-central/v/org.zalando/opentracing-flowid.svg)](https://maven-badges.herokuapp.com/maven-central/org.zalando/opentracing-flowid)
[![OpenTracing](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/zalando/opentracing-toolbox/master/LICENSE)

Expand All @@ -28,9 +29,8 @@ This library historically originates from a closed-source implementation called

## Dependencies

- Java 8
- Any build tool using Maven Central, or direct download
- [OpenTracing](https://opentracing.io/guides/java/) 0.32.0 or higher
- Java 8 or higher
- [OpenTracing](https://github.com/opentracing/opentracing-java)
- Servlet Container (optional)
- Apache HTTP Client (optional)
- OkHttp (optional)
Expand All @@ -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
118 changes: 118 additions & 0 deletions opentracing-jdbc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# OpenTracing: JDBC

[![Stability: Active](https://masterminds.github.io/stability/active.svg)](https://masterminds.github.io/stability/active.html)
![Build Status](https://github.com/zalando/opentracing-toolbox/workflows/Test/badge.svg)
[![Coverage Status](https://img.shields.io/coveralls/zalando/opentracing-toolbox/master.svg)](https://coveralls.io/r/zalando/opentracing-toolbox)
[![Code Quality](https://img.shields.io/codacy/grade/69e173024eec403797466e147a2051a3/master.svg)](https://www.codacy.com/app/whiskeysierra/opentracing-toolbox)
[![Javadoc](http://javadoc.io/badge/org.zalando/opentracing-jdbc.svg)](http://www.javadoc.io/doc/org.zalando/opentracing-jdbc)
[![Release](https://img.shields.io/github/release/zalando/opentracing-toolbox.svg)](https://github.com/zalando/opentracing-toolbox/releases)
[![Maven Central](https://img.shields.io/maven-central/v/org.zalando/opentracing-jdbc.svg)](https://maven-badges.herokuapp.com/maven-central/org.zalando/opentracing-jdbc)
[![OpenTracing](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/zalando/opentracing-toolbox/master/LICENSE)

- **Technology stack**: Java 8+, OpenTracing, JDBC
- **Status**: Under development and used in production

## 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` | `db` |
| `db.statement` | `DatabaseStatementSpanDecorator` | `SELECT * FROM user WHERE id = ?` |
| `db.type` | `DatabaseTypeSpanDecorator` | `sql` |
| `db.user` | `DatabaseUserSpanDecorator` | `root` |
| `peer.address`¹ | `PeerAddressSpanDecorator` | `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 [...]` |

¹ Disabled by default due to security concerns (may expose passwords)

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