Class ExtendedDefaultTracer.NoopSpanBuilder
- java.lang.Object
-
- io.opentelemetry.api.incubator.trace.ExtendedDefaultTracer.NoopSpanBuilder
-
- All Implemented Interfaces:
ExtendedSpanBuilder,SpanBuilder
- Enclosing class:
- ExtendedDefaultTracer
private static final class ExtendedDefaultTracer.NoopSpanBuilder extends java.lang.Object implements ExtendedSpanBuilder
-
-
Field Summary
Fields Modifier and Type Field Description private SpanContextspanContext
-
Constructor Summary
Constructors Modifier Constructor Description privateNoopSpanBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtendedDefaultTracer.NoopSpanBuilderaddLink(SpanContext spanContext)Adds a link to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuilderaddLink(SpanContext spanContext, Attributes attributes)Adds a link to the newly createdSpan.(package private) static ExtendedDefaultTracer.NoopSpanBuildercreate()ExtendedDefaultTracer.NoopSpanBuildersetAllAttributes(Attributes attributes)Sets attributes to theSpanBuilder.<T> ExtendedDefaultTracer.NoopSpanBuildersetAttribute(AttributeKey<T> key, T value)Sets an attribute to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetAttribute(java.lang.String key, boolean value)Sets an attribute to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetAttribute(java.lang.String key, double value)Sets an attribute to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetAttribute(java.lang.String key, long value)Sets an attribute to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetAttribute(java.lang.String key, java.lang.String value)Sets an attribute to the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetNoParent()Sets the option to become a rootSpanfor a new trace.ExtendedDefaultTracer.NoopSpanBuildersetParent(Context context)Sets the parent to use from the specifiedContext.ExtendedDefaultTracer.NoopSpanBuildersetParentFrom(ContextPropagators propagators, java.util.Map<java.lang.String,java.lang.String> carrier)Extract a span context from the given carrier and set it as parent of the span forExtendedSpanBuilder.startAndCall(SpanCallable)andExtendedSpanBuilder.startAndRun(SpanRunnable).ExtendedDefaultTracer.NoopSpanBuildersetSpanKind(SpanKind spanKind)Sets theSpanKindfor the newly createdSpan.ExtendedDefaultTracer.NoopSpanBuildersetStartTimestamp(long startTimestamp, java.util.concurrent.TimeUnit unit)Sets an explicit start timestamp for the newly createdSpan.<T,E extends java.lang.Throwable>
TstartAndCall(SpanCallable<T,E> spanCallable)Runs the givenSpanCallableinside of the span created by the givenSpanBuilder.<T,E extends java.lang.Throwable>
TstartAndCall(SpanCallable<T,E> spanCallable, java.util.function.BiConsumer<Span,java.lang.Throwable> handleException)Runs the givenSpanCallableinside of the span created by the givenSpanBuilder.<E extends java.lang.Throwable>
voidstartAndRun(SpanRunnable<E> runnable)Runs the givenSpanRunnableinside of the span created by the givenSpanBuilder.<E extends java.lang.Throwable>
voidstartAndRun(SpanRunnable<E> runnable, java.util.function.BiConsumer<Span,java.lang.Throwable> handleException)Runs the givenSpanRunnableinside of the span created by the givenSpanBuilder.SpanstartSpan()Starts a newSpan.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder
setStartTimestamp
-
-
-
-
Field Detail
-
spanContext
@Nullable private SpanContext spanContext
-
-
Method Detail
-
create
static ExtendedDefaultTracer.NoopSpanBuilder create()
-
startSpan
public Span startSpan()
Description copied from interface:SpanBuilderStarts a newSpan.Users must manually call
Span.end()to end thisSpan.Does not install the newly created
Spanto the current Context.IMPORTANT: This method can be called only once per
SpanBuilderinstance and as the last method called. After this method is called calling any method is undefined behavior.Example of usage:
class MyClass { private final Tracer tracer; MyClass(OpenTelemetry openTelemetry) { tracer = openTelemetry.getTracer("com.example.rpc"); } void doWork(Span parent) { Span childSpan = tracer.spanBuilder("MyChildSpan") .setParent(Context.current().with(parent)) .startSpan(); childSpan.addEvent("my event"); try { doSomeWork(childSpan); // Manually propagate the new span down the stack. } finally { // To make sure we end the span even in case of an exception. childSpan.end(); // Manually end the span. } } }- Specified by:
startSpanin interfaceSpanBuilder- Returns:
- the newly created
Span.
-
setParent
public ExtendedDefaultTracer.NoopSpanBuilder setParent(Context context)
Description copied from interface:ExtendedSpanBuilderSets the parent to use from the specifiedContext. If not set, the value ofSpan.current()atSpanBuilder.startSpan()time will be used as parent.If no
Spanis available in the specifiedContext, the resultingSpanwill become a root instance, as ifSpanBuilder.setNoParent()had been called.If called multiple times, only the last specified value will be used. Observe that the state defined by a previous call to
SpanBuilder.setNoParent()will be discarded.- Specified by:
setParentin interfaceExtendedSpanBuilder- Specified by:
setParentin interfaceSpanBuilder- Parameters:
context- theContext.- Returns:
- this.
-
setParentFrom
public ExtendedDefaultTracer.NoopSpanBuilder setParentFrom(ContextPropagators propagators, java.util.Map<java.lang.String,java.lang.String> carrier)
Description copied from interface:ExtendedSpanBuilderExtract a span context from the given carrier and set it as parent of the span forExtendedSpanBuilder.startAndCall(SpanCallable)andExtendedSpanBuilder.startAndRun(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.- Specified by:
setParentFromin interfaceExtendedSpanBuilder- Parameters:
propagators- provide the propagators fromOpenTelemetry.getPropagators()carrier- the string map where to extract the span context from
-
setNoParent
public ExtendedDefaultTracer.NoopSpanBuilder setNoParent()
Description copied from interface:ExtendedSpanBuilderSets the option to become a rootSpanfor a new trace. If not set, the value ofSpan.current()atSpanBuilder.startSpan()time will be used as parent.Observe that any previously set parent will be discarded.
- Specified by:
setNoParentin interfaceExtendedSpanBuilder- Specified by:
setNoParentin interfaceSpanBuilder- Returns:
- this.
-
addLink
public ExtendedDefaultTracer.NoopSpanBuilder addLink(SpanContext spanContext)
Description copied from interface:ExtendedSpanBuilderAdds a link to the newly createdSpan.Links are used to link
Spans in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces or the same trace.Implementations may ignore calls with an invalid span context.
- Specified by:
addLinkin interfaceExtendedSpanBuilder- Specified by:
addLinkin interfaceSpanBuilder- Parameters:
spanContext- the context of the linkedSpan.- Returns:
- this.
-
addLink
public ExtendedDefaultTracer.NoopSpanBuilder addLink(SpanContext spanContext, Attributes attributes)
Description copied from interface:ExtendedSpanBuilderAdds a link to the newly createdSpan.Links are used to link
Spans in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces or the same trace.Implementations may ignore calls with an invalid span context.
- Specified by:
addLinkin interfaceExtendedSpanBuilder- Specified by:
addLinkin interfaceSpanBuilder- Parameters:
spanContext- the context of the linkedSpan.attributes- the attributes of theLink.- Returns:
- this.
-
setAttribute
public ExtendedDefaultTracer.NoopSpanBuilder setAttribute(java.lang.String key, java.lang.String value)
Description copied from interface:ExtendedSpanBuilderSets an attribute to the newly createdSpan. IfSpanBuilderpreviously contained a mapping for the key, the old value is replaced by the specified value.If a null or empty String
valueis passed in, the behavior is undefined, and hence strongly discouraged.Note: It is strongly recommended to use
SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.- Specified by:
setAttributein interfaceExtendedSpanBuilder- Specified by:
setAttributein interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
public ExtendedDefaultTracer.NoopSpanBuilder setAttribute(java.lang.String key, long value)
Description copied from interface:ExtendedSpanBuilderSets an attribute to the newly createdSpan. IfSpanBuilderpreviously contained a mapping for the key, the old value is replaced by the specified value.Note: It is strongly recommended to use
SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.- Specified by:
setAttributein interfaceExtendedSpanBuilder- Specified by:
setAttributein interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
public ExtendedDefaultTracer.NoopSpanBuilder setAttribute(java.lang.String key, double value)
Description copied from interface:ExtendedSpanBuilderSets an attribute to the newly createdSpan. IfSpanBuilderpreviously contained a mapping for the key, the old value is replaced by the specified value.Note: It is strongly recommended to use
SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.- Specified by:
setAttributein interfaceExtendedSpanBuilder- Specified by:
setAttributein interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
public ExtendedDefaultTracer.NoopSpanBuilder setAttribute(java.lang.String key, boolean value)
Description copied from interface:ExtendedSpanBuilderSets an attribute to the newly createdSpan. IfSpanBuilderpreviously contained a mapping for the key, the old value is replaced by the specified value.Note: It is strongly recommended to use
SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.- Specified by:
setAttributein interfaceExtendedSpanBuilder- Specified by:
setAttributein interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
public <T> ExtendedDefaultTracer.NoopSpanBuilder setAttribute(AttributeKey<T> key, T value)
Description copied from interface:ExtendedSpanBuilderSets an attribute to the newly createdSpan. IfSpanBuilderpreviously contained a mapping for the key, the old value is replaced by the specified value.Note: the behavior of null values is undefined, and hence strongly discouraged.
- Specified by:
setAttributein interfaceExtendedSpanBuilder- Specified by:
setAttributein interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAllAttributes
public ExtendedDefaultTracer.NoopSpanBuilder setAllAttributes(Attributes attributes)
Description copied from interface:ExtendedSpanBuilderSets attributes to theSpanBuilder. If theSpanBuilderpreviously contained a mapping for any of the keys, the old values are replaced by the specified values.- Specified by:
setAllAttributesin interfaceExtendedSpanBuilder- Specified by:
setAllAttributesin interfaceSpanBuilder- Parameters:
attributes- the attributes- Returns:
- this.
-
setSpanKind
public ExtendedDefaultTracer.NoopSpanBuilder setSpanKind(SpanKind spanKind)
Description copied from interface:ExtendedSpanBuilderSets theSpanKindfor the newly createdSpan. If not called, the implementation will provide a default valueSpanKind.INTERNAL.- Specified by:
setSpanKindin interfaceExtendedSpanBuilder- Specified by:
setSpanKindin interfaceSpanBuilder- Parameters:
spanKind- the kind of the newly createdSpan.- Returns:
- this.
-
setStartTimestamp
public ExtendedDefaultTracer.NoopSpanBuilder setStartTimestamp(long startTimestamp, java.util.concurrent.TimeUnit unit)
Description copied from interface:ExtendedSpanBuilderSets an explicit start timestamp for the newly createdSpan.LIRInstruction.Use this method to specify an explicit start timestamp. If not called, the implementation will use the timestamp value at
SpanBuilder.startSpan()time, which should be the default case.Important this is NOT equivalent with System.nanoTime().
- Specified by:
setStartTimestampin interfaceExtendedSpanBuilder- Specified by:
setStartTimestampin interfaceSpanBuilder- Parameters:
startTimestamp- the explicit start timestamp from the epoch of the newly createdSpan.unit- the unit of the timestamp.- Returns:
- this.
-
startAndCall
public <T,E extends java.lang.Throwable> T startAndCall(SpanCallable<T,E> spanCallable) throws E extends java.lang.Throwable
Description copied from interface:ExtendedSpanBuilderRuns 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.- Specified by:
startAndCallin interfaceExtendedSpanBuilder- 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 java.lang.Throwable
-
startAndCall
public <T,E extends java.lang.Throwable> T startAndCall(SpanCallable<T,E> spanCallable, java.util.function.BiConsumer<Span,java.lang.Throwable> handleException) throws E extends java.lang.Throwable
Description copied from interface:ExtendedSpanBuilderRuns 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.- Specified by:
startAndCallin interfaceExtendedSpanBuilder- 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 java.lang.Throwable
-
startAndRun
public <E extends java.lang.Throwable> void startAndRun(SpanRunnable<E> runnable) throws E extends java.lang.Throwable
Description copied from interface:ExtendedSpanBuilderRuns 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.- Specified by:
startAndRunin interfaceExtendedSpanBuilder- Type Parameters:
E- the type of the exception- Parameters:
runnable- theSpanRunnableto run- Throws:
E extends java.lang.Throwable
-
startAndRun
public <E extends java.lang.Throwable> void startAndRun(SpanRunnable<E> runnable, java.util.function.BiConsumer<Span,java.lang.Throwable> handleException) throws E extends java.lang.Throwable
Description copied from interface:ExtendedSpanBuilderRuns 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.- Specified by:
startAndRunin interfaceExtendedSpanBuilder- Type Parameters:
E- the type of the exception- Parameters:
runnable- theSpanRunnableto run- Throws:
E extends java.lang.Throwable
-
-