Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3521: Only trace JAX-RS Client requests when tracing services are present #3961

Merged
merged 1 commit into from
May 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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