sqlfu emits one OpenTelemetry span per query throughDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/iterate/sqlfu/llms.txt
Use this file to discover all available pages before exploring further.
instrument.otel({tracer}). The span carries the query name, the parameterized SQL text, and the adapter system. Because TracerLike is a structural type, there is no peer dependency on @opentelemetry/api — you bring your own OTel SDK and pass a tracer.
Setup
src/db.ts
Span attributes
| Attribute | Value |
|---|---|
db.query.summary | The generated query name, e.g. listPosts |
db.query.text | Parameterized SQL with placeholders — values are in args, not interpolated into the text |
db.system.name | The adapter system, e.g. sqlite |
instrument.otel() records the exception as a span event and sets the span status to ERROR.
No peer dependency
instrument.otel accepts a TracerLike — a structural type with only a startActiveSpan(name, fn) method. The real OTel Tracer from @opentelemetry/api satisfies this, as does any compatible tracer from other SDKs. sqlfu itself has no import of @opentelemetry/api.
Full setup example
Configure your OTel SDK with the exporter for your backend, then pass the tracer toinstrument.otel:
src/observability.ts
instrument.otel line stays identical.
Ad-hoc SQL
Generated wrappers carry aname automatically. Ad-hoc SQL has no generated name, but you can pass one yourself:
name becomes db.query.summary on the span.
Composing with error reporting
instrument.onError calls a reporter whenever a query throws, then always rethrows. Compose it with instrument.otel to get both OTel spans and error reporting:
Composition order
instrument(client, a, b, c) applies hooks outer-to-inner: a wraps b, which wraps c, which wraps the underlying adapter call. Putting instrument.otel first means the OTel span covers the full execution, including any error-reporter work. Putting it last means the span only covers the raw adapter call.
Read next
Observability
The full hook model, plus recipes for Sentry, PostHog, and Datadog.
Runtime client
The shared client interface and how
instrument wraps it.