Skip to content

Commit

Permalink
Add send and receive trace spans
Browse files Browse the repository at this point in the history
```
2023-10-31T20:35:01.600364Z TRACE oprf_ipa_query{sz=10000}:send{i=914 total=1658 to=H2 gate="protocol/binary_validator/row1/attributed_breakdown_key/bit7"}: ipa::helpers::gateway::send: new
2023-10-31T20:35:01.600382Z TRACE oprf_ipa_query{sz=10000}:send{i=914 total=1658 to=H2 gate="protocol/binary_validator/row1/attributed_breakdown_key/bit7"}: ipa::helpers::gateway::send: close time.busy=2.42µs time.idle=15.7µs
```

it is a bit verbose, but logging enter/exit allows to see if send was completed (because it may be blocked if it is out of bounds) and the timing.
  • Loading branch information
akoshelev committed Nov 1, 2023
1 parent da2ee44 commit b4d10d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/helpers/gateway/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl<T: Transport, M: Message> ReceivingEnd<T, M> {
/// ## Panics
/// This will panic if message size does not fit into 8 bytes and it somehow got serialized
/// and sent to this helper.
#[tracing::instrument(level = "trace", "receive", skip_all, fields(i = %record_id, from = ?self.channel_id.role, gate = ?self.channel_id.gate.as_ref()))]
pub async fn receive(&self, record_id: RecordId) -> Result<M, Error> {
self.unordered_rx
.recv::<M, _>(record_id)
Expand Down
1 change: 1 addition & 0 deletions src/helpers/gateway/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<M: Message> SendingEnd<M> {
/// call.
///
/// [`set_total_records`]: crate::protocol::context::Context::set_total_records
#[tracing::instrument(level = "trace", "send", skip_all, fields(i = %record_id, total = %self.inner.total_records, to = ?self.channel_id.role, gate = ?self.channel_id.gate.as_ref()))]
pub async fn send(&self, record_id: RecordId, msg: M) -> Result<(), Error> {
let r = self.inner.send(record_id, msg).await;
metrics::increment_counter!(RECORDS_SENT,
Expand Down
12 changes: 11 additions & 1 deletion src/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fmt::{Debug, Formatter},
fmt::{Debug, Display, Formatter},
num::NonZeroUsize,
};

Expand Down Expand Up @@ -441,6 +441,16 @@ pub enum TotalRecords {
Indeterminate,
}

impl Display for TotalRecords {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
TotalRecords::Unspecified => write!(f, "unspecified"),
TotalRecords::Specified(v) => write!(f, "{v}"),
TotalRecords::Indeterminate => write!(f, "∞"),
}
}
}

impl TotalRecords {
#[must_use]
pub fn is_specified(&self) -> bool {
Expand Down
6 changes: 6 additions & 0 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ impl TryFrom<&str> for QueryId {
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RecordId(u32);

impl Display for RecordId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<u32> for RecordId {
fn from(v: u32) -> Self {
RecordId(v)
Expand Down

0 comments on commit b4d10d6

Please sign in to comment.