use of fish.payara.opentracing.propagation.MapToTextMap 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.propagation.MapToTextMap in project Payara by payara.
the class ContextSetupProviderImpl method startConcurrentContextSpan.
private void startConcurrentContextSpan(ComponentInvocation invocation, InvocationContext handle) {
Tracer tracer = openTracing.getTracer(openTracing.getApplicationName(Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class)));
// Start a trace in the request tracing system
SpanBuilder builder = tracer.buildSpan("executeConcurrentContext");
// Check for propagated span
if (handle.getSpanContextMap() != null) {
@SuppressWarnings("unchecked") SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new MapToTextMap(handle.getSpanContextMap()));
if (spanContext != null) {
builder.asChildOf(spanContext);
// Check for the presence of a propagated parent operation name
try {
String operationName = ((RequestTraceSpanContext) spanContext).getBaggageItems().get("operation.name");
if (operationName != null) {
builder.withTag("Parent Operation Name", operationName);
}
} catch (ClassCastException cce) {
logger.log(Level.FINE, "ClassCastException caught converting Span Context", cce);
}
}
}
if (invocation != null) {
builder = builder.withTag("App Name", invocation.getAppName()).withTag("Component ID", invocation.getComponentId()).withTag("Module Name", invocation.getModuleName());
Object instance = invocation.getInstance();
if (instance != null) {
builder.withTag("Class Name", instance.getClass().getName());
}
}
builder.withTag("Thread Name", Thread.currentThread().getName());
tracer.activateSpan(builder.start());
}
Aggregations