Muzzle doesn’t seem to like those helper classes there
Had to move them externally for muzzle to be happy.
This commit is contained in:
parent
fc30b4c5bb
commit
452a619b4b
|
@ -7,12 +7,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -35,7 +31,7 @@ public final class ContinuationInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
getClass().getName() + "$ResumeAdvice$BlockWrapper",
|
||||
packageName + ".BlockWrapper",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -50,45 +46,12 @@ public final class ContinuationInstrumentation extends Instrumenter.Default {
|
|||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void wrap(@Advice.Argument(value = 0, readOnly = false) Block block) {
|
||||
final Span span = GlobalTracer.get().activeSpan();
|
||||
if (span != null) {
|
||||
block = BlockWrapper.wrapIfNeeded(block, span);
|
||||
}
|
||||
block = BlockWrapper.wrapIfNeeded(block, GlobalTracer.get().activeSpan());
|
||||
}
|
||||
|
||||
public void muzzleCheck(final PathBinding binding) {
|
||||
// This was added in 1.4. Added here to ensure consistency with other instrumentation.
|
||||
binding.getDescription();
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
public static class BlockWrapper implements Block {
|
||||
private final Block delegate;
|
||||
private final Span span;
|
||||
|
||||
private BlockWrapper(final Block delegate, final Span span) {
|
||||
assert span != null;
|
||||
this.delegate = delegate;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
}
|
||||
delegate.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public static Block wrapIfNeeded(final Block delegate, final Span span) {
|
||||
if (delegate instanceof BlockWrapper) {
|
||||
return delegate;
|
||||
}
|
||||
log.debug("Wrapping block {}", delegate);
|
||||
return new BlockWrapper(delegate, span);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
|
||||
import com.google.auto.service.AutoService;
|
||||
import datadog.trace.agent.tooling.Instrumenter;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
|
@ -36,7 +33,7 @@ public final class DefaultExecutionInstrumentation extends Instrumenter.Default
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
getClass().getName() + "$DelimitAdvice$ActionWrapper",
|
||||
packageName + ".ActionWrapper",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -55,50 +52,18 @@ public final class DefaultExecutionInstrumentation extends Instrumenter.Default
|
|||
public static void wrap(
|
||||
@Advice.Argument(value = 0, readOnly = false) Action<? super Throwable> onError,
|
||||
@Advice.Argument(value = 1, readOnly = false) Action<? super Continuation> segment) {
|
||||
final Span span = GlobalTracer.get().activeSpan();
|
||||
if (span != null) {
|
||||
/**
|
||||
* Here we pass along the span instead of a continuation because we aren't sure it won't be
|
||||
* used for both callbacks.
|
||||
* Here we pass along the span instead of a continuation because we aren't sure the callback
|
||||
* will actually be called.
|
||||
*/
|
||||
final Span span = GlobalTracer.get().activeSpan();
|
||||
onError = ActionWrapper.wrapIfNeeded(onError, span);
|
||||
segment = ActionWrapper.wrapIfNeeded(segment, span);
|
||||
}
|
||||
}
|
||||
|
||||
public void muzzleCheck(final PathBinding binding) {
|
||||
// This was added in 1.4. Added here to ensure consistency with other instrumentation.
|
||||
binding.getDescription();
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
public static class ActionWrapper<T> implements Action<T> {
|
||||
private final Action<T> delegate;
|
||||
private final Span span;
|
||||
|
||||
private ActionWrapper(final Action<T> delegate, final Span span) {
|
||||
assert span != null;
|
||||
this.delegate = delegate;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final T t) throws Exception {
|
||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
}
|
||||
delegate.execute(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Action<T> wrapIfNeeded(final Action<T> delegate, final Span span) {
|
||||
if (delegate instanceof ActionWrapper || span == null) {
|
||||
return delegate;
|
||||
}
|
||||
log.debug("Wrapping action task {}", delegate);
|
||||
return new ActionWrapper(delegate, span);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package datadog.trace.instrumentation.ratpack;
|
||||
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ratpack.func.Action;
|
||||
|
||||
@Slf4j
|
||||
public class ActionWrapper<T> implements Action<T> {
|
||||
private final Action<T> delegate;
|
||||
private final Span span;
|
||||
|
||||
private ActionWrapper(final Action<T> delegate, final Span span) {
|
||||
assert span != null;
|
||||
this.delegate = delegate;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final T t) throws Exception {
|
||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
}
|
||||
delegate.execute(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Action<T> wrapIfNeeded(final Action<T> delegate, final Span span) {
|
||||
if (delegate instanceof ActionWrapper || span == null) {
|
||||
return delegate;
|
||||
}
|
||||
log.debug("Wrapping action task {}", delegate);
|
||||
return new ActionWrapper(delegate, span);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package datadog.trace.instrumentation.ratpack;
|
||||
|
||||
import datadog.trace.context.TraceScope;
|
||||
import io.opentracing.Scope;
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.util.GlobalTracer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ratpack.func.Block;
|
||||
|
||||
@Slf4j
|
||||
public class BlockWrapper implements Block {
|
||||
private final Block delegate;
|
||||
private final Span span;
|
||||
|
||||
private BlockWrapper(final Block delegate, final Span span) {
|
||||
assert span != null;
|
||||
this.delegate = delegate;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||
if (scope instanceof TraceScope) {
|
||||
((TraceScope) scope).setAsyncPropagation(true);
|
||||
}
|
||||
delegate.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public static Block wrapIfNeeded(final Block delegate, final Span span) {
|
||||
if (delegate instanceof BlockWrapper || span == null) {
|
||||
return delegate;
|
||||
}
|
||||
log.debug("Wrapping block {}", delegate);
|
||||
return new BlockWrapper(delegate, span);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue