diff --git a/dbclient/tracing/pom.xml b/dbclient/tracing/pom.xml index bd35e4ea517..70608209489 100644 --- a/dbclient/tracing/pom.xml +++ b/dbclient/tracing/pom.xml @@ -40,12 +40,8 @@ helidon-tracing-config - io.opentracing - opentracing-api - - - io.opentracing - opentracing-util + io.helidon.tracing + helidon-tracing io.helidon.dbclient diff --git a/dbclient/tracing/src/main/java/io/helidon/dbclient/tracing/DbClientTracing.java b/dbclient/tracing/src/main/java/io/helidon/dbclient/tracing/DbClientTracing.java index 4043550db83..e81c194abcc 100644 --- a/dbclient/tracing/src/main/java/io/helidon/dbclient/tracing/DbClientTracing.java +++ b/dbclient/tracing/src/main/java/io/helidon/dbclient/tracing/DbClientTracing.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,20 +23,20 @@ import io.helidon.config.Config; import io.helidon.dbclient.DbClientServiceContext; import io.helidon.dbclient.common.DbClientServiceBase; +import io.helidon.tracing.Span; +import io.helidon.tracing.SpanContext; +import io.helidon.tracing.Tag; +import io.helidon.tracing.Tracer; import io.helidon.tracing.config.SpanTracingConfig; import io.helidon.tracing.config.TracingConfigUtil; -import io.opentracing.Span; -import io.opentracing.SpanContext; -import io.opentracing.Tracer; -import io.opentracing.tag.Tags; -import io.opentracing.util.GlobalTracer; - /** * Tracing interceptor. * This interceptor is added through Java Service loader. */ public class DbClientTracing extends DbClientServiceBase { + private static final Tag DBCLIENT_TAG = Tag.COMPONENT.create("dbclient"); + private DbClientTracing(Builder builder) { super(builder); } @@ -77,42 +77,38 @@ protected Single apply(DbClientServiceContext serviceCon } Context context = serviceContext.context(); - Tracer tracer = context.get(Tracer.class).orElseGet(GlobalTracer::get); + Tracer tracer = context.get(Tracer.class).orElseGet(Tracer::global); // now if span context is missing, we build a span without a parent - Tracer.SpanBuilder spanBuilder = tracer.buildSpan(serviceContext.statementName()); + Span.Builder spanBuilder = tracer.spanBuilder(serviceContext.statementName()); context.get(SpanContext.class) - .ifPresent(spanBuilder::asChildOf); + .ifPresent(spanBuilder::parent); Span span = spanBuilder.start(); - span.setTag("db.operation", serviceContext.statementType().toString()); + span.tag("db.operation", serviceContext.statementType().toString()); if (spanConfig.logEnabled("statement", true)) { - Tags.DB_STATEMENT.set(span, serviceContext.statement()); + Tag.DB_STATEMENT.create(serviceContext.statement()).apply(span); } - Tags.COMPONENT.set(span, "dbclient"); - Tags.DB_TYPE.set(span, serviceContext.dbType()); + + DBCLIENT_TAG.apply(span); + Tag.DB_TYPE.create(serviceContext.dbType()).apply(span); serviceContext.statementFuture().thenAccept(nothing -> { if (spanConfig.logEnabled("statement-finish", true)) { - span.log(Map.of("type", "statement")); + span.addEvent("log", Map.of("type", "statement")); } }); serviceContext.resultFuture().thenAccept(count -> { if (spanConfig.logEnabled("result-finish", true)) { - span.log(Map.of("type", "result", + span.addEvent("log", Map.of("type", "result", "count", count)); } - span.finish(); + span.end(); }).exceptionally(throwable -> { - Tags.ERROR.set(span, Boolean.TRUE); - span.log(Map.of("event", "error", - "error.kind", "Exception", - "error.object", throwable, - "message", throwable.getMessage())); - span.finish(); + span.end(throwable); return null; }); diff --git a/dbclient/tracing/src/main/java/module-info.java b/dbclient/tracing/src/main/java/module-info.java index 348d8a7c663..021e01679e5 100644 --- a/dbclient/tracing/src/main/java/module-info.java +++ b/dbclient/tracing/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +25,10 @@ requires io.helidon.dbclient; requires io.helidon.tracing.config; - requires io.opentracing.api; - requires io.opentracing.util; + requires io.helidon.tracing; requires io.helidon.dbclient.common; + exports io.helidon.dbclient.tracing; provides DbClientServiceProvider with io.helidon.dbclient.tracing.DbClientTracingProvider; diff --git a/tracing/tracing/src/main/java/io/helidon/tracing/Tag.java b/tracing/tracing/src/main/java/io/helidon/tracing/Tag.java index a3c6231a11a..5f94b1ff50e 100644 --- a/tracing/tracing/src/main/java/io/helidon/tracing/Tag.java +++ b/tracing/tracing/src/main/java/io/helidon/tracing/Tag.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022 Oracle and/or its affiliates. + * Copyright (c) 2018, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,17 @@ public abstract class Tag { * Status code that was returned. */ public static final TagSource HTTP_STATUS = new NumberTagSource<>("http.status_code"); + + /** + * Tag marking a Database type. + */ + public static final TagSource DB_TYPE = new StringTagSource("db.type"); + + /** + * Tag marking a Database statement. + */ + public static final TagSource DB_STATEMENT = new StringTagSource("db.statement"); + private final String key; private final T value;