googleapis / googleapis/google-cloud-python

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

未关闭
#15,909 1 条评论 0 个 reaction 已指派 1 人 已被 @c24t 认领 在 GitHub 查看
api: spanner
主要语言
Python
星标
5.4k
派生
1.8k
平均合并
3 天 4 小时
30 天内合并 PR
122

描述

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
```python
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 https://github.com/googleapis/python-spanner/pull/1207
```python
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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。