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

Move Payload pretty-print from Display to Debug #805

Merged
merged 7 commits into from
Oct 10, 2024

Conversation

yuandrew
Copy link
Contributor

@yuandrew yuandrew commented Aug 27, 2024

What was changed

Spencer previously implemented a pretty-print for Display for Payload. Debug was not touched because prost automatically generated the Debug impl for Payload. Prost and tonic-build now support skipping the Debug impl, tokio-rs/prost#797, so we can leverage this to provide our own Debug impl.

Also added support to skip this truncation by specifying the TEMPORAL_PRINT_FULL_PAYLOADS env variable

Why?

A nice-to-have feature to make debug logs more readable.

Checklist

  1. Closes
    [Feature Request] Pretty print Payload data #806

  2. How was this tested:

Generated temporal.api.common.v1.rs now generates

#[cfg_attr(
    feature = "serde_serialize",
    derive(::serde::Serialize, ::serde::Deserialize)
)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[prost(skip_debug)]
pub struct Payload {
    #[prost(map = "string, bytes", tag = "1")]
    pub metadata: ::std::collections::HashMap<
        ::prost::alloc::string::String,
        ::prost::alloc::vec::Vec<u8>,
    >,
    #[prost(bytes = "vec", tag = "2")]
    pub data: ::prost::alloc::vec::Vec<u8>,
}

impl std::fmt::Debug for Payload {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if self.data.len() > 64 {
            let mut windows = self.data.as_slice().windows(32);
            write!(
                f,
                "[{}..{}]",
                BASE64_STANDARD.encode(windows.next().unwrap_or_default()),
                BASE64_STANDARD.encode(windows.next_back().unwrap_or_default())
            )
        } else {
            write!(f, "[{}]", BASE64_STANDARD.encode(&self.data))
        }
    }
}
  1. Any docs updates needed?

@yuandrew yuandrew requested a review from a team as a code owner August 27, 2024 21:52
sdk-core-protos/build.rs Outdated Show resolved Hide resolved
sdk-core-protos/build.rs Outdated Show resolved Hide resolved
Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yaaaaaaay! I'm jazzed for this.

My only remaining thought is that sometimes it may be pretty important to get the full payload dumped to the log, even if it is longer than 64 bytes. I can't really think of any reasonable way to configure than other than an environment variable.

Let's add that so we at least have the option when debugging stuff or if a customer needs to show us some info. We can call it something like TEMPORAL_PRINT_FULL_PAYLOADS and if that's set in the environment, then don't do the >64 byte truncation thing

Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice!

@yuandrew yuandrew merged commit 019a650 into temporalio:master Oct 10, 2024
6 checks passed
@yuandrew yuandrew deleted the pretty_print_debug_payload branch October 10, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants