Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion getstream/common/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ def span_request(
"""
include_bodies = INCLUDE_BODIES if include_bodies is None else include_bodies
if not _HAS_OTEL: # pragma: no cover
yield _NullSpan()
return
tracer = _get_tracer()
if tracer is None: # pragma: no cover
if tracer is None:
yield _NullSpan() # pragma: no cover
return
with tracer.start_as_current_span(name, kind=SpanKind.CLIENT) as span: # type: ignore[arg-type]
base_attrs: Dict[str, Any] = dict(attributes or {})
Expand Down
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,23 @@ def test_incorrect_client_throws_exception(monkeypatch):

with pytest.raises(ValueError):
Stream(api_key="xxx", api_secret="xxx", base_url="ftp://example.com")


def test_client_does_not_raise_exception_without_tracer(client: Stream, monkeypatch):
# Monkey patch _get_tracer to always return None
from getstream.common import telemetry

monkeypatch.setattr(telemetry, "_get_tracer", lambda: None)

response = client.get_app()
assert response.data is not None


def test_client_works_with_no_otel(client: Stream, monkeypatch):
# Monkey patch _get_tracer to always return None
from getstream.common import telemetry

monkeypatch.setattr(telemetry, "_HAS_OTEL", False)

response = client.get_app()
assert response.data is not None