Skip to content

Commit

Permalink
fix spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
jandro996 committed Nov 4, 2024
1 parent 09766b9 commit 85bd34a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ public void methodAdvice(MethodTransformer transformer) {
public static class UriRequestAdvice {
@Advice.OnMethodEnter()
public static AgentScope methodEnter(@Advice.Argument(0) final HttpUriRequest request) {
try{
try {
return HelperMethods.doMethodEnter(request);
} catch (BlockingException e) {
HelperMethods.onBlockingRequest();
// re-throw blocking exceptions
throw e;
} catch (Throwable e) {
// suppress anything else
ExceptionLogger.LOGGER.debug(
"datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientInstrumentation", e);
return null;
}
HelperMethods.onBlockingRequest();
// re-throw blocking exceptions
throw e;
} catch (Throwable e) {
// suppress anything else
ExceptionLogger.LOGGER.debug(
"datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientInstrumentation", e);
return null;
}
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand All @@ -190,11 +190,12 @@ public static AgentScope methodEnter(
readOnly = false)
Object handler) {

try{
try {
final AgentScope scope = HelperMethods.doMethodEnter(request);
// Wrap the handler so we capture the status code
if (null != scope && handler instanceof ResponseHandler) {
handler = new WrappingStatusSettingResponseHandler(scope.span(), (ResponseHandler) handler);
handler =
new WrappingStatusSettingResponseHandler(scope.span(), (ResponseHandler) handler);
}
return scope;
} catch (BlockingException e) {
Expand All @@ -207,7 +208,6 @@ public static AgentScope methodEnter(
"datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientInstrumentation", e);
return null;
}

}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand All @@ -223,22 +223,22 @@ public static class RequestAdvice {
@Advice.OnMethodEnter()
public static AgentScope methodEnter(
@Advice.Argument(0) final HttpHost host, @Advice.Argument(1) final HttpRequest request) {
try{
try {
if (request instanceof HttpUriRequest) {
return HelperMethods.doMethodEnter((HttpUriRequest) request);
} else {
return HelperMethods.doMethodEnter(host, request);
}
} catch (BlockingException e) {
HelperMethods.onBlockingRequest();
// re-throw blocking exceptions
throw e;
} catch (Throwable e) {
// suppress anything else
HelperMethods.onBlockingRequest();
// re-throw blocking exceptions
throw e;
} catch (Throwable e) {
// suppress anything else
ExceptionLogger.LOGGER.debug(
"datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientInstrumentation", e);
return null;
}
"datadog.trace.instrumentation.apachehttpclient.ApacheHttpClientInstrumentation", e);
return null;
}
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand All @@ -262,7 +262,7 @@ public static AgentScope methodEnter(
typing = Assigner.Typing.DYNAMIC,
readOnly = false)
Object handler) {
try{
try {
final AgentScope scope;
if (request instanceof HttpUriRequest) {
scope = HelperMethods.doMethodEnter((HttpUriRequest) request);
Expand All @@ -271,7 +271,8 @@ public static AgentScope methodEnter(
}
// Wrap the handler so we capture the status code
if (null != scope && handler instanceof ResponseHandler) {
handler = new WrappingStatusSettingResponseHandler(scope.span(), (ResponseHandler) handler);
handler =
new WrappingStatusSettingResponseHandler(scope.span(), (ResponseHandler) handler);
}
return scope;
} catch (BlockingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void doMethodExit(
}
}

public static void onBlockingRequest(){
public static void onBlockingRequest() {
CallDepthThreadLocalMap.reset(HttpClient.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void methodAdvice(MethodTransformer transformer) {
public static class RequestAdvice {
@Advice.OnMethodEnter()
public static AgentScope methodEnter(@Advice.Argument(0) final ClassicHttpRequest request) {
try{
try {
return HelperMethods.doMethodEnter(request);
} catch (BlockingException e) {
HelperMethods.onBlockingRequest();
Expand Down Expand Up @@ -145,8 +145,8 @@ public static class HostRequestAdvice {
public static AgentScope methodEnter(
@Advice.Argument(0) final HttpHost host,
@Advice.Argument(1) final ClassicHttpRequest request) {
try{
return HelperMethods.doMethodEnter(host,request);
try {
return HelperMethods.doMethodEnter(host, request);
} catch (BlockingException e) {
HelperMethods.onBlockingRequest();
// re-throw blocking exceptions
Expand Down Expand Up @@ -181,7 +181,7 @@ public static AgentScope methodEnter(
typing = Assigner.Typing.DYNAMIC,
readOnly = false)
Object handler) {
try{
try {
final AgentScope scope = HelperMethods.doMethodEnter(host, request);
// Wrap the handler so we capture the status code
if (null != scope && handler instanceof HttpClientResponseHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void doMethodExit(
}
}

public static void onBlockingRequest(){
public static void onBlockingRequest() {
CallDepthThreadLocalMap.reset(HttpClient.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.google.auto.service.AutoService;
import datadog.trace.bootstrap.ExceptionLogger;
import datadog.appsec.api.blocking.BlockingException;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
import datadog.trace.bootstrap.ExceptionLogger;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator;
Expand Down Expand Up @@ -58,7 +58,7 @@ public static class ExecAdvice {
@Advice.OnMethodEnter()
public static AgentScope methodEnter(@Advice.Argument(1) final HttpMethod httpMethod) {

try{
try {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(HttpClient.class);
if (callDepth > 0) {
return null;
Expand All @@ -81,7 +81,8 @@ public static AgentScope methodEnter(@Advice.Argument(1) final HttpMethod httpMe
throw e;
} catch (Throwable e) {
// suppress anything else
ExceptionLogger.LOGGER.debug("datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientInstrumentation", e);
ExceptionLogger.LOGGER.debug(
"datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientInstrumentation", e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import static datadog.trace.instrumentation.httpclient.JavaNetClientDecorator.DECORATE;

import datadog.appsec.api.blocking.BlockingException;
import datadog.trace.bootstrap.ExceptionLogger;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
import datadog.trace.bootstrap.ExceptionLogger;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
Expand All @@ -21,8 +21,9 @@ public class SendAsyncAdvice {
public static AgentScope methodEnter(
@Advice.Argument(value = 0) final HttpRequest httpRequest,
@Advice.Argument(value = 1, readOnly = false) HttpResponse.BodyHandler<?> bodyHandler) {
try{
// Here we avoid having the advice applied twice in case we have nested call of this intercepted
try {
// Here we avoid having the advice applied twice in case we have nested call of this
// intercepted
// method.
// In this particular case, in HttpClientImpl the send method is calling sendAsync under the
// hood and we do not want to instrument twice.
Expand Down Expand Up @@ -50,7 +51,6 @@ public static AgentScope methodEnter(
ExceptionLogger.LOGGER.debug("datadog.trace.instrumentation.httpclient.SendAsyncAdvice", e);
return null;
}

}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down

0 comments on commit 85bd34a

Please sign in to comment.