use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.
the class Ejb method shouldNotBeTraced.
/**
* This method itself should not be traced.
*
* @return The current baggage items
*/
@Override
@Traced(false)
public String shouldNotBeTraced() {
randomSleep();
Span activeSpan = tracer.activeSpan();
if (activeSpan != null) {
return getBaggageItems(activeSpan);
} else {
return "Nothing found!";
}
}
use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.
the class Ejb method annotatedMethod.
/**
* This method should be traced with a custom name
*
* @return The current baggage items
*/
@Override
@Traced(operationName = "customName")
public String annotatedMethod() {
randomSleep();
Span activeSpan = tracer.activeSpan();
if (activeSpan != null) {
return getBaggageItems(activeSpan);
} else {
return "Nothing found!";
}
}
use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.
the class JaxwsContainerRequestTracingFilter method filterResponse.
// After method invocation
@Override
public void filterResponse(Packet pipeRequest, Packet pipeResponse, MonitorContext monitorContext) {
// Try block so that we can always attach error info if there is any
try {
// If request tracing is enabled, and there is a trace in progress (which there should be!)
if (isTraceInProgress()) {
// Get the Traced annotation from the target method if CDI is initialised
Traced tracedAnnotation = getTraceAnnotation(monitorContext);
// pattern and a traced annotation set to true (via annotation or config override)
if (shouldTrace(pipeRequest) && shouldTrace(monitorContext, tracedAnnotation)) {
Span activeSpan = getTracer().scopeManager().activeSpan();
if (activeSpan == null) {
return;
}
HttpServletRequest httpRequest = (HttpServletRequest) pipeRequest.get(SERVLET_REQUEST);
try {
// Get and add the response status to the active span
Response.StatusType statusInfo = getResponseStatus(pipeRequest, pipeRequest);
activeSpan.setTag(HTTP_STATUS.getKey(), statusInfo.getStatusCode());
// If the response status is an error, add error information to the span
if (statusInfo.getFamily() == CLIENT_ERROR || statusInfo.getFamily() == SERVER_ERROR) {
activeSpan.setTag(ERROR.getKey(), true);
activeSpan.log(singletonMap("event", "error"));
// If there's an attached exception, add it to the span
Message message = pipeResponse.getMessage();
if (message != null && message.isFault()) {
activeSpan.log(singletonMap("error.object", getErrorObject(message)));
}
}
} finally {
activeSpan.finish();
Object scopeObj = httpRequest.getAttribute(Scope.class.getName());
if (scopeObj != null && scopeObj instanceof Scope) {
try (Scope scope = (Scope) scopeObj) {
httpRequest.removeAttribute(Scope.class.getName());
}
}
}
}
}
} finally {
// If there's an attached error on the response, log the exception
Message message = pipeResponse.getMessage();
if (message != null && message.isFault()) {
Object errorObject = getErrorObject(message);
if (errorObject != null) {
// TODO: have an actual detail formatter for fault
logger.log(SEVERE, getErrorObject(message).toString());
}
}
}
}
use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.
the class OpenTracingRequestEventListener method determineOperationName.
/**
* Helper method that determines what the operation name of the span.
* Depends on completely initialized resourceInfo.
*
* @return The name to use as the Span's operation name
*/
private String determineOperationName(final ContainerRequestContext request, final Traced tracedAnnotation) {
if (tracedAnnotation != null) {
String operationName = OpenTracingCdiUtils.getConfigOverrideValue(Traced.class, "operationName", resourceInfo, String.class).orElse(tracedAnnotation.operationName());
// followed by the method signature
if (operationName.equals("")) {
operationName = request.getMethod() + ":" + resourceInfo.getResourceClass().getCanonicalName() + "." + resourceInfo.getResourceMethod().getName();
}
return operationName;
}
// If there is no @Traced annotation
final Config config = getConfig();
// Determine if an operation name provider has been given
final Optional<String> operationNameProviderOptional = config == null ? Optional.empty() : config.getOptionalValue("mp.opentracing.server.operation-name-provider", String.class);
if (operationNameProviderOptional.isPresent()) {
final String operationNameProvider = operationNameProviderOptional.get();
final Path classLevelAnnotation = resourceInfo.getResourceClass().getAnnotation(Path.class);
final Path methodLevelAnnotation = resourceInfo.getResourceMethod().getAnnotation(Path.class);
// If the provider is set to "http-path" and the class-level @Path annotation is actually present
if (operationNameProvider.equals("http-path") && classLevelAnnotation != null) {
String operationName = request.getMethod() + ":";
if (classLevelAnnotation.value().startsWith("/")) {
operationName += classLevelAnnotation.value();
} else {
operationName += "/" + classLevelAnnotation.value();
}
// If the method-level @Path annotation is present, use its value
if (methodLevelAnnotation != null) {
if (methodLevelAnnotation.value().startsWith("/")) {
operationName += methodLevelAnnotation.value();
} else {
operationName += "/" + methodLevelAnnotation.value();
}
}
return operationName;
}
}
// If we haven't returned by now, just go with the default ("class-method")
return request.getMethod() + ":" + resourceInfo.getResourceClass().getCanonicalName() + "." + resourceInfo.getResourceMethod().getName();
}
use of org.eclipse.microprofile.opentracing.Traced in project quickstart by wildfly.
the class ExplicitlyTracedBean method getHello.
@Traced
public String getHello() {
Span prepareHelloSpan = tracer.buildSpan("prepare-hello").start();
String hello = "hello";
Span processHelloSpan = tracer.buildSpan("process-hello").start();
hello = hello.toUpperCase();
processHelloSpan.finish();
prepareHelloSpan.finish();
return hello;
}
Aggregations