use of io.opentracing.Tracer in project wildfly-swarm by wildfly-swarm.
the class HealthServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Tracer tracer = GlobalTracer.get();
SpanContext context = (SpanContext) req.getAttribute(SERVER_SPAN_CONTEXT);
tracer.buildSpan("health-check-1").asChildOf(context).startActive(true).close();
resp.getWriter().write("alive");
}
use of io.opentracing.Tracer in project wildfly-swarm by wildfly-swarm.
the class SimpleServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Tracer tracer = GlobalTracer.get();
SpanContext context = (SpanContext) req.getAttribute(SERVER_SPAN_CONTEXT);
tracer.buildSpan("business-operation-1").asChildOf(context).startActive(true).close();
resp.getWriter().write("world");
}
use of io.opentracing.Tracer in project ballerina by ballerina-lang.
the class OpenTracerBallerinaWrapper method startSpan.
/**
* Method to start a span using parent span context.
*
* @param serviceName name of the service the span should belong to
* @param spanName name of the span
* @param tags key value paired tags to attach to the span
* @param referenceType type of reference to any parent span
* @param parentSpanContext map of the parent span context
* @return unique id of the created span
*/
public String startSpan(String serviceName, String spanName, Map<String, String> tags, ReferenceType referenceType, Map<String, SpanContext> parentSpanContext) {
if (enabled) {
Map<String, Span> spanMap = new HashMap<>();
Map<String, SpanContext> spanContextMap = new HashMap<>();
Map<String, Tracer> tracers = tracerStore.getTracers(serviceName);
tracers.forEach((tracerName, tracer) -> {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(spanName);
for (Map.Entry<String, String> tag : tags.entrySet()) {
spanBuilder = spanBuilder.withTag(tag.getKey(), tag.getValue());
}
if (parentSpanContext != null && !parentSpanContext.isEmpty()) {
spanBuilder = setParent(referenceType, parentSpanContext, spanBuilder, tracerName);
}
Span span = spanBuilder.start();
spanMap.put(tracerName, span);
spanContextMap.put(tracerName, span.context());
});
String spanId = UUID.randomUUID().toString();
spanStore.addSpan(spanId, spanMap);
spanStore.addSpanContext(spanId, spanContextMap);
return spanId;
} else {
return null;
}
}
use of io.opentracing.Tracer in project ballerina by ballerina-lang.
the class OpenTracerBallerinaWrapper method inject.
/**
* Method to inject the span context of a span into a map carrier.
*
* @param spanId the span Id of the span to be injected
* @return the map carrier holding the span context
*/
public Map<String, String> inject(String spanId) {
if (enabled) {
Map<String, String> carrierMap = new HashMap<>();
Map<String, Span> activeSpanMap = spanStore.getSpan(spanId);
for (Map.Entry<String, Span> activeSpanEntry : activeSpanMap.entrySet()) {
Map<String, Tracer> tracers = tracerStore.getTracers(DEFAULT_TRACER);
Tracer tracer = tracers.get(activeSpanEntry.getKey());
if (tracer != null && activeSpanEntry.getValue() != null) {
tracer.inject(activeSpanEntry.getValue().context(), Format.Builtin.HTTP_HEADERS, new RequestInjector(carrierMap));
}
}
return carrierMap;
} else {
return Collections.emptyMap();
}
}
use of io.opentracing.Tracer in project ballerina by ballerina-lang.
the class OpenTracerManager method startSpan.
@Override
public Map<String, Object> startSpan(long invocationId, String spanName, Map<String, ?> spanContextMap, Map<String, String> tags, String serviceName) {
Map<String, Object> spanMap = new HashMap<>();
Map<String, Tracer> tracers = tracerStore.getTracers(serviceName);
for (Map.Entry spanContextEntry : spanContextMap.entrySet()) {
Tracer tracer = tracers.get(spanContextEntry.getKey().toString());
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(spanName);
for (Map.Entry<String, String> tag : tags.entrySet()) {
spanBuilder = spanBuilder.withTag(tag.getKey(), tag.getValue());
}
if (spanContextEntry.getValue() != null) {
spanBuilder = spanBuilder.asChildOf((SpanContext) spanContextEntry.getValue());
}
Span span = spanBuilder.start();
spanMap.put(spanContextEntry.getKey().toString(), span);
}
return spanMap;
}
Aggregations