You've already forked AstralRinth
Add SQLx operation tracing (#5223)
* wip: vendor sqlx-tracing * (compiles) standardize pg types used * more standardization * general log message improvements * wip: improve sqlx-tracing architecture * unify sqlx::Executor type * wip: try fix sqlx tracing * wip: sqlx-tracing compiles * so close * it compiles * fix ci
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
use eyre::Context;
|
||||
use prometheus::{IntGauge, Registry};
|
||||
use sqlx::migrate::{MigrateDatabase, Migrator};
|
||||
use sqlx::postgres::{PgPool, PgPoolOptions};
|
||||
use sqlx::{Connection, PgConnection, Postgres};
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::{Connection, Postgres};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::time::Duration;
|
||||
use tracing::info;
|
||||
|
||||
// TODO tracing spans
|
||||
pub type PgPool = sqlx_tracing::Pool<Postgres>;
|
||||
pub type PgTransaction<'c> = sqlx_tracing::Transaction<'c, Postgres>;
|
||||
pub use sqlx_tracing::Acquire;
|
||||
pub use sqlx_tracing::Executor;
|
||||
|
||||
// pub type PgPool = sqlx::PgPool;
|
||||
// pub type PgTransaction<'c> = sqlx::Transaction<'c, Postgres>;
|
||||
// pub use sqlx::Acquire;
|
||||
// pub use sqlx::Executor;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[repr(transparent)]
|
||||
pub struct ReadOnlyPgPool(PgPool);
|
||||
@@ -71,6 +82,7 @@ pub async fn connect_all() -> Result<(PgPool, ReadOnlyPgPool), sqlx::Error> {
|
||||
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
||||
.connect(&database_url)
|
||||
.await?;
|
||||
let pool = PgPool::from(pool);
|
||||
|
||||
if let Ok(url) = dotenvy::var("READONLY_DATABASE_URL") {
|
||||
let ro_pool = PgPoolOptions::new()
|
||||
@@ -90,6 +102,7 @@ pub async fn connect_all() -> Result<(PgPool, ReadOnlyPgPool), sqlx::Error> {
|
||||
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
||||
.connect(&url)
|
||||
.await?;
|
||||
let ro_pool = PgPool::from(ro_pool);
|
||||
|
||||
Ok((pool, ReadOnlyPgPool(ro_pool)))
|
||||
} else {
|
||||
@@ -114,9 +127,10 @@ pub async fn check_for_migrations() -> eyre::Result<()> {
|
||||
|
||||
info!("Applying migrations...");
|
||||
|
||||
let mut conn: PgConnection = PgConnection::connect(uri)
|
||||
.await
|
||||
.wrap_err("failed to connect to database")?;
|
||||
let mut conn: sqlx::PgConnection =
|
||||
sqlx::PgConnection::connect(uri)
|
||||
.await
|
||||
.wrap_err("failed to connect to database")?;
|
||||
MIGRATOR
|
||||
.run(&mut conn)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user