Skip to content

Commit e6cfd38

Browse files
authored
[4.x] - Migrate opentracing to Helidon Tracing (helidon-io#7708)
* Migrate to Helidon tracing --------- Signed-off-by: Dmitry Aleksandrov <dmitry.aleksandrov@oracle.com>
1 parent 312ea87 commit e6cfd38

4 files changed

Lines changed: 33 additions & 30 deletions

File tree

dbclient/tracing/pom.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@
3939
<artifactId>helidon-tracing-config</artifactId>
4040
</dependency>
4141
<dependency>
42-
<groupId>io.opentracing</groupId>
43-
<artifactId>opentracing-api</artifactId>
44-
</dependency>
45-
<dependency>
46-
<groupId>io.opentracing</groupId>
47-
<artifactId>opentracing-util</artifactId>
42+
<groupId>io.helidon.tracing</groupId>
43+
<artifactId>helidon-tracing</artifactId>
4844
</dependency>
4945
<dependency>
5046
<groupId>io.helidon.common.features</groupId>

dbclient/tracing/src/main/java/io/helidon/dbclient/tracing/DbClientTracing.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@
2121
import io.helidon.common.context.Context;
2222
import io.helidon.dbclient.DbClientServiceBase;
2323
import io.helidon.dbclient.DbClientServiceContext;
24+
import io.helidon.tracing.Span;
25+
import io.helidon.tracing.SpanContext;
26+
import io.helidon.tracing.Tag;
27+
import io.helidon.tracing.Tracer;
2428
import io.helidon.tracing.config.SpanTracingConfig;
2529
import io.helidon.tracing.config.TracingConfigUtil;
2630

27-
import io.opentracing.Span;
28-
import io.opentracing.SpanContext;
29-
import io.opentracing.Tracer;
30-
import io.opentracing.tag.Tags;
31-
import io.opentracing.util.GlobalTracer;
3231

3332
/**
3433
* Tracing interceptor.
3534
* This interceptor is added through Java Service loader.
3635
*/
3736
public class DbClientTracing extends DbClientServiceBase {
3837

38+
private static final Tag<? super String> DBCLIENT_TAG = Tag.COMPONENT.create("dbclient");
39+
3940
private DbClientTracing(Builder builder) {
4041
super(builder);
4142
}
@@ -76,42 +77,37 @@ protected DbClientServiceContext apply(DbClientServiceContext serviceContext) {
7677
}
7778

7879
Context context = serviceContext.context();
79-
@SuppressWarnings("resource") Tracer tracer = context.get(Tracer.class).orElseGet(GlobalTracer::get);
80+
@SuppressWarnings("resource") Tracer tracer = context.get(Tracer.class).orElseGet(Tracer::global);
8081

8182
// now if span context is missing, we build a span without a parent
82-
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(serviceContext.statementName());
83+
Span.Builder<?> spanBuilder = tracer.spanBuilder(serviceContext.statementName());
8384

8485
context.get(SpanContext.class)
85-
.ifPresent(spanBuilder::asChildOf);
86+
.ifPresent(spanBuilder::parent);
8687

8788
Span span = spanBuilder.start();
8889

89-
span.setTag("db.operation", serviceContext.statementType().toString());
90+
span.tag("db.operation", serviceContext.statementType().toString());
9091
if (spanConfig.logEnabled("statement", true)) {
91-
Tags.DB_STATEMENT.set(span, serviceContext.statement());
92+
Tag.DB_STATEMENT.create(serviceContext.statement()).apply(span);
9293
}
93-
Tags.COMPONENT.set(span, "dbclient");
94-
Tags.DB_TYPE.set(span, serviceContext.dbType());
94+
DBCLIENT_TAG.apply(span);
95+
Tag.DB_TYPE.create(serviceContext.dbType()).apply(span);
9596

9697
serviceContext.statementFuture().thenAccept(nothing -> {
9798
if (spanConfig.logEnabled("statement-finish", true)) {
98-
span.log(Map.of("type", "statement"));
99+
span.addEvent("log", Map.of("type", "statement"));
99100
}
100101
});
101102

102103
serviceContext.resultFuture().thenAccept(count -> {
103104
if (spanConfig.logEnabled("result-finish", true)) {
104-
span.log(Map.of("type", "result",
105+
span.addEvent("log", Map.of("type", "result",
105106
"count", count));
106107
}
107-
span.finish();
108+
span.end();
108109
}).exceptionally(throwable -> {
109-
Tags.ERROR.set(span, Boolean.TRUE);
110-
span.log(Map.of("event", "error",
111-
"error.kind", "Exception",
112-
"error.object", throwable,
113-
"message", throwable.getMessage()));
114-
span.finish();
110+
span.end(throwable);
115111
return null;
116112
});
117113

dbclient/tracing/src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
module io.helidon.dbclient.tracing {
2929

3030
requires io.helidon.tracing.config;
31-
requires io.opentracing.api;
32-
requires io.opentracing.util;
31+
requires io.helidon.tracing;
3332

3433
requires static io.helidon.common.features.api;
3534

3635
requires transitive io.helidon.dbclient;
3736

37+
3838
exports io.helidon.dbclient.tracing;
3939

4040
provides io.helidon.dbclient.spi.DbClientServiceProvider with io.helidon.dbclient.tracing.DbClientTracingProvider;

tracing/tracing/src/main/java/io/helidon/tracing/Tag.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,17 @@ public abstract class Tag<T> {
4343
* Status code that was returned.
4444
*/
4545
public static final TagSource<Integer> HTTP_STATUS = new NumberTagSource<>("http.status_code");
46+
47+
/**
48+
* Tag marking a Database type.
49+
*/
50+
public static final TagSource<String> DB_TYPE = new StringTagSource("db.type");
51+
52+
/**
53+
* Tag marking a Database statement.
54+
*/
55+
public static final TagSource<String> DB_STATEMENT = new StringTagSource("db.statement");
56+
4657
private final String key;
4758
private final T value;
4859

0 commit comments

Comments
 (0)