Skip to content

feat: Use query id as trace id #17947

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/query/service/src/servers/mysql/mysql_interactive_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,20 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for InteractiveWorke
query: &'a str,
writer: QueryResultWriter<'a, W>,
) -> Result<()> {
let query_id = Uuid::new_v4().to_string();
let query_id = Uuid::now_v7();
// Ensure the query id shares the same representation as trace_id.
let query_id_str = query_id.simple().to_string();

let sampled =
thread_rng().gen_range(0..100) <= self.base.session.get_trace_sample_rate()?;
let root = Span::root(func_path!(), SpanContext::random().sampled(sampled))
let span_context =
SpanContext::new(TraceId(query_id.as_u128()), SpanId::default()).sampled(sampled);
let root = Span::root(func_path!(), span_context)
.with_properties(|| self.base.session.to_fastrace_properties());

let mut tracking_payload = ThreadTracker::new_tracking_payload();
tracking_payload.query_id = Some(query_id.clone());
tracking_payload.mem_stat = Some(MemStat::create(query_id.clone()));
tracking_payload.query_id = Some(query_id_str.clone());
tracking_payload.mem_stat = Some(MemStat::create(query_id_str.to_string()));
let _guard = ThreadTracker::tracking(tracking_payload);

ThreadTracker::tracking_future(async {
Expand All @@ -226,7 +231,7 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for InteractiveWorke
let instant = Instant::now();
let query_result = self
.base
.do_query(query_id, query)
.do_query(query_id_str, query)
.await
.map_err(|err| err.display_with_sql(query));

Expand Down
Loading