Skip to content

Commit

Permalink
only add trace comment to sql if we are tracing (#3188)
Browse files Browse the repository at this point in the history
* only add trace comment to sql if we are tracing
  • Loading branch information
garrensmith committed Sep 15, 2022
1 parent 06b6b4b commit b40cafb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions query-engine/connectors/sql-query-connector/src/query_ext.rs
Expand Up @@ -50,9 +50,7 @@ pub trait QueryExt: Queryable + Send + Sync {
Query::Select(Box::from(x.comment(trace_parent_to_string(span_ctx))))
}
// This is part of the required changes to pass a traceid
(Query::Select(x), Some(traceparent)) => {
Query::Select(Box::from(x.comment(format!("traceparent={}", traceparent))))
}
(Query::Select(x), trace_id) => Query::Select(Box::from(x.add_trace_id(trace_id))),
(q, _) => q,
};

Expand Down
10 changes: 9 additions & 1 deletion query-engine/connectors/sql-query-connector/src/sql_trace.rs
Expand Up @@ -33,7 +33,11 @@ macro_rules! sql_trace {
// Temporary method to pass the traceid in an operation
fn add_trace_id(self, trace_id: Option<String>) -> Self {
if let Some(traceparent) = trace_id {
self.comment(format!("traceparent={}", traceparent))
if should_sample(&traceparent) {
self.comment(format!("traceparent={}", traceparent))
} else {
self
}
} else {
self
}
Expand All @@ -42,6 +46,10 @@ macro_rules! sql_trace {
};
}

fn should_sample(traceparent: &str) -> bool {
traceparent.split('-').count() == 4 && traceparent.ends_with("-01")
}

sql_trace!(Insert<'_>);

sql_trace!(Update<'_>);
Expand Down

0 comments on commit b40cafb

Please sign in to comment.