|
21 | 21 | import io.helidon.common.context.Context; |
22 | 22 | import io.helidon.dbclient.DbClientServiceBase; |
23 | 23 | 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; |
24 | 28 | import io.helidon.tracing.config.SpanTracingConfig; |
25 | 29 | import io.helidon.tracing.config.TracingConfigUtil; |
26 | 30 |
|
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; |
32 | 31 |
|
33 | 32 | /** |
34 | 33 | * Tracing interceptor. |
35 | 34 | * This interceptor is added through Java Service loader. |
36 | 35 | */ |
37 | 36 | public class DbClientTracing extends DbClientServiceBase { |
38 | 37 |
|
| 38 | + private static final Tag<? super String> DBCLIENT_TAG = Tag.COMPONENT.create("dbclient"); |
| 39 | + |
39 | 40 | private DbClientTracing(Builder builder) { |
40 | 41 | super(builder); |
41 | 42 | } |
@@ -76,42 +77,37 @@ protected DbClientServiceContext apply(DbClientServiceContext serviceContext) { |
76 | 77 | } |
77 | 78 |
|
78 | 79 | 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); |
80 | 81 |
|
81 | 82 | // 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()); |
83 | 84 |
|
84 | 85 | context.get(SpanContext.class) |
85 | | - .ifPresent(spanBuilder::asChildOf); |
| 86 | + .ifPresent(spanBuilder::parent); |
86 | 87 |
|
87 | 88 | Span span = spanBuilder.start(); |
88 | 89 |
|
89 | | - span.setTag("db.operation", serviceContext.statementType().toString()); |
| 90 | + span.tag("db.operation", serviceContext.statementType().toString()); |
90 | 91 | if (spanConfig.logEnabled("statement", true)) { |
91 | | - Tags.DB_STATEMENT.set(span, serviceContext.statement()); |
| 92 | + Tag.DB_STATEMENT.create(serviceContext.statement()).apply(span); |
92 | 93 | } |
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); |
95 | 96 |
|
96 | 97 | serviceContext.statementFuture().thenAccept(nothing -> { |
97 | 98 | if (spanConfig.logEnabled("statement-finish", true)) { |
98 | | - span.log(Map.of("type", "statement")); |
| 99 | + span.addEvent("log", Map.of("type", "statement")); |
99 | 100 | } |
100 | 101 | }); |
101 | 102 |
|
102 | 103 | serviceContext.resultFuture().thenAccept(count -> { |
103 | 104 | if (spanConfig.logEnabled("result-finish", true)) { |
104 | | - span.log(Map.of("type", "result", |
| 105 | + span.addEvent("log", Map.of("type", "result", |
105 | 106 | "count", count)); |
106 | 107 | } |
107 | | - span.finish(); |
| 108 | + span.end(); |
108 | 109 | }).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); |
115 | 111 | return null; |
116 | 112 | }); |
117 | 113 |
|
|
0 commit comments