Skip to content

Commit b5c497d

Browse files
committed
feat(sqlite): Trace sqlite host components
Signed-off-by: Caleb Schoepp <[email protected]>
1 parent f25a5e9 commit b5c497d

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sqlite-inproc/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ anyhow = "1.0"
1212
rusqlite = { version = "0.29.0", features = [ "bundled" ] }
1313
rand = "0.8"
1414
once_cell = "1"
15-
tokio = "1"
15+
tokio = "1"
16+
tracing = { workspace = true }
17+
18+
[lints]
19+
workspace = true

crates/sqlite-inproc/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use async_trait::async_trait;
88
use once_cell::sync::OnceCell;
99
use spin_sqlite::Connection;
1010
use spin_world::v2::sqlite;
11+
use tracing::{instrument, Level};
1112

1213
#[derive(Debug, Clone)]
1314
pub enum InProcDatabaseLocation {
@@ -46,6 +47,7 @@ impl InProcConnection {
4647

4748
#[async_trait]
4849
impl Connection for InProcConnection {
50+
#[instrument(name = "spin_sqlite_inproc.query", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", otel.name = query))]
4951
async fn query(
5052
&self,
5153
query: &str,
@@ -60,6 +62,7 @@ impl Connection for InProcConnection {
6062
.map_err(|e| sqlite::Error::Io(e.to_string()))?
6163
}
6264

65+
#[instrument(name = "spin_sqlite_inproc.execute_batch", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", db.statements = statements))]
6366
async fn execute_batch(&self, statements: &str) -> anyhow::Result<()> {
6467
let connection = self.db_connection()?;
6568
let statements = statements.to_owned();

crates/sqlite-libsql/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ spin-world = { path = "../world" }
1515
sqlparser = "0.34"
1616
libsql = { version = "0.3.2", features = ["remote"], default-features = false }
1717
tokio = { version = "1", features = ["full"] }
18+
tracing = { workspace = true }
19+
20+
[lints]
21+
workspace = true

crates/sqlite-libsql/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use spin_world::v2::sqlite::{self, RowResult};
2+
use tracing::{instrument, Level};
23

34
#[derive(Clone)]
45
pub struct LibsqlClient {
56
inner: libsql::Connection,
67
}
78

89
impl LibsqlClient {
10+
#[instrument(name = "spin_sqlite_libsql.create_connection", skip(token), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite"))]
911
pub async fn create(url: String, token: String) -> anyhow::Result<Self> {
1012
let db = libsql::Builder::new_remote(url, token).build().await?;
1113
let inner = db.connect()?;
@@ -15,6 +17,7 @@ impl LibsqlClient {
1517

1618
#[async_trait::async_trait]
1719
impl spin_sqlite::Connection for LibsqlClient {
20+
#[instrument(name = "spin_sqlite_libsql.query", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", otel.name = query))]
1821
async fn query(
1922
&self,
2023
query: &str,
@@ -34,6 +37,7 @@ impl spin_sqlite::Connection for LibsqlClient {
3437
})
3538
}
3639

40+
#[instrument(name = "spin_sqlite_libsql.execute_batch", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", db.statements = statements))]
3741
async fn execute_batch(&self, statements: &str) -> anyhow::Result<()> {
3842
self.inner.execute_batch(statements).await?;
3943

crates/sqlite/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ spin-app = { path = "../app" }
1212
spin-world = { path = "../world" }
1313
table = { path = "../table" }
1414
tokio = "1"
15+
tracing = { workspace = true }

0 commit comments

Comments
 (0)