googleapis/python-spanner

tracing: trace_call returns None if opentelemetry is not enabled or if no session but that makes it awkward to seamlessly use library, it should return a NoopSpan

odeke-em opened this issue · 0 comments

If we examine the code for trace_call it returns None

def trace_call(name, session, extra_attributes=None):
if not HAS_OPENTELEMETRY_INSTALLED or not session:
# Empty context manager. Users will have to check if the generated value is None or a span
yield None
return

and when we try to perform what should be a simple thing like add annotations, we have to awkwardly check if span is not None and that's not a good user experience.

Remedy

  • Let's implement a NoopSpan which has all the methods for a Span but does nothing