Interface ExtendedSpanBuilder
- All Superinterfaces:
io.opentelemetry.api.trace.SpanBuilder
SpanBuilder with experimental APIs.-
Method Summary
Modifier and TypeMethodDescriptionsetParentFrom(io.opentelemetry.context.propagation.ContextPropagators propagators, Map<String, String> carrier) Extract a span context from the given carrier and set it as parent of the span forstartAndCall(SpanCallable)andstartAndRun(SpanRunnable).<T,E extends Throwable>
TstartAndCall(SpanCallable<T, E> spanCallable) Runs the givenSpanCallableinside of the span created by the givenSpanBuilder.<T,E extends Throwable>
TstartAndCall(SpanCallable<T, E> spanCallable, BiConsumer<io.opentelemetry.api.trace.Span, Throwable> handleException) Runs the givenSpanCallableinside of the span created by the givenSpanBuilder.<E extends Throwable>
voidstartAndRun(SpanRunnable<E> runnable) Runs the givenSpanRunnableinside of the span created by the givenSpanBuilder.<E extends Throwable>
voidstartAndRun(SpanRunnable<E> runnable, BiConsumer<io.opentelemetry.api.trace.Span, Throwable> handleException) Runs the givenSpanRunnableinside of the span created by the givenSpanBuilder.Methods inherited from interface io.opentelemetry.api.trace.SpanBuilder
addLink, addLink, setAllAttributes, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setNoParent, setParent, setSpanKind, setStartTimestamp, setStartTimestamp, startSpan
-
Method Details
-
setParentFrom
ExtendedSpanBuilder setParentFrom(io.opentelemetry.context.propagation.ContextPropagators propagators, Map<String, String> carrier) Extract a span context from the given carrier and set it as parent of the span forstartAndCall(SpanCallable)andstartAndRun(SpanRunnable).The span context will be extracted from the
carrier, which you usually get from HTTP headers of the metadata of a message you're processing.A typical usage would be:
ExtendedTracer.create(tracer) .setSpanKind(SpanKind.SERVER) .setParentFrom(propagators, carrier) .run("my-span", () -> { ... });- Parameters:
propagators- provide the propagators fromOpenTelemetry.getPropagators()carrier- the string map where to extract the span context from
-
startAndCall
Runs the givenSpanCallableinside of the span created by the givenSpanBuilder. The span will be ended at the end of theSpanCallable.If an exception is thrown by the
SpanCallable, the span will be marked as error, and the exception will be recorded.- Type Parameters:
T- the type of the resultE- the type of the exception- Parameters:
spanCallable- theSpanCallableto call- Returns:
- the result of the
SpanCallable - Throws:
E extends Throwable
-
startAndCall
<T,E extends Throwable> T startAndCall(SpanCallable<T, E> spanCallable, BiConsumer<io.opentelemetry.api.trace.Span, throws EThrowable> handleException) Runs the givenSpanCallableinside of the span created by the givenSpanBuilder. The span will be ended at the end of theSpanCallable.If an exception is thrown by the
SpanCallable, thehandleExceptionconsumer will be called, giving you the opportunity to handle the exception and span in a custom way, e.g. not marking the span as error.- Type Parameters:
T- the type of the resultE- the type of the exception- Parameters:
spanCallable- theSpanCallableto callhandleException- the consumer to call when an exception is thrown- Returns:
- the result of the
SpanCallable - Throws:
E extends Throwable
-
startAndRun
Runs the givenSpanRunnableinside of the span created by the givenSpanBuilder. The span will be ended at the end of theSpanRunnable.If an exception is thrown by the
SpanRunnable, the span will be marked as error, and the exception will be recorded.- Type Parameters:
E- the type of the exception- Parameters:
runnable- theSpanRunnableto run- Throws:
E extends Throwable
-
startAndRun
<E extends Throwable> void startAndRun(SpanRunnable<E> runnable, BiConsumer<io.opentelemetry.api.trace.Span, Throwable> handleException) throws ERuns the givenSpanRunnableinside of the span created by the givenSpanBuilder. The span will be ended at the end of theSpanRunnable.If an exception is thrown by the
SpanRunnable, thehandleExceptionconsumer will be called, giving you the opportunity to handle the exception and span in a custom way, e.g. not marking the span as error.- Type Parameters:
E- the type of the exception- Parameters:
runnable- theSpanRunnableto run- Throws:
E extends Throwable
-