Repository navigation
feat(entities): a span per SQL statement — all 245 of them, from one change (telemetry P10) - #411
Merged
Merged
Conversation
…change (telemetry P10)
"Attribute every single SQL statement" — the payload of the programme. 244
declared statements plus the bulk-append path, instrumented by a ~145-line
change to the emitters rather than 245 edits.
## Why the emitters are the right seam
Every persistent statement in this repo is a declared `.sql` + `.yaml` pair,
and every one of them becomes Rust through five functions in
`er-sql-check/src/emit.rs`. The statement's identity — the `(entity, folder,
stem)` triple that names its file — is **already in scope** at the moment each
emitter writes its `conn.prepare` / `client.query` line. So attribution is by
construction: a statement added tomorrow is attributed without anyone
remembering to, and `er-entity verify` fails if a generated file drifts.
For a lake read the emitted body is now:
const SQL: &str = "SELECT record_key\nFROM lake.main.int_std_records\n…";
let __span = ::er_span::sql_span(
::er_span::Store::Lake, "int_std_record", "read", "all_keys_live",
"int_std_records", SQL,
);
let __entered = __span.enter();
let mut stmt = ::er_span::check(&__span, conn.prepare(SQL))?;
let batches = ::er_span::check(&__span, stmt.query_arrow(…))?.collect();
::er_span::rows(&__span, batches.iter().map(|b| b.num_rows() as u64).sum());
## The async path uses instrument, never enter
A `tracing` span guard held across an `.await` attributes whatever else that
thread runs to this span. The control-plane functions are async, so the wrong
form would have been GENERATED into 110 call sites simultaneously. They use
`::er_span::instrument(&__span, fut).await` and only enter the span afterwards,
for the synchronous row mapping. A test asserts the absence of the guard form,
not just the presence of the right one.
## Three classes of SQL, three treatments
- **Declared** statements export their template as `db.query.text`, gated on
`ER_TRACE_SQL_TEXT`. Provably literal-free: the analyser rewrites every
`$name` to a bound `$N`, so the text carries placeholders and never values.
The TEMPLATE is recorded even for a snapshot-pinned read — splicing the
version in would make the attribute unique per call.
- **`append_rows`** assembles its SQL at runtime (500 placeholder tuples
joined), so it gets a `generator_span` with a compile-time summary —
`INSERT INTO lake.main.raw_records VALUES (…)` — and never its text. One span
for the whole append, not one per chunk: chunking is a bind limit, not a unit
of work, and a span per chunk would make a 10k-row append look like twenty
statements.
- Engine-core generator SQL keeps its own treatment in `er-span`.
## Cost, and the PII boundary
**This adds no log volume.** A `tracing` span emits no record on its own —
only events do — so 245 spans are pure context today and become exported spans
the day the OTLP exporter lands.
`sql_span` takes no parameter argument: there is nowhere to put a bind value.
In a deduplication engine the bind values are the payload, so §10.4's rule is a
property of the signature rather than a line in a document.
## What a reviewer should read
The emitter and its tests, not the 3,747-line generated diff. The tests now pin
the statement identity, the store, the declared relation, and the absence of
the across-await guard. Four existing assertions changed because they pinned
the old emitted shape; `entity` is threaded into three emitters so the span can
carry the declared relation.
`make check` green at exit 0 — including `entities-check`, which byte-compares
all 51 regenerated files.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"Attribute every single SQL statement" — the payload of the programme. 244 declared statements plus the bulk-append path, instrumented by a ~145-line change to the emitters rather than 245 edits.
Why the emitters are the right seam
Every persistent statement in this repo is a declared
.sql+.yamlpair, and every one becomes Rust through five functions iner-sql-check/src/emit.rs. The statement's identity — the(entity, folder, stem)triple that names its file — is already in scope where each emitter writes itsconn.prepare/client.queryline.So attribution is by construction: a statement added tomorrow is attributed without anyone remembering to, and
er-entity verifyfails if a generated file drifts.The async path uses
instrument, neverenterA span guard held across an
.awaitattributes whatever else that thread runs to this span. The control-plane functions are async — so the wrong form would have been generated into 110 call sites simultaneously.They use
::er_span::instrument(&__span, fut).awaitand only enter the span afterwards, for the synchronous row mapping. A test asserts the absence of the guard form, not merely the presence of the right one.Three classes of SQL, three treatments
db.query.textER_TRACE_SQL_TEXTappend_rowsgenerator_span+ compile-time summaryer-spantreatmentDeclared statements are provably literal-free: the analyser rewrites every
$nameto a bound$N, so the text carries placeholders and never values. The template is recorded even for a snapshot-pinned read — splicing the version in would make the attribute unique per call.append_rowsassembles SQL at runtime (500 placeholder tuples joined), so it gets a summary —INSERT INTO lake.main.raw_records VALUES (…)— and one span for the whole append, not one per chunk. Chunking is a bind limit, not a unit of work; a span per chunk would make a 10k-row append look like twenty statements.Cost, and the PII boundary
This adds no log volume. A
tracingspan emits no record on its own — only events do. So 245 spans are pure context today, and become exported spans the day the OTLP exporter lands.sql_spantakes no parameter argument — there is nowhere to put a bind value. In a deduplication engine the bind values are the payload, so §10.4's rule is a property of the signature rather than a line in a document.What to review
The emitter and its tests, not the 3,747-line generated diff. The tests now pin the statement identity, the store, the declared relation, and the absence of the across-await guard. Four existing assertions changed because they pinned the old emitted shape;
entityis threaded into three emitters so the span can carry the declared relation.make checkgreen at exit 0 — includingentities-check, which byte-compares all 51 regenerated files.🤖 Generated with Claude Code