Review polish: drop unused prefix machinery, tighten comments and docs

- Remove the registry's unused prefix=True slot, its span_for() branch,
  its doc-rendering case and its test - nothing in the stack sets it.
- Stop promising a "later phase" query-duration metric dimension in the
  db.operation.name description; the cardinality rationale stands alone.
- Replace baked-in benchmark numbers in the telemetry module docstring
  with the docs' own phrasing (below run-to-run variation).
- Compact the duplicated copy_context() and enqueue-site comments in
  database.py to pointers at their canonical tellings.
- Make the "catch people out" gotchas skimmable as a bullet list and
  give the changelog's "nothing is removed" line a clear antecedent.
- Add a test that a result cut short by max_returned_rows records
  datasette.truncated=True - previously only ever asserted False.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
This commit is contained in:
Alex Garcia 2026-09-02 11:25:10 -07:00 • committed by GitHub
commit 4dac83a247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 46 additions and 65 deletions

View file

@ -147,6 +147,29 @@ async def test_db_query_span_basic_attributes(ds_client, otel_spans):
assert span.status.status_code == StatusCode.UNSET
@pytest.mark.asyncio
async def test_truncated_result_sets_truncated_attribute(otel_spans):
"""
A result actually cut short by max_returned_rows records truncated=True.
Every other test asserts the attribute is False, so a regression that
recorded the flag before the slice (or inverted it) would pass the rest
of the suite.
"""
ds = Datasette(memory=True, settings={"max_returned_rows": 5})
db = ds.add_memory_database("t04_truncated")
results = await db.execute(
"select value from json_each('[1,2,3,4,5,6,7,8,9,10]')", truncate=True
)
assert results.truncated
spans = _spans_for_namespace(otel_spans, "t04_truncated")
assert spans
span = spans[-1]
assert span.attributes["datasette.truncated"] is True
assert span.attributes["datasette.rows_returned"] == 5
@pytest.mark.asyncio
async def test_facetable_request_produces_db_query_spans(ds_client, otel_spans):
response = await ds_client.get("/fixtures/facetable.json")

View file

@ -287,23 +287,3 @@ def test_span_and_attribute_lookup():
assert not reg.attribute_allowed(reg.DB_QUERY, "db.namespace.extra")
assert not reg.attribute_allowed(reg.DB_QUERY, "datasette.isolated_connection")
assert not reg.attribute_allowed(None, "db.namespace")
def test_prefix_span_lookup():
"""
`prefix=True` matching, exercised directly.
Phase 1 registers no prefix spans, so without this the branch in
`span_for()` would be untested code that the conformance tests silently
never reach.
"""
hook = reg.SpanName("datasette.hook.", "A hypothetical span family", prefix=True)
original = reg.SPANS
reg.SPANS = original + (hook,)
try:
assert reg.span_for("datasette.hook.render_cell") is hook
assert reg.span_for("datasette.hook.anything") is hook
assert reg.span_for("datasette.hookish") is None
assert reg.span_for("db.query") is reg.DB_QUERY
finally:
reg.SPANS = original