Skip to content

Offer a specific/static no-op Span instance. #41

@carlosalberto

Description

@carlosalberto

In Java, we have a DefaultSpan which does nothing by default (it can propagate SpanContext too, but that's more of additional stuff), and can be used as both a no-op object.

Specifically, DefaultSpan.getInvalid() offers a static instance that can also be used when setting parent (through SpanBuilder.serParent()) and also for Tracer.getCurrentSpan() (so the user doesn't have to do a null check).

As Span at this moment already has this no-op functionality, maybe it makes sense to add a class field? This way we could do:

def start_span(..., parent = Span.invalid(), ...):
   if parent is Span.invalid():
     # fetch the actual current Span as parent.

def get_current_span(self):
   ...
   # Return a no-op in case there's no current Span.
   return Span.invalid()

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions