Skip to content

Commit

Permalink
Add additional tracing fields specific to Scylla
Browse files Browse the repository at this point in the history
  • Loading branch information
karlpvoss committed Sep 21, 2023
1 parent 1854c96 commit 8179892
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/source/tracing/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Queries that support tracing:
* [`Session::prepare()`](prepare.md)

After obtaining the tracing id you can use `Session::get_tracing_info()` to query tracing information.\
`TracingInfo` contains values that are the same in Scylla and Cassandra®, skipping any database-specific ones.\
`Session::get_tracing_info()` returns a `TracingInfo` which only contains values that are the same
in both Scylla and Cassandra®, skipping any database-specific ones.\
If `TracingInfo` does not contain some needed value it's possible to query it manually from the tables
`system_traces.sessions` and `system_traces.events`

Expand Down
15 changes: 15 additions & 0 deletions scylla/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct TracingInfo {
pub request: Option<String>,
/// started_at is a timestamp - time since unix epoch
pub started_at: Option<chrono::Duration>,
/// only present in Scylla
pub request_size: Option<i32>,
/// only present in Scylla
pub response_size: Option<i32>,
/// only present in Scylla
pub username: Option<String>,

pub events: Vec<TracingEvent>,
}
Expand All @@ -30,6 +36,10 @@ pub struct TracingEvent {
pub source: Option<IpAddr>,
pub source_elapsed: Option<i32>,
pub thread: Option<String>,
/// only present in Scylla
pub scylla_parent_id: Option<i64>,
/// only present in Scylla
pub scylla_span_id: Option<i64>,
}

impl TracingInfo {
Expand Down Expand Up @@ -75,6 +85,9 @@ impl FromRow for TracingInfo {
parameters,
request,
started_at,
request_size: None,
response_size: None,
username: None,
events: Vec::new(),
})
}
Expand All @@ -97,6 +110,8 @@ impl FromRow for TracingEvent {
source,
source_elapsed,
thread,
scylla_parent_id: None,
scylla_span_id: None,
})
}
}
17 changes: 14 additions & 3 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,11 @@ impl Session {
///
/// See [the book](https://rust-driver.docs.scylladb.com/stable/tracing/tracing.html)
/// for more information about query tracing
///
/// Does not query for the fields that are only present in the Scylla schema (
/// [request_size](TracingInfo::request_size), [response_size](TracingInfo::response_size),
/// [username](TracingInfo::username), [scylla_parent_id](TracingEvent::scylla_parent_id),
/// and [scylla_span_id](TracingEvent::scylla_span_id)).
pub async fn get_tracing_info(&self, tracing_id: &Uuid) -> Result<TracingInfo, QueryError> {
// tracing_info_fetch_attempts is NonZeroU32 so at least one attempt will be made
for _ in 0..self.tracing_info_fetch_attempts.get() {
Expand Down Expand Up @@ -1396,9 +1401,15 @@ impl Session {
self.keyspace_name.load_full()
}

// Tries getting the tracing info
// If the queries return 0 rows then returns None - the information didn't reach this node yet
// If there is some other error returns this error
// Tries getting the tracing info from `system_traces`.
//
// If the queries return 0 rows then returns `Ok(None)` - the information didn't reach this
// node yet.
//
// If there is some other error returns `Err(that_error)`.
//
// Does not query for the fields that are only present in the Scylla schema (request_size,
// response_size, username, scylla_parent_id, and scylla_span_id).
async fn try_getting_tracing_info(
&self,
tracing_id: &Uuid,
Expand Down

0 comments on commit 8179892

Please sign in to comment.