#[cfg(any(feature = "daemon", feature = "tempo", feature = "jaeger-query"))]
pub mod auth_header;
pub mod jaeger;
#[cfg(feature = "jaeger-query")]
pub mod jaeger_query;
pub mod json;
#[cfg(any(feature = "tempo", feature = "jaeger-query"))]
pub mod lookback;
pub mod mysql_stat;
pub mod otlp;
pub mod pg_stat;
#[cfg(feature = "tempo")]
pub mod tempo;
#[cfg(any(feature = "tempo", feature = "jaeger-query"))]
pub(crate) mod url_enc;
pub mod zipkin;
use crate::event::SpanEvent;
const NON_SQL_DB_SYSTEMS: &[&str] = &[
"redis",
"memcached",
"mongodb",
"cassandra",
"dynamodb",
"couchbase",
"couchdb",
"elasticsearch",
"opensearch",
"neo4j",
"hbase",
"geode",
"influxdb",
];
#[must_use]
pub(crate) fn is_non_sql_db_system(system: &str) -> bool {
NON_SQL_DB_SYSTEMS
.iter()
.any(|s| system.eq_ignore_ascii_case(s))
}
const SQL_DB_SYSTEMS: &[&str] = &[
"postgresql",
"mysql",
"mariadb",
"mssql",
"oracle",
"db2",
"sqlite",
"h2",
"hsqldb",
"derby",
"cockroachdb",
"clickhouse",
"spanner",
"redshift",
"snowflake",
"bigquery",
"trino",
"presto",
"vertica",
"teradata",
"hive",
"sql",
];
#[must_use]
pub(crate) fn is_sql_db_system(system: &str) -> bool {
SQL_DB_SYSTEMS
.iter()
.any(|s| system.eq_ignore_ascii_case(s))
}
#[must_use]
pub(crate) fn canonical_db_system(system: &str) -> &str {
const ALIASES: &[(&str, &str)] = &[
("postgres", "postgresql"),
("sqlserver", "mssql"),
("sql server", "mssql"),
("microsoft.sql_server", "mssql"),
("oracle.db", "oracle"),
("ibm.db2", "db2"),
("gcp.spanner", "spanner"),
("aws.redshift", "redshift"),
("aws.dynamodb", "dynamodb"),
];
for &(alias, canonical) in ALIASES {
if system.eq_ignore_ascii_case(alias) {
return canonical;
}
}
system
}
pub trait IngestSource {
type Error: std::error::Error;
fn ingest(&self, raw: &[u8]) -> Result<Vec<SpanEvent>, Self::Error>;
}
#[cfg(test)]
mod tests {
use super::{
NON_SQL_DB_SYSTEMS, SQL_DB_SYSTEMS, canonical_db_system, is_non_sql_db_system,
is_sql_db_system,
};
#[test]
fn sql_and_non_sql_lists_are_disjoint() {
for s in SQL_DB_SYSTEMS {
assert!(!is_non_sql_db_system(s), "{s} is in both lists");
}
for s in NON_SQL_DB_SYSTEMS {
assert!(!is_sql_db_system(s), "{s} is in both lists");
}
}
#[test]
fn canonical_aliases_resolve_to_a_classified_system() {
let alias_inputs = [
"postgres",
"sqlserver",
"sql server",
"microsoft.sql_server",
"oracle.db",
"ibm.db2",
"gcp.spanner",
"aws.redshift",
"aws.dynamodb",
];
for input in alias_inputs {
let canonical = canonical_db_system(input);
let sql = is_sql_db_system(canonical);
let non_sql = is_non_sql_db_system(canonical);
assert!(
sql ^ non_sql,
"{input} -> {canonical} classified as neither or both (sql={sql}, non_sql={non_sql})"
);
}
}
}