Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: avoid returning None if OpenTelemetry is not installed; instead return a custom noop-span #1222

Open
odeke-em opened this issue Nov 3, 2024 · 0 comments
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API.

Comments

@odeke-em
Copy link
Contributor

odeke-em commented Nov 3, 2024

Trying to uniformly instrument this library is really tricky in the case that OpenTelemetry is not installed.
Currently the code returns None in the case that the dependency wasn't imported.

Trying to invoke

with trace_call('foo') as span:
    if span:
         # Add code

and then in other cases where we need to add span annotations firstly having to check if span is not None is awkward such as in #1207

if span is not None:
    span.add_event(...)

we shouldn't labor ourselves with dependency implementation details which constitutes a leaky abstraction.

Suggestion

Let's implement a NoopSpan class that'll be returned on every invocation if not installed and that should make it clean for this package to freely add events.

/cc @harshachinta @surbhigarg92

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API.
Projects
None yet
Development

No branches or pull requests

2 participants