Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only add trace comment to sql if we are tracing #3188

Merged
merged 3 commits into from Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
16 changes: 15 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,16 @@ macro_rules! sql_trace {
};
}

fn should_sample(traceparent: &str) -> bool {
let trace_info: Vec<&str> = traceparent.split('-').collect();
pimeys marked this conversation as resolved.
Show resolved Hide resolved

if trace_info.len() != 4 {
false
} else {
trace_info.last() == Some(&"01")
}
}

sql_trace!(Insert<'_>);

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