Wraps SQLite3::Database query methods with OpenTelemetry spans, capturing SQL statements with configurable obfuscation. Fills the gap in the OpenTelemetry Ruby ecosystem where adapter instrumentations exist for PG, Mysql2, and Trilogy, but not for SQLite3.
Add to your Gemfile:
gem "opentelemetry-instrumentation-sqlite3", github: "6temes/opentelemetry-instrumentation-sqlite3"If you already use opentelemetry-instrumentation-all, the SQLite3 instrumentation is picked up automatically:
OpenTelemetry::SDK.configure do |c|
c.use_all
endrequire "opentelemetry/sdk"
require "opentelemetry-instrumentation-sqlite3"
OpenTelemetry::SDK.configure do |c|
c.use "OpenTelemetry::Instrumentation::SQLite3"
endOpenTelemetry::SDK.configure do |c|
c.use "OpenTelemetry::Instrumentation::SQLite3", {
db_statement: :obfuscate,
obfuscation_limit: 2000,
record_exception: true
}
endAll SQLite3::Database queries are now traced:
db = SQLite3::Database.new("app.sqlite3")
db.execute("SELECT * FROM users WHERE id = ?", [42])
# => Creates a span: name="SELECT app.sqlite3", db.system.name="sqlite", db.query.text="SELECT * FROM users WHERE id = ?"| Option | Default | Values | Description |
|---|---|---|---|
db_statement |
:obfuscate |
:omit, :include, :obfuscate |
Controls SQL capture in spans |
obfuscation_limit |
2000 |
Integer | Max length of obfuscated SQL |
record_exception |
true |
Boolean | Record exceptions on spans |
db_statement modes:
:obfuscate(default) — captures SQL with literal values replaced by?:include— captures raw SQL including all literal values:omit— no SQL captured in spans
Note: Avoid
:includein production if your queries contain sensitive data (passwords, PII, tokens). The default:obfuscatemode is recommended.
Each span includes:
| Attribute | Value | Example |
|---|---|---|
db.system.name |
"sqlite" |
"sqlite" |
db.namespace |
Database filename (basename) | "app.sqlite3" |
db.operation.name |
SQL operation (first keyword) | "SELECT" |
db.query.text |
SQL (per db_statement config) |
"SELECT * FROM users WHERE id = ?" |
error.type |
Exception class name (on errors) | "SQLite3::SQLException" |
db.response.status_code |
SQLite error code (on errors) | "1" |
Uses stable database semantic conventions. SQLite-specific simplifications (compared to PG/Trilogy):
- No
server.addressorserver.port— SQLite is an embedded database - No
db.user— SQLite has no authentication db.namespaceisnilfor in-memory databases (:memory:)
The following SQLite3::Database methods are wrapped with spans:
executeexecute2execute_batchexecute_batch2query
- Ruby >= 3.1
- sqlite3 gem >= 2.0, < 3.0
Apache-2.0. See LICENSE.