Remove deprecated end() & endExceptionally() methods from BaseTracer (#2424)

This commit is contained in:
Mateusz Rzeszutek 2021-03-01 18:14:30 +01:00 committed by GitHub
parent d8e630a0a8
commit 163062d13e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 47 deletions

View File

@ -195,16 +195,6 @@ public abstract class BaseTracer {
end(Span.fromContext(context), endTimeNanos);
}
/**
* End span.
*
* @deprecated Use {@link #end(Context)} instead.
*/
@Deprecated
public void end(Span span) {
end(span, -1);
}
private void end(Span span, long endTimeNanos) {
if (endTimeNanos > 0) {
span.end(endTimeNanos, TimeUnit.NANOSECONDS);
@ -221,16 +211,6 @@ public abstract class BaseTracer {
endExceptionally(Span.fromContext(context), throwable, endTimeNanos);
}
/**
* End span.
*
* @deprecated Use {@link #endExceptionally(Context, Throwable)} instead.
*/
@Deprecated
public void endExceptionally(Span span, Throwable throwable) {
endExceptionally(span, throwable, -1);
}
private void endExceptionally(Span span, Throwable throwable, long endTimeNanos) {
span.setStatus(StatusCode.ERROR);
onError(span, unwrapThrowable(throwable));

View File

@ -36,7 +36,7 @@ public class TransportActionListener<T extends ActionResponse> implements Action
private final Context context;
public TransportActionListener(
ActionRequest actionRequest, ActionListener<T> listener, Context context) {
ActionRequest<?> actionRequest, ActionListener<T> listener, Context context) {
this.listener = listener;
this.context = context;
onRequest(actionRequest);
@ -123,7 +123,7 @@ public class TransportActionListener<T extends ActionResponse> implements Action
}
}
tracer().end(span);
tracer().end(context);
listener.onResponse(response);
}

View File

@ -124,7 +124,7 @@ public class TransportActionListener<T extends ActionResponse> implements Action
}
}
tracer().end(span);
tracer().end(context);
listener.onResponse(response);
}

View File

@ -15,7 +15,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
@ -85,19 +85,19 @@ public class GeodeInstrumentationModule extends InstrumentationModule {
public static void onEnter(
@Advice.This Region<?, ?> thiz,
@Advice.Origin Method method,
@Advice.Local("otelSpan") Span span,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (CallDepthThreadLocalMap.incrementCallDepth(Region.class) > 0) {
return;
}
span = tracer().startSpan(method.getName(), thiz, null);
scope = span.makeCurrent();
context = tracer().startSpan(method.getName(), thiz, null);
scope = context.makeCurrent();
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
@Advice.Thrown Throwable throwable,
@Advice.Local("otelSpan") Span span,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
return;
@ -106,9 +106,9 @@ public class GeodeInstrumentationModule extends InstrumentationModule {
CallDepthThreadLocalMap.reset(Region.class);
if (throwable != null) {
tracer().endExceptionally(span, throwable);
tracer().endExceptionally(context, throwable);
} else {
tracer().end(span);
tracer().end(context);
}
}
}
@ -119,19 +119,19 @@ public class GeodeInstrumentationModule extends InstrumentationModule {
@Advice.This Region<?, ?> thiz,
@Advice.Origin Method method,
@Advice.Argument(0) String query,
@Advice.Local("otelSpan") Span span,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (CallDepthThreadLocalMap.incrementCallDepth(Region.class) > 0) {
return;
}
span = tracer().startSpan(method.getName(), thiz, query);
scope = span.makeCurrent();
context = tracer().startSpan(method.getName(), thiz, query);
scope = context.makeCurrent();
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
@Advice.Thrown Throwable throwable,
@Advice.Local("otelSpan") Span span,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
return;
@ -140,9 +140,9 @@ public class GeodeInstrumentationModule extends InstrumentationModule {
CallDepthThreadLocalMap.reset(Region.class);
if (throwable != null) {
tracer().endExceptionally(span, throwable);
tracer().endExceptionally(context, throwable);
} else {
tracer().end(span);
tracer().end(context);
}
}
}

View File

@ -7,8 +7,8 @@ package io.opentelemetry.javaagent.instrumentation.geode;
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementInfo;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementSanitizer;
@ -23,7 +23,7 @@ public class GeodeTracer extends DatabaseClientTracer<Region<?, ?>, String, SqlS
return TRACER;
}
public Span startSpan(String operation, Region<?, ?> connection, String query) {
public Context startSpan(String operation, Region<?, ?> connection, String query) {
SqlStatementInfo sanitizedStatement = sanitizeStatement(query);
SpanBuilder span =
@ -37,7 +37,7 @@ public class GeodeTracer extends DatabaseClientTracer<Region<?, ?>, String, SqlS
setNetSemanticConvention(span, connection);
onStatement(span, connection, query, sanitizedStatement);
return span.startSpan();
return Context.current().with(span.startSpan());
}
@Override

View File

@ -38,22 +38,22 @@ public class LettuceFluxTerminationRunnable implements Consumer<Signal<?>>, Runn
private void finishSpan(boolean isCommandCancelled, Throwable throwable) {
if (context != null) {
Span span = Span.fromContext(context);
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
Span span = Span.fromContext(context);
span.setAttribute("lettuce.command.results.count", numResults);
if (isCommandCancelled) {
span.setAttribute("lettuce.command.cancelled", true);
}
}
if (throwable == null) {
tracer().end(span);
tracer().end(context);
} else {
tracer().endExceptionally(span, throwable);
tracer().endExceptionally(context, throwable);
}
} else {
LoggerFactory.getLogger(Flux.class)
.error(
"Failed to finish this.span, LettuceFluxTerminationRunnable cannot find this.span "
"Failed to end this.context, LettuceFluxTerminationRunnable cannot find this.context "
+ "because it probably wasn't started.");
}
}

View File

@ -49,17 +49,17 @@ public abstract class CompletionListener<T> {
span.setAttribute(DB_COMMAND_CANCELLED, true);
}
} else {
tracer().endExceptionally(span, e);
tracer().endExceptionally(context, e);
}
} catch (InterruptedException e) {
// Avoid swallowing InterruptedException
tracer().endExceptionally(span, e);
tracer().endExceptionally(context, e);
Thread.currentThread().interrupt();
} catch (Exception e) {
// This should never happen, just in case to make sure we cover all unexpected exceptions
tracer().endExceptionally(span, e);
tracer().endExceptionally(context, e);
} finally {
tracer().end(span);
tracer().end(context);
}
}