Skip to content

Commit

Permalink
Merge pull request #3961 from pdudits/payara-3521
Browse files Browse the repository at this point in the history
PAYARA-3521: Only trace JAX-RS Client requests when tracing services are present
  • Loading branch information
Pandrex247 authored May 20, 2019
2 parents 896eecd + 042256b commit 339f037
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
*/
package fish.payara.requesttracing.jaxrs.client.decorators;

import fish.payara.nucleus.requesttracing.RequestTracingService;
import fish.payara.opentracing.OpenTracingService;
import fish.payara.requesttracing.jaxrs.client.JaxrsClientRequestTracingFilter;
import java.security.KeyStore;
import java.util.Map;
Expand All @@ -51,6 +53,8 @@
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Configuration;

import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.Globals;
import org.glassfish.jersey.client.Initializable;
import org.glassfish.jersey.client.JerseyClientBuilder;

Expand Down Expand Up @@ -129,6 +133,10 @@ public ClientBuilder readTimeout(long timeout, TimeUnit unit) {

@Override
public Client build() {
if (!requestTracingPresent()) {
return clientBuilder.build();
}

// Register the Request Tracing filter
this.register(JaxrsClientRequestTracingFilter.class);

Expand All @@ -146,6 +154,20 @@ public Client build() {
return new JaxrsClientDecorator(client);
}

private boolean requestTracingPresent() {
try {
ServiceLocator serviceLocator = Globals.getDefaultBaseServiceLocator();
if (serviceLocator != null) {
RequestTracingService requestTracing = serviceLocator.getService(RequestTracingService.class);
OpenTracingService openTracing = serviceLocator.getService(OpenTracingService.class);
return requestTracing != null && openTracing != null;
}
} catch (Exception e) {
// means that we likely cannot do request tracing anyway
}
return false;
}

@Override
public Configuration getConfiguration() {
return this.clientBuilder.getConfiguration();
Expand Down

0 comments on commit 339f037

Please sign in to comment.