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

[3.x] - Migrate opentracing to Helidon Tracing #7709

Merged
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
8 changes: 2 additions & 6 deletions dbclient/tracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@
<artifactId>helidon-tracing-config</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<? super String> DBCLIENT_TAG = Tag.COMPONENT.create("dbclient");

private DbClientTracing(Builder builder) {
super(builder);
}
Expand Down Expand Up @@ -77,42 +77,38 @@ protected Single<DbClientServiceContext> 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;
});

Expand Down
6 changes: 3 additions & 3 deletions dbclient/tracing/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion tracing/tracing/src/main/java/io/helidon/tracing/Tag.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -43,6 +43,17 @@ public abstract class Tag<T> {
* Status code that was returned.
*/
public static final TagSource<Integer> HTTP_STATUS = new NumberTagSource<>("http.status_code");

/**
* Tag marking a Database type.
*/
public static final TagSource<String> DB_TYPE = new StringTagSource("db.type");

/**
* Tag marking a Database statement.
*/
public static final TagSource<String> DB_STATEMENT = new StringTagSource("db.statement");

private final String key;
private final T value;

Expand Down
Loading