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

Feature request: Optionally leave out Debug impl #795

Closed
audunska opened this issue Jan 12, 2023 · 6 comments
Closed

Feature request: Optionally leave out Debug impl #795

audunska opened this issue Jan 12, 2023 · 6 comments

Comments

@audunska
Copy link
Contributor

audunska commented Jan 12, 2023

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
Copy link
Member

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
Copy link
Contributor Author

audunska commented Jan 12, 2023

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
Copy link
Member

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
Copy link
Contributor Author

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.

@caspermeijn
Copy link
Collaborator

If this comment helps you, please consider updating the crate documentation to make these features more findable.

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

No branches or pull requests

4 participants