Skip to content

Commit

Permalink
Test logs are renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Dec 16, 2022
1 parent 3e1a99d commit cbcaa14
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions query-engine/core/src/trace_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ impl From<&SpanData> for UserFacingSpan {
// Override the name of quaint. It will be confusing for users to see quaint instead of
// Prisma in the spans.
let name: Cow<str> = match span.name {
Cow::Borrowed("quaint:query") => "prisma:engine:db_query".into(),
Cow::Borrowed("quaint:query") | Cow::Borrowed("mongodb_query_connector=debug") => {
"prisma:engine:db_query".into()
}
_ => span.name.clone(),
};

Expand Down Expand Up @@ -164,7 +166,18 @@ pub fn convert_to_high_res_time(time: Duration) -> HrTime {

#[cfg(test)]
mod tests {
use std::time::Duration;
use opentelemetry::{
sdk::{
export::trace::SpanData,
trace::{EvictedHashMap, EvictedQueue},
InstrumentationLibrary,
},
trace::{SpanContext, SpanId, SpanKind, StatusCode},
};
use std::{
borrow::Cow,
time::{Duration, SystemTime},
};

use super::*;

Expand All @@ -174,4 +187,35 @@ mod tests {
let time_val = Duration::from_millis(1609504210150);
assert_eq!([1609504210, 150000000], convert_to_high_res_time(time_val));
}

#[test]
fn test_reanames_user_facing_span() {
let template = SpanData {
span_context: SpanContext::empty_context(),
parent_span_id: SpanId::INVALID,
span_kind: SpanKind::Internal,
name: Cow::Borrowed("foo"),
start_time: SystemTime::now(),
end_time: SystemTime::now(),
attributes: EvictedHashMap::new(0, 0),
events: EvictedQueue::new(0),
links: EvictedQueue::new(0),
status_code: StatusCode::Ok,
status_message: Cow::Borrowed("foo"),
resource: None,
instrumentation_lib: InstrumentationLibrary::new("foo", None),
};

let quaint_span = SpanData {
name: Cow::Borrowed("quaint:query"),
..template.clone()
};
assert_eq!("prisma:engine:db_query", UserFacingSpan::from(&quaint_span).name);

let mongo_span = SpanData {
name: Cow::Borrowed("mongodb_query_connector=debug"),
..template.clone()
};
assert_eq!("prisma:engine:db_query", UserFacingSpan::from(&mongo_span).name);
}
}

0 comments on commit cbcaa14

Please sign in to comment.