googleapis / googleapis/google-cloud-python

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

オープン
#15,909 コメント 1 件 リアクション 0 件 担当者 1 名 @c24t が担当を希望しています GitHub で見る
api: spanner
主要言語
Python
スター
5.4k
フォーク
1.8k
平均マージ
3日 4時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。