use of io.opentelemetry.api.trace.SpanBuilder in project wildfly by wildfly.
the class OpenTelemetryContainerFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) {
if (tracer != null) {
final boolean remoteContext = requestContext.getHeaders().keySet().stream().anyMatch(k -> W3CTraceContextPropagator.getInstance().fields().contains(k));
final UriInfo uriInfo = requestContext.getUriInfo();
final URI requestUri = uriInfo.getRequestUri();
final String method = requestContext.getMethod();
final String uri = uriInfo.getPath();
SpanBuilder spanBuilder = tracer.spanBuilder(method + " " + uri).setSpanKind(SpanKind.SERVER);
if (remoteContext) {
spanBuilder.setParent(openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), requestContext, new TextMapGetter<ContainerRequestContext>() {
@Override
public String get(ContainerRequestContext requestContext, String key) {
if (requestContext.getHeaders().containsKey(key)) {
return requestContext.getHeaders().get(key).get(0);
}
return null;
}
@Override
public Iterable<String> keys(ContainerRequestContext requestContext) {
return requestContext.getHeaders().keySet();
}
}));
} else {
spanBuilder.setNoParent();
}
Span serverSpan = spanBuilder.startSpan();
serverSpan.makeCurrent();
serverSpan.setAttribute(SemanticAttributes.HTTP_METHOD, method);
serverSpan.setAttribute(SemanticAttributes.HTTP_SCHEME, requestUri.getScheme());
serverSpan.setAttribute(SemanticAttributes.HTTP_HOST, requestUri.getHost() + ":" + requestUri.getPort());
serverSpan.setAttribute(SemanticAttributes.HTTP_TARGET, uri);
requestContext.setProperty(SERVER_SPAN, serverSpan);
}
}
use of io.opentelemetry.api.trace.SpanBuilder in project accumulo by apache.
the class TraceUtil method startSpan.
private static Span startSpan(Class<?> caller, String spanName, SpanKind kind, Map<String, String> attributes, TInfo tinfo) {
if (!enabled) {
return Span.getInvalid();
}
final String name = String.format(SPAN_FORMAT, caller.getSimpleName(), spanName);
final SpanBuilder builder = getTracer(getOpenTelemetry()).spanBuilder(name);
if (kind != null) {
builder.setSpanKind(kind);
}
if (attributes != null) {
attributes.forEach(builder::setAttribute);
}
if (tinfo != null) {
builder.setParent(getContext(tinfo));
}
return builder.startSpan();
}
Aggregations