Class DefaultTracer.NoopSpanBuilder
- All Implemented Interfaces:
SpanBuilder
- Enclosing class:
DefaultTracer
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddLink(SpanContext spanContext) Adds a link to the newly createdSpan.addLink(SpanContext spanContext, Attributes attributes) Adds a link to the newly createdSpan.(package private) static DefaultTracer.NoopSpanBuildercreate()setAllAttributes(Attributes attributes) Sets attributes to theSpanBuilder.setAttribute(AttributeKey<T> key, T value) Sets an attribute to the newly createdSpan.setAttribute(String key, boolean value) Sets an attribute to the newly createdSpan.setAttribute(String key, double value) Sets an attribute to the newly createdSpan.setAttribute(String key, long value) Sets an attribute to the newly createdSpan.setAttribute(String key, String value) Sets an attribute to the newly createdSpan.Sets the option to become a rootSpanfor a new trace.Sets the parent to use from the specifiedContext.setSpanKind(SpanKind spanKind) Sets theSpanKindfor the newly createdSpan.setStartTimestamp(long startTimestamp, TimeUnit unit) Sets an explicit start timestamp for the newly createdSpan.Starts a newSpan.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SpanBuilder
setStartTimestamp
-
Field Details
-
spanContext
-
-
Constructor Details
-
NoopSpanBuilder
private NoopSpanBuilder()
-
-
Method Details
-
create
-
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
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
context- theContext.- Returns:
- this.
-
setNoParent
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Returns:
- this.
-
addLink
Description copied from interface:SpanBuilderAdds 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 interfaceSpanBuilder- Parameters:
spanContext- the context of the linkedSpan.- Returns:
- this.
-
addLink
Description copied from interface:SpanBuilderAdds 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 interfaceSpanBuilder- Parameters:
spanContext- the context of the linkedSpan.attributes- the attributes of theLink.- Returns:
- this.
-
setAttribute
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAttribute
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
key- the key for this attribute.value- the value for this attribute.- Returns:
- this.
-
setAllAttributes
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
attributes- the attributes- Returns:
- this.
-
setSpanKind
Description copied from interface:SpanBuilderSets theSpanKindfor the newly createdSpan. If not called, the implementation will provide a default valueSpanKind.INTERNAL.- Specified by:
setSpanKindin interfaceSpanBuilder- Parameters:
spanKind- the kind of the newly createdSpan.- Returns:
- this.
-
setStartTimestamp
Description copied from interface:SpanBuilderSets 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 interfaceSpanBuilder- Parameters:
startTimestamp- the explicit start timestamp from the epoch of the newly createdSpan.unit- the unit of the timestamp.- Returns:
- this.
-