Skip to content

Commit

Permalink
Revert "Output params key in events"
Browse files Browse the repository at this point in the history
This reverts commit 9278ba3.
  • Loading branch information
miguelff committed Jan 13, 2023
1 parent 10f4fe3 commit c48c15d
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions query-engine/core/src/telemetry/capturing/capturer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,13 @@ impl Candidate<'_, models::TraceSpan> {
"unknown".to_string()
};

let mut attributes: HashMap<String, serde_json::Value> = vec![(
let attributes = vec![(
"duration_ms".to_owned(),
serde_json::Value::Number(serde_json::Number::from_f64(duration_ms).unwrap()),
)]
.into_iter()
.collect();

if let Some(params) = span.attributes.get("params") {
attributes.insert("params".to_owned(), params.clone());
};

models::Event {
span_id: Some(span.span_id.to_owned()),
name: statement,
Expand Down Expand Up @@ -171,12 +167,8 @@ impl Candidate<'_, models::LogEvent> {
fn query_event(self) -> models::LogEvent {
let mut attributes = self.value.attributes;
let mut attrs = HashMap::new();
if let Some(duration) = attributes.get("duration_ms") {
attrs.insert("duration_ms".to_owned(), duration.clone());
}

if let Some(params) = attributes.get("params") {
attrs.insert("params".to_owned(), params.clone());
if let Some(dur) = attributes.get("duration_ms") {
attrs.insert("duration_ms".to_owned(), dur.clone());
}

let mut name = "uknown".to_owned();
Expand Down Expand Up @@ -368,9 +360,14 @@ mod tests {
level: "debug".to_owned(),
timestamp: [101, 0],
attributes: vec![
("target".to_owned(), serde_json::json!("mongodb_query_connector::query")),
("query".to_owned(), serde_json::json!("db.Users.find()")),
("params".to_owned(), serde_json::json!(vec![1])),
(
"target".to_owned(),
serde_json::Value::String("mongodb_query_connector::query".to_owned()),
),
(
"query".to_owned(),
serde_json::Value::String("db.Users.find()".to_owned()),
),
("duration_ms".to_owned(), serde_json::json!(100.0)),
]
.into_iter()
Expand All @@ -390,8 +387,7 @@ mod tests {
Capture::LogEvent(event) => {
assert_eq!(event.level, "query");
assert_eq!(event.name.to_string().as_str(), "db.Users.find()");
assert!(event.attributes.contains_key("duration_ms"));
assert!(event.attributes.contains_key("params"))
assert_eq!(event.attributes.get("duration_ms").unwrap().to_string(), "100.0");
}
_ => unreachable!(),
};
Expand Down Expand Up @@ -427,10 +423,10 @@ mod tests {
name: "prisma:engine:db_query".to_ascii_lowercase(),
start_time: [101, 0],
end_time: [101, 10000000],
attributes: vec![
("db.statement".to_owned(), serde_json::json!("SELECT ?")),
("params".to_owned(), serde_json::json!([1])),
]
attributes: vec![(
"db.statement".to_owned(),
serde_json::Value::String("SELECT 1".to_owned()),
)]
.into_iter()
.collect(),
events: Default::default(),
Expand All @@ -451,9 +447,8 @@ mod tests {
match capture {
Capture::LogEvent(event) => {
assert_eq!(event.level, "query");
assert_eq!(event.name.to_string().as_str(), "SELECT ?");
assert!(event.attributes.contains_key("duration_ms"));
assert!(event.attributes.contains_key("params"));
assert_eq!(event.name.to_string().as_str(), "SELECT 1");
assert_eq!(event.attributes.get("duration_ms").unwrap().to_string(), "10.0");
}
_ => unreachable!(),
};
Expand Down

0 comments on commit c48c15d

Please sign in to comment.