use of fish.payara.opentracing.OpenTracingService in project Payara by payara.
the class JavaEETransactionManagerSimplified method commit.
@Override
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
boolean acquiredlock = false;
try {
JavaEETransaction tx = transactions.get();
if (tx != null && tx.isLocalTx()) {
if (monitoringEnabled) {
// XXX acquireReadLock();
getDelegate().getReadLock().lock();
acquiredlock = true;
}
// commit local tx
tx.commit();
} else {
try {
// an XA transaction
getDelegate().commitDistributedTransaction();
} finally {
if (tx != null) {
((JavaEETransactionImpl) tx).onTxCompletion(true);
}
}
}
if (openTracingServiceProvider != null) {
OpenTracingService openTracingService = getOpenTracing();
if (openTracingService != null && openTracingService.isEnabled()) {
addJtaEventTraceLog(constructJTAEndSpanLog(tx), tx, openTracingService);
}
}
} finally {
// clear current thread's tx
setCurrentTransaction(null);
delegates.set(null);
if (acquiredlock) {
// XXX releaseReadLock();
getDelegate().getReadLock().unlock();
}
}
// END IASRI 4662745
}
use of fish.payara.opentracing.OpenTracingService in project Payara by payara.
the class InvocationContext method saveTracingContext.
private void saveTracingContext() {
ServiceLocator serviceLocator = Globals.getDefaultBaseServiceLocator();
if (serviceLocator != null) {
RequestTracingService requestTracing = serviceLocator.getService(RequestTracingService.class);
OpenTracingService openTracing = serviceLocator.getService(OpenTracingService.class);
// Check that there's actually a trace running
if (requestTracing != null && requestTracing.isRequestTracingEnabled() && requestTracing.isTraceInProgress() && openTracing != null) {
Tracer tracer = openTracing.getTracer(openTracing.getApplicationName(serviceLocator.getService(InvocationManager.class)));
SpanContext spanContext = null;
// Check if there's an active Span running
Span activeSpan = tracer.activeSpan();
if (activeSpan != null) {
// The traceId is likely incorrect at this point as it initialises as a random UUID
try {
((RequestTraceSpan) activeSpan).setTraceId(requestTracing.getConversationID());
} catch (ClassCastException cce) {
Logger.getLogger(InvocationContext.class).log(Level.FINE, "ClassCastException caught converting Span", cce);
}
spanContext = activeSpan.context();
} else {
// Create a new span context using the starting span as a parent - the request tracing service doesn't
// know about unfinished spans so we can't get the actual parent with the current impl
spanContext = new RequestTraceSpanContext(requestTracing.getConversationID(), requestTracing.getStartingTraceID());
}
// Check to see if we're using the mock tracer to prevent ClassCastExceptions
try {
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, new MapToTextMap(spanContextMap = new HashMap()));
} catch (ClassCastException cce) {
Logger.getLogger(InvocationContext.class).log(Level.FINE, "ClassCastException caught injecting SpanContext", cce);
}
}
}
}
use of fish.payara.opentracing.OpenTracingService in project Payara by payara.
the class TracedInterceptor method traceCdiCall.
/**
* If the tracing is enabled and possible for the invoked method, traces it's execution.
* If not, only executes the invocation context.
*
* @param invocationContext the context to be executed
* @return result of the invocation context execution.
* @throws Exception any execution thrown from the invocation context execution.
*/
@AroundInvoke
public Object traceCdiCall(final InvocationContext invocationContext) throws Exception {
LOG.fine(() -> "traceCdiCall(" + invocationContext + ")");
// Get the required HK2 services
final PayaraTracingServices payaraTracingServices = new PayaraTracingServices();
final OpenTracingService openTracing = payaraTracingServices.getOpenTracingService();
final InvocationManager invocationManager = payaraTracingServices.getInvocationManager();
// If Request Tracing is enabled, and this isn't a JaxRs method
if (//
openTracing == null || !openTracing.isEnabled() || isJaxRsMethod(invocationContext) || isWebServiceMethod(invocationContext, invocationManager)) {
// If request tracing was turned off, or this is a JaxRs method, just carry on
LOG.finest("The call is already monitored by some different component, proceeding the invocation.");
return invocationContext.proceed();
}
// Get the Traced annotation present on the method or class
final Traced traced = getAnnotation(beanManager, Traced.class, invocationContext);
// Get the enabled (value) variable from a config override, or from the annotation if there is no override
final boolean tracingEnabled = OpenTracingCdiUtils.getConfigOverrideValue(Traced.class, "value", invocationContext, boolean.class).orElse(traced.value());
// If we've explicitly been told not to trace the method: don't!
if (!tracingEnabled) {
LOG.finest("Tracing is not enabled, nothing to do.");
return invocationContext.proceed();
}
// If we *have* been told to, get the application's Tracer instance and start an active span.
final String applicationName = openTracing.getApplicationName(invocationManager, invocationContext);
final Tracer tracer = openTracing.getTracer(applicationName);
final String operationName = getOperationName(invocationContext, traced);
Span parentSpan = tracer.activeSpan();
final Span span = tracer.buildSpan(operationName).start();
try (Scope scope = tracer.scopeManager().activate(span)) {
try {
return invocationContext.proceed();
} catch (final Exception ex) {
LOG.log(Level.FINEST, "Setting the error to the active span ...", ex);
span.setTag(Tags.ERROR.getKey(), true);
final Map<String, Object> errorInfoMap = new HashMap<>();
errorInfoMap.put(Fields.EVENT, "error");
errorInfoMap.put(Fields.ERROR_OBJECT, ex.getClass().getName());
span.log(errorInfoMap);
throw ex;
}
} finally {
span.finish();
}
}
use of fish.payara.opentracing.OpenTracingService in project Payara by payara.
the class JavaEETransactionManagerSimplified method initJavaEETransaction.
private JavaEETransactionImpl initJavaEETransaction(int timeout) {
JavaEETransactionImpl tx;
// Do not need to use injection.
if (timeout > 0) {
tx = new JavaEETransactionImpl(timeout, this);
ScheduledFuture<?> scheduledFuture = scheduledTransactionManagerExecutor.schedule(tx, timeout, TimeUnit.SECONDS);
tx.setScheduledTimeoutFuture(scheduledFuture);
scheduledTransactionTimeouts.incrementAndGet();
} else {
tx = new JavaEETransactionImpl(this);
}
setCurrentTransaction(tx);
if (openTracingServiceProvider != null) {
OpenTracingService openTracingService = getOpenTracing();
if (openTracingService != null && openTracingService.isEnabled()) {
addJtaEventTraceLog(constructJTABeginSpanLog(tx), tx, openTracingService);
}
}
return tx;
}
use of fish.payara.opentracing.OpenTracingService in project Payara by payara.
the class JavaEETransactionManagerSimplified method rollback.
@Override
public void rollback() throws IllegalStateException, SecurityException, SystemException {
boolean acquiredlock = false;
try {
JavaEETransaction tx = transactions.get();
if (tx != null && tx.isLocalTx()) {
if (monitoringEnabled) {
// XXX acquireReadLock();
getDelegate().getReadLock().lock();
acquiredlock = true;
}
// rollback local tx
tx.rollback();
} else {
try {
// an XA transaction
getDelegate().rollbackDistributedTransaction();
} finally {
if (tx != null) {
((JavaEETransactionImpl) tx).onTxCompletion(false);
}
}
}
if (openTracingServiceProvider != null) {
OpenTracingService openTracingService = getOpenTracing();
if (openTracingService != null && openTracingService.isEnabled()) {
addJtaEventTraceLog(constructJTAEndSpanLog(tx), tx, openTracingService);
}
}
} finally {
// clear current thread's tx
setCurrentTransaction(null);
delegates.set(null);
if (acquiredlock) {
// XXX releaseReadLock();
getDelegate().getReadLock().unlock();
}
}
}
Aggregations