mod jsonl;
#[cfg(feature = "cloud")]
mod postgres;
use anyhow::Result;
use crate::config::{CommentsBackend, CommentsConfig};
use crate::storage::models::TraceComment;
pub use jsonl::JsonlComments;
pub trait CommentsStore: Send + Sync {
fn add(
&self,
trace_id: &str,
span_id: Option<&str>,
author: &str,
body: &str,
) -> Result<TraceComment>;
fn get(&self, trace_id: &str) -> Result<Vec<TraceComment>>;
}
pub fn open(config: &CommentsConfig, data_dir: &str) -> Result<Box<dyn CommentsStore>> {
match config.backend {
CommentsBackend::Jsonl => Ok(Box::new(JsonlComments::open(data_dir)?)),
CommentsBackend::Postgres => open_postgres(config),
}
}
#[cfg(feature = "cloud")]
fn open_postgres(config: &CommentsConfig) -> Result<Box<dyn CommentsStore>> {
let url = config
.database_url
.as_deref()
.filter(|u| !u.trim().is_empty())
.ok_or_else(|| {
anyhow::anyhow!("TAEL_COMMENTS_STORE=postgres requires TAEL_COMMENTS_DATABASE_URL")
})?;
Ok(Box::new(postgres::PgComments::connect(url)?))
}
#[cfg(not(feature = "cloud"))]
fn open_postgres(_config: &CommentsConfig) -> Result<Box<dyn CommentsStore>> {
anyhow::bail!(
"Postgres comments are not included in this build; rebuild with `--features cloud` \
to use TAEL_COMMENTS_STORE=postgres"
)
}