Skip to content

Commit a95ed83

Browse files
committed
session: record partition key in tracing using human readable form
The RequestSpan is modified so that it includes the partition key in a human readable form instead of the encoded one.
1 parent 31b6fad commit a95ed83

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

scylla/src/transport/iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ impl RowIterator {
288288

289289
let span_creator = move || {
290290
let span = RequestSpan::new_prepared(
291+
prepared_ref.get_prepared_metadata(),
291292
partition_key.as_ref(),
292293
token,
293294
serialized_values_size,

scylla/src/transport/session.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ use crate::cloud::CloudConfig;
77
use crate::frame::types::LegacyConsistency;
88
use crate::history;
99
use crate::history::HistoryListener;
10+
use crate::prepared_statement::PartitionKeyDecoder;
1011
use crate::retry_policy::RetryPolicy;
12+
use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer};
1113
use arc_swap::ArcSwapOption;
1214
use async_trait::async_trait;
1315
use bytes::BufMut;
1416
use bytes::Bytes;
1517
use bytes::BytesMut;
1618
use futures::future::join_all;
1719
use futures::future::try_join_all;
20+
use itertools::Either;
1821
pub use scylla_cql::errors::TranslationError;
19-
use scylla_cql::frame::response::result::Rows;
22+
use scylla_cql::frame::response::result::{PreparedMetadata, Rows};
2023
use scylla_cql::frame::response::NonErrorResponse;
2124
use std::borrow::Borrow;
2225
use std::collections::HashMap;
@@ -952,8 +955,12 @@ impl Session {
952955
is_confirmed_lwt: prepared.is_confirmed_lwt(),
953956
};
954957

955-
let span =
956-
RequestSpan::new_prepared(partition_key.as_ref(), token, serialized_values.size());
958+
let span = RequestSpan::new_prepared(
959+
prepared.get_prepared_metadata(),
960+
partition_key.as_ref(),
961+
token,
962+
serialized_values.size(),
963+
);
957964

958965
if !span.span().is_disabled() {
959966
if let (Some(keyspace), Some(token)) = (statement_info.keyspace.as_ref(), token) {
@@ -2063,11 +2070,11 @@ impl RequestSpan {
20632070
}
20642071

20652072
pub(crate) fn new_prepared(
2073+
prepared_metadata: &PreparedMetadata,
20662074
partition_key: Option<&Bytes>,
20672075
token: Option<Token>,
20682076
request_size: usize,
20692077
) -> Self {
2070-
use crate::utils::pretty::HexBytes;
20712078
use tracing::field::Empty;
20722079

20732080
let span = trace_span!(
@@ -2087,7 +2094,10 @@ impl RequestSpan {
20872094
if let Some(partition_key) = partition_key {
20882095
span.record(
20892096
"partition_key",
2090-
tracing::field::display(format_args!("{:x}", HexBytes(partition_key))),
2097+
tracing::field::display(format_args!(
2098+
"{}",
2099+
partition_key_displayer(prepared_metadata, partition_key),
2100+
)),
20912101
);
20922102
}
20932103
if let Some(token) = token {
@@ -2185,3 +2195,15 @@ impl Drop for RequestSpan {
21852195
);
21862196
}
21872197
}
2198+
2199+
fn partition_key_displayer<'pk>(
2200+
prepared_metadata: &'pk PreparedMetadata,
2201+
partition_key: &'pk [u8],
2202+
) -> impl Display + 'pk {
2203+
CommaSeparatedDisplayer(
2204+
PartitionKeyDecoder::new(prepared_metadata, partition_key).map(|c| match c {
2205+
Ok(c) => Either::Left(CqlValueDisplayer(c)),
2206+
Err(_) => Either::Right("<decoding error>"),
2207+
}),
2208+
)
2209+
}

0 commit comments

Comments
 (0)