Public documentation
Documentation indexRead as MarkdownSQLite
SQLite runs inside the application process. There is no separate database server to scrape, and Contrib 0.160.0 does not include a dedicated SQLite receiver. Instrument database calls and collect the application's logs and metrics to understand query time, lock failures, and the surrounding request.
Configure the application SDK
Follow the guide for your calling language.
If your selected instrumentation supports your exact SQLite driver, enable it
before creating connections. Otherwise, create manual spans around operations.
Keep service.name equal to the calling application, such as catalog-api.
The following smoke test uses Python's standard-library SQLite driver and a temporary in-memory database. Complete the Python SDK setup first, including OTLP export to the Collector in common setup. Run this fragment after SDK initialization:
import sqlite3
from time import perf_counter
from opentelemetry import metrics, trace
from opentelemetry.trace import SpanKind
tracer = trace.get_tracer("example.sqlite")
meter = metrics.get_meter("example.sqlite")
duration = meter.create_histogram("app.sqlite.operation.duration", unit="s")
with sqlite3.connect(":memory:") as connection:
started = perf_counter()
with tracer.start_as_current_span(
"sqlite.select", kind=SpanKind.CLIENT,
attributes={"db.system.name": "sqlite", "db.operation.name": "SELECT"},
):
assert connection.execute("SELECT 1").fetchone() == (1,)
duration.record(perf_counter() - started, {"operation": "SELECT"})
This records a span and a custom duration metric for successful operations. The metric requires an SDK meter provider and OTLP metric reader/exporter; a tracer provider alone only configures traces. Flush/shut down both providers when a short-lived test program exits.
For production, instrument the existing connection rather than opening a new database per request. Record failures with a bounded error category and preserve the original exception. Avoid recording the same database call twice when automatic instrumentation is already enabled.
Protect the database file
SQLite access is controlled by application and operating-system file access, rather than a database monitoring username. Do not give a Collector permission to read the database merely to instrument calls. Restrict the application's database and journal/WAL files to the identities that need them.
For a deliberate read-only diagnostic connection to an existing file, use the driver's read-only URI mode instead of a writable connection:
with sqlite3.connect("file:/approved/path/catalog.db?mode=ro", uri=True) as db:
assert db.execute("SELECT 1").fetchone() == (1,)
Replace the path with an approved existing file. This example does not enumerate tables or export their contents. Do not add database paths, raw statements with literal values, row contents, or user identifiers to metric labels.
Add the signals you need
Instrument operation latency, lock/busy failures, and transaction outcomes in the application. Keep metric dimensions small: operation type and outcome are useful; SQL strings and individual record IDs are not.
Use application log collection for errors. Host or container metrics can explain
disk and memory pressure, but they are not SQLite query metrics. Follow the
other service guide for approved file logs or an existing
Prometheus endpoint; no SQLite file belongs in a filelog receiver.
Verify
Run the in-memory smoke operation after initializing the SDK. In Corridora,
select the calling application's service and find sqlite.select. Confirm a
successful span, and find app.sqlite.operation.duration when metric export
is configured. Then instrument one real application query and inspect its
parent request without exposing row values.
If the query works but telemetry is absent, check SDK initialization, sampling, export configuration, and shutdown. If the real database fails but the in-memory smoke test works, investigate file access, lock contention, and the application's connection settings. Finish verification.
Source basis: SQLite Is Serverless; Python standard-library sqlite3 documentation; OpenTelemetry Python instrumentation; Collector Contrib distribution manifest 0.160.0. Reviewed 2026-09-28.