tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.93k stars 508 forks source link

Feature request: Optionally leave out Debug impl #795

Open audunska opened 1 year ago

audunska commented 1 year ago

We are using tonic, prost and tracing in a service handling customer data. All of our endpoint handler functions look like for example

#[instrument(skip(self))]
async fn handle_search_files(
    &self,
    request: SearchFilesRequest,
) -> Result<Response<SearchFilesStream>, Status> {
    ...
}

where the SearchFilesRequest is a prost message. This pushes the request body to the tracing provider using its Debug implementation. However, we would like to limit the amount of customer data pushed to the tracing provider, while still seeing the structure of the request as well as internal ids.

Possible ways of doing this is to manually go through all the endpoints and only push allowed fields to tracing, or to wrap all the request objects in a custom wrapper type with a restricted Debug impl. However, this seems quite brittle and boilerplate-heavy.

One solution that would be really neat is to derive our own Debug impl for the messages, by using a prost_build config with .type_attribute(".", "#[derive(CustomDebug)]"). This custom debug deriver could then consult an internal allowlist for which fields to include in the debug output, and which fields to leave out. However, this is not possible if prost_build already provides its own Debug.

So, my question is: Would it be possible to optionally leave out the Debug impl for messages and oneofs?

LucioFranco commented 1 year ago

Yeah, I think we can just do this https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.disable_comments but for debug impl? Should be pretty easy to add and isn't a breaking change.

audunska commented 1 year ago

Yeah, I think we can just do this https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.disable_comments but for debug impl? Should be pretty easy to add and isn't a breaking change.

One would think that, but the Debug impl is generated in prost-derive as part of the #[derive(Message)] and friends, and that doesn't have access to the config. I guess we could add a struct attribute to control whether Debug is generated.

LucioFranco commented 1 year ago

Ah you're right, maybe we can have a attribute option that sets no debug and then that can be enabled via prost-build.

audunska commented 1 year ago

Ah you're right, maybe we can have a attribute option that sets no debug and then that can be enabled via prost-build.

Yes, I am investigating this option.

AlJohri commented 1 year ago

Related: