Skip to content

Commit a84b3d3

Browse files
authored
Fix SDK without otel. (#165)
1 parent dc66145 commit a84b3d3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

getstream/common/telemetry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ def span_request(
170170
"""
171171
include_bodies = INCLUDE_BODIES if include_bodies is None else include_bodies
172172
if not _HAS_OTEL: # pragma: no cover
173+
yield _NullSpan()
173174
return
174175
tracer = _get_tracer()
175-
if tracer is None: # pragma: no cover
176+
if tracer is None:
177+
yield _NullSpan() # pragma: no cover
176178
return
177179
with tracer.start_as_current_span(name, kind=SpanKind.CLIENT) as span: # type: ignore[arg-type]
178180
base_attrs: Dict[str, Any] = dict(attributes or {})

tests/test_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,23 @@ def test_incorrect_client_throws_exception(monkeypatch):
3838

3939
with pytest.raises(ValueError):
4040
Stream(api_key="xxx", api_secret="xxx", base_url="ftp://example.com")
41+
42+
43+
def test_client_does_not_raise_exception_without_tracer(client: Stream, monkeypatch):
44+
# Monkey patch _get_tracer to always return None
45+
from getstream.common import telemetry
46+
47+
monkeypatch.setattr(telemetry, "_get_tracer", lambda: None)
48+
49+
response = client.get_app()
50+
assert response.data is not None
51+
52+
53+
def test_client_works_with_no_otel(client: Stream, monkeypatch):
54+
# Monkey patch _get_tracer to always return None
55+
from getstream.common import telemetry
56+
57+
monkeypatch.setattr(telemetry, "_HAS_OTEL", False)
58+
59+
response = client.get_app()
60+
assert response.data is not None

0 commit comments

Comments
 (0)