Skip to content

Commit

Permalink
Uses instrumenter as static import
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragagarwal561994 committed Apr 6, 2022
1 parent bcf46b5 commit 064fcbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0.ApacheHttpClientSingletons.instrumenter;
import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
import static java.util.logging.Level.FINE;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
Expand Down Expand Up @@ -144,9 +145,8 @@ public DelegatingRequestChannel(
@Override
public void sendRequest(HttpRequest request, EntityDetails entityDetails, HttpContext context)
throws HttpException, IOException {
if (ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, request)) {
wrappedFutureCallback.context =
ApacheHttpClientSingletons.instrumenter().start(parentContext, request);
if (instrumenter().shouldStart(parentContext, request)) {
wrappedFutureCallback.context = instrumenter().start(parentContext, request);
wrappedFutureCallback.httpRequest = request;
}

Expand Down Expand Up @@ -182,8 +182,7 @@ public void completed(T result) {
return;
}

ApacheHttpClientSingletons.instrumenter()
.end(context, httpRequest, getResponse(httpContext), null);
instrumenter().end(context, httpRequest, getResponse(httpContext), null);

if (parentContext == null) {
completeDelegate(result);
Expand All @@ -205,8 +204,7 @@ public void failed(Exception ex) {
}

// end span before calling delegate
ApacheHttpClientSingletons.instrumenter()
.end(context, httpRequest, getResponse(httpContext), ex);
instrumenter().end(context, httpRequest, getResponse(httpContext), ex);

if (parentContext == null) {
failDelegate(ex);
Expand All @@ -229,8 +227,7 @@ public void cancelled() {

// TODO (trask) add "canceled" span attribute
// end span before calling delegate
ApacheHttpClientSingletons.instrumenter()
.end(context, httpRequest, getResponse(httpContext), null);
instrumenter().end(context, httpRequest, getResponse(httpContext), null);

if (parentContext == null) {
cancelDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0.ApacheHttpClientSingletons.instrumenter;
import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
Expand Down Expand Up @@ -129,11 +130,11 @@ public static void methodEnter(
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, request)) {
if (!instrumenter().shouldStart(parentContext, request)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, request);
context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();
}

Expand Down Expand Up @@ -163,11 +164,11 @@ public static void methodEnter(
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, request)) {
if (!instrumenter().shouldStart(parentContext, request)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, request);
context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();

// Wrap the handler so we capture the status code
Expand Down Expand Up @@ -203,11 +204,11 @@ public static void methodEnter(
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, request)) {
if (!instrumenter().shouldStart(parentContext, request)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, request);
context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();

// Wrap the handler so we capture the status code
Expand Down Expand Up @@ -245,11 +246,11 @@ public static void methodEnter(
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
fullRequest = new RequestWithHost(host, request);
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, fullRequest)) {
if (!instrumenter().shouldStart(parentContext, fullRequest)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, fullRequest);
context = instrumenter().start(parentContext, fullRequest);
scope = context.makeCurrent();
}

Expand Down Expand Up @@ -283,11 +284,11 @@ public static void methodEnter(

Context parentContext = currentContext();
fullRequest = new RequestWithHost(host, request);
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, fullRequest)) {
if (!instrumenter().shouldStart(parentContext, fullRequest)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, fullRequest);
context = instrumenter().start(parentContext, fullRequest);
scope = context.makeCurrent();

// Wrap the handler so we capture the status code
Expand Down Expand Up @@ -328,11 +329,11 @@ public static void methodEnter(

Context parentContext = currentContext();
fullRequest = new RequestWithHost(host, request);
if (!ApacheHttpClientSingletons.instrumenter().shouldStart(parentContext, fullRequest)) {
if (!instrumenter().shouldStart(parentContext, fullRequest)) {
return;
}

context = ApacheHttpClientSingletons.instrumenter().start(parentContext, fullRequest);
context = instrumenter().start(parentContext, fullRequest);
scope = context.makeCurrent();

// Wrap the handler so we capture the status code
Expand Down

0 comments on commit 064fcbf

Please sign in to comment.