diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1d25a06..e07e609 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-java@v2 with: - java-version: '8' + java-version: '11' distribution: 'adopt' - uses: actions/cache@v2 with: @@ -34,7 +34,7 @@ jobs: path: '*/target/*.jar' retention-days: 1 publish: - if: ${{ (github.event_name != 'pull_request') && (github.repository == 'lucidsoftware/opentracing-jdbc') }} + if: ${{ (github.event_name != 'pull_request') && (github.repository == 'lucidsoftware/otel-jdbc') }} needs: build runs-on: ubuntu-20.04 steps: @@ -54,7 +54,7 @@ jobs: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} release: - if: ${{ startsWith(github.ref, 'refs/tags') && (github.repository == 'lucidsoftware/opentracing-jdbc') }} + if: ${{ startsWith(github.ref, 'refs/tags') && (github.repository == 'lucidsoftware/otel-jdbc') }} runs-on: ubuntu-latest needs: build steps: @@ -70,4 +70,4 @@ jobs: set -x tag="${GITHUB_REF#refs/tags/}" targets="jdbc/target/*.jar" - hub release create -a $targets -m "Release $tag" $tag \ No newline at end of file + hub release create -a $targets -m "Release $tag" $tag diff --git a/.gitignore b/.gitignore index ae0cc37..8f72330 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,8 @@ target/ target-*/ + +.metals/ +.bloop/ +.bsp/ +project/metals.sbt diff --git a/README.md b/README.md index 8552baa..af32d64 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -# OpenTracing for JDBC +# OpenTelemetry for JDBC -[![Build Status](https://travis-ci.com/lucidsoftware/opentracing-jdbc.svg)](https://travis-ci.com/lucidsoftware/opentracing-jdbc) -![Maven Version](https://img.shields.io/maven-central/v/com.lucidchart/opentracing-jdbc.svg) +![Maven Version](https://img.shields.io/maven-central/v/com.lucidchart/otel-jdbc.svg) ## Install -Published as the `com.lucidchart:opentracing-jdbc` artifact. +Published as the `com.lucidchart:otel-jdbc` artifact. ## Example ```java -import io.opentracing.contrib.jdbc.*; +import com.lucidchart.otel.jdbc.*; import java.net.InetAddress; import java.nio.ByteBuffer; diff --git a/build.sbt b/build.sbt index 392a099..14d62f7 100644 --- a/build.sbt +++ b/build.sbt @@ -9,18 +9,21 @@ inScope(Global)(Seq( sys.env.getOrElse("SONATYPE_PASSWORD", "" )), crossPaths := false, - developers += Developer("pauldraper", "Paul Draper", "paulddraper@gmail.com", url("https://github.com/pauldraper")), - homepage := Some(url("https://git.lucidchart.com/lucidsoftware/opentracing-playframework")), + developers ++= List( + Developer("lucidsoftware", "Lucid Software, Inc.", "support@lucid.co", url("https://lucid.co")), + Developer("tmccombs", "Thayne McCombs", "thayne@lucid.co", url("https://github.com/tmccombs")), + ), + homepage := Some(url("https://git.lucidchart.com/lucidsoftware/otel-jdbc")), licenses += "Apache 2.0 License" -> url("https://www.apache.org/licenses/LICENSE-2.0"), organization := "com.lucidchart", - organizationHomepage := Some(url("http://opentracing.io/")), - organizationName := "OpenTracing", + organizationHomepage := Some(url("http://lucid.co/")), + organizationName := "Lucid Software, Inc.", scmInfo := Some(ScmInfo( - url("https://github.com/lucidsoftware/opentracing-jdbc"), - "scm:git:git@github.com:lucidsoftware/opentracing-jdbc.git" + url("https://github.com/lucidsoftware/otel-jdbc"), + "scm:git:git@github.com:lucidsoftware/otel-jdbc.git" )), - startYear := Some(2017), + startYear := Some(2024), version := sys.props.getOrElse("build.version", "0-SNAPSHOT") )) -skip in publish := true +publish / skip := true diff --git a/jdbc/build.sbt b/jdbc/build.sbt index 35b21c8..70ef721 100644 --- a/jdbc/build.sbt +++ b/jdbc/build.sbt @@ -1,9 +1,9 @@ libraryDependencies ++= Seq( - "com.lucidchart" % "opentracing-thread-context" % "0.5", - "io.opentracing" % "opentracing-api" % "0.31.0", - "io.opentracing" % "opentracing-util" % "0.31.0", - "p6spy" % "p6spy" % "3.9.1" + "io.opentelemetry" % "opentelemetry-bom" % "1.41.0", + "io.opentelemetry" % "opentelemetry-api" % "1.41.0", + "io.opentelemetry.semconv" % "opentelemetry-semconv" % "1.27.0-alpha", + "p6spy" % "p6spy" % "3.9.1", ) -moduleName := s"opentracing-${name.value}" +moduleName := s"otel-${name.value}" publishTo := sonatypePublishToBundle.value diff --git a/jdbc/src/main/java/co/lucid/otel/jdbc/JdbcPeer.java b/jdbc/src/main/java/co/lucid/otel/jdbc/JdbcPeer.java new file mode 100644 index 0000000..6fbfb02 --- /dev/null +++ b/jdbc/src/main/java/co/lucid/otel/jdbc/JdbcPeer.java @@ -0,0 +1,9 @@ +package co.lucid.otel.jdbc; + +public class JdbcPeer { + + public String name; + public String ip; + public Long port; + +} diff --git a/jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanConnectionWrapper.java b/jdbc/src/main/java/co/lucid/otel/jdbc/SpanConnectionWrapper.java similarity index 58% rename from jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanConnectionWrapper.java rename to jdbc/src/main/java/co/lucid/otel/jdbc/SpanConnectionWrapper.java index dbbaf31..c697065 100644 --- a/jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanConnectionWrapper.java +++ b/jdbc/src/main/java/co/lucid/otel/jdbc/SpanConnectionWrapper.java @@ -1,23 +1,23 @@ -package io.opentracing.contrib.jdbc; +package co.lucid.otel.jdbc; import com.p6spy.engine.common.ConnectionInformation; import com.p6spy.engine.event.JdbcEventListener; import com.p6spy.engine.wrapper.ConnectionWrapper; -import io.opentracing.Tracer; -import io.opentracing.util.GlobalTracer; -import io.opentracing.threadcontext.ContextSpan; +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import java.sql.Connection; public class SpanConnectionWrapper { public static SpanConnectionWrapper createDefault(JdbcPeer peer) { - return new SpanConnectionWrapper(GlobalTracer.get(), ContextSpan.DEFAULT, peer); + return new SpanConnectionWrapper(GlobalOpenTelemetry.getTracer("co.lucid.otel.jdbc"), peer); } private final JdbcEventListener eventListener; - public SpanConnectionWrapper(Tracer tracer, ContextSpan contextSpan, JdbcPeer peer) { - this.eventListener = new SpanEventListener(tracer, contextSpan, peer); + public SpanConnectionWrapper(Tracer tracer, JdbcPeer peer) { + this.eventListener = new SpanEventListener(tracer, peer); } public Connection wrap(Connection delegate) { @@ -27,5 +27,4 @@ public Connection wrap(Connection delegate) { ConnectionInformation.fromTestConnection(delegate) ); } - } diff --git a/jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanEventListener.java b/jdbc/src/main/java/co/lucid/otel/jdbc/SpanEventListener.java similarity index 58% rename from jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanEventListener.java rename to jdbc/src/main/java/co/lucid/otel/jdbc/SpanEventListener.java index b806d88..b0096f2 100644 --- a/jdbc/src/main/java/io/opentracing/contrib/jdbc/SpanEventListener.java +++ b/jdbc/src/main/java/co/lucid/otel/jdbc/SpanEventListener.java @@ -1,15 +1,14 @@ -package io.opentracing.contrib.jdbc; +package co.lucid.otel.jdbc; import com.p6spy.engine.common.PreparedStatementInformation; import com.p6spy.engine.common.StatementInformation; import com.p6spy.engine.event.JdbcEventListener; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.noop.NoopSpan; -import io.opentracing.tag.Tags; -import io.opentracing.threadcontext.ContextSpan; -import java.io.PrintWriter; -import java.io.StringWriter; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.semconv.SemanticAttributes; +import io.opentelemetry.semconv.NetworkAttributes; import java.sql.Driver; import java.sql.SQLException; import java.time.Instant; @@ -18,16 +17,15 @@ public class SpanEventListener extends JdbcEventListener { - private final ContextSpan spanContext; private final Tracer tracer; private final JdbcPeer peer; - public SpanEventListener(Tracer tracer, ContextSpan spanContext, JdbcPeer peer) { - this.spanContext = spanContext; + public SpanEventListener(Tracer tracer, JdbcPeer peer) { this.tracer = tracer; this.peer = peer; } + @Override public void onAfterExecute(StatementInformation statementInformation, long timeElapsedNanos, String sql, SQLException e) { onAfterExecute("execute", statementInformation, timeElapsedNanos, e); @@ -62,38 +60,30 @@ private void onAfterExecute(String type, StatementInformation statementInformati Instant end = Instant.now(); Instant start = end.minusNanos(timeElapsedNanos); String sql = statementInformation.getSql(); - Span parentSpan = spanContext.get() != NoopSpan.INSTANCE ? spanContext.get() : null; - Span span = tracer.buildSpan(String.format("SQL %s %s", type, new Scanner(sql).next())) - .asChildOf(parentSpan) - .withStartTimestamp(TimeUnit.SECONDS.toMicros(start.getEpochSecond()) + TimeUnit.NANOSECONDS.toMicros(start.getNano())) - .start(); - Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); + var span = tracer.spanBuilder(String.format("SQL %s %s", type, new Scanner(sql).next())) + .setStartTimestamp(start) + .setAttribute(SemanticAttributes.DB_STATEMENT, sql) + .setSpanKind(SpanKind.CLIENT) + .startSpan(); if (peer.name != null) { - Tags.PEER_SERVICE.set(span, peer.name); - } - if (peer.ipv4 != null) { - Tags.PEER_HOST_IPV4.set(span, peer.ipv4); + span.setAttribute(SemanticAttributes.PEER_SERVICE, peer.name); } - if (peer.ipv6 != null) { - Tags.PEER_HOST_IPV6.set(span, peer.ipv6); + if (peer.ip != null) { + span.setAttribute(NetworkAttributes.NETWORK_PEER_ADDRESS, peer.ip); } if (peer.port != null) { - Tags.PEER_PORT.set(span, peer.port); + span.setAttribute(NetworkAttributes.NETWORK_PEER_PORT, peer.port); } Driver driver = statementInformation.getConnectionInformation().getDriver(); if (driver != null) { - span.setTag("jdbc.driver", driver.getClass().getName()); + span.setAttribute(SemanticAttributes.DB_JDBC_DRIVER_CLASSNAME, driver.getClass().getName()); } - span.setTag("jdbc.query", sql); + if (e != null) { - Tags.ERROR.set(span, true); - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - span.setTag("error.message", e.getMessage() + ". SqlState: " + e.getSQLState()+ ". ErrorCode: " +e.getErrorCode()); - span.setTag("error.stack", sw.toString()); + span.recordException(e); + span.setStatus(StatusCode.ERROR, e.getMessage() + ". SqlState: " + e.getSQLState() + ". ErrorCode: " + e.getErrorCode()); } - span.finish(TimeUnit.SECONDS.toMicros(end.getEpochSecond()) + TimeUnit.NANOSECONDS.toMicros(end.getNano())); + span.end(end); } } diff --git a/jdbc/src/main/java/io/opentracing/contrib/jdbc/JdbcPeer.java b/jdbc/src/main/java/io/opentracing/contrib/jdbc/JdbcPeer.java deleted file mode 100644 index 877c766..0000000 --- a/jdbc/src/main/java/io/opentracing/contrib/jdbc/JdbcPeer.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.opentracing.contrib.jdbc; - -public class JdbcPeer { - - public String name; - public Integer ipv4; - public String ipv6; - public Integer port; - -} diff --git a/project/build.properties b/project/build.properties index 6adcdc7..ee4c672 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.3 +sbt.version=1.10.1