Skip to content

Commit 0d6473e

Browse files
authored
chore: upgrade lite-bootstrap to 1.13.0 (#87)
* chore: upgrade lite-bootstrap to 1.13.0 * test: fold the tracing tests into one traced request
1 parent e702bc7 commit 0d6473e

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

‎tests/test_tracing.py‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastapi import status
66
from httpx import ASGITransport, AsyncClient
77
from opentelemetry import trace
8-
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
8+
from opentelemetry.sdk.trace import TracerProvider
99
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
1010
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
1111
from opentelemetry.trace import SpanKind
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020

21-
async def _trace_list_decks(monkeypatch: pytest.MonkeyPatch) -> tuple[ReadableSpan, ...]:
21+
async def test_traced_request_records_server_and_db_spans_only(monkeypatch: pytest.MonkeyPatch) -> None:
2222
traced_config = dataclasses.replace(settings.api_bootstrapper_config, opentelemetry_log_traces=True)
2323
monkeypatch.setattr(Settings, "api_bootstrapper_config", traced_config)
2424
exporter = InMemorySpanExporter()
@@ -31,26 +31,20 @@ async def _trace_list_decks(monkeypatch: pytest.MonkeyPatch) -> tuple[ReadableSp
3131
response = await client.get("/api/decks/")
3232

3333
assert response.status_code == status.HTTP_200_OK
34-
return exporter.get_finished_spans()
35-
36-
37-
async def test_db_queries_produce_sqlalchemy_spans(monkeypatch: pytest.MonkeyPatch) -> None:
34+
spans = exporter.get_finished_spans()
35+
sqlalchemy_scope = "opentelemetry.instrumentation.sqlalchemy"
3836
db_spans = [
3937
span
40-
for span in await _trace_list_decks(monkeypatch)
38+
for span in spans
4139
if span.instrumentation_scope is not None
42-
and span.instrumentation_scope.name == "opentelemetry.instrumentation.sqlalchemy"
40+
and span.instrumentation_scope.name == sqlalchemy_scope
4341
and span.name.startswith("SELECT")
4442
]
4543
assert db_spans
4644
assert all(span.parent is not None for span in db_spans)
47-
48-
49-
async def test_request_has_no_asgi_event_spans(monkeypatch: pytest.MonkeyPatch) -> None:
5045
request_spans = [
5146
span
52-
for span in await _trace_list_decks(monkeypatch)
53-
if span.instrumentation_scope is None
54-
or span.instrumentation_scope.name != "opentelemetry.instrumentation.sqlalchemy"
47+
for span in spans
48+
if span.instrumentation_scope is None or span.instrumentation_scope.name != sqlalchemy_scope
5549
]
5650
assert [span.kind for span in request_spans] == [SpanKind.SERVER]

‎uv.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)