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

tracing-tracy: replace baked-in config fields with a Config trait #91

Merged
merged 5 commits into from
Jan 28, 2024

Conversation

nagisa
Copy link
Owner

@nagisa nagisa commented Jan 6, 2024

This allows users to more flexibly adjust the behaviour of the tracing layer. My favourite examples are actually an ability to implement this structure for some other serialization format that holds the application-wide config. That way people do not need to litter their application set up code with accesses to their configuration, conversion and other concerns.

But with this if people want constant evaluation for performance critical applications, now they can do it too.

@nagisa
Copy link
Owner Author

nagisa commented Jan 6, 2024

In the 2nd commit I went ahead and added an example of how Config trait enables customization beyond what was reasonable with any sort of field-based approach (const or not.)

type Formatter: for<'writer> FormatFields<'writer> + 'static;

/// Use a custom field formatting implementation.
fn formatter(&self) -> &Self::Formatter;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish there was a way to specify a default here. Sadly not much progress: https://rust-lang.github.io/rfcs/2532-associated-type-defaults.html

Copy link
Owner Author

Choose a reason for hiding this comment

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

I wish it was possible too, however even with ATDs it wouldn’t be possible as the method returns a reference to &self and traits do not have access to fields. Achieving this would need something like rust-lang/rfcs#1546.

tracing-tracy/src/config.rs Outdated Show resolved Hide resolved
/// report the issues in whatever way they wish to.
///
/// By default a message coloured in red is emitted to the tracy client.
fn on_error(&self, client: &Client, error: &'static str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooooooh, this is quite a nice flexibility improvement.

tracing-tracy/src/config.rs Outdated Show resolved Hide resolved
tracing-tracy/src/lib.rs Outdated Show resolved Hide resolved
tracing-tracy/src/config.rs Outdated Show resolved Hide resolved
This allows users to more flexibly adjust the behaviour of the tracing
layer. My favourite examples are actually an ability to implement this
structure for some other serialization format that holds the
application-wide config. That way people do not need to litter their
application set up code with accesses to their configuration, conversion
and other concerns.

But with this if people want constant evaluation for performance
critical applications, now they can do it too.
In practice I have found that, whenever a library provides an ability to
configure through a trait generic and then provides a basic runtime
cofniguration convenience-type, the convenience type ends up being
dropped in favour of a manual implementation pretty quickly.

So it seems like a not-terrible-idea to just push users to the trait
immediately? And we don’t need to figure a good design for a
compile-time configuration type…

Might still go back on this decision, idk.
@nagisa nagisa merged commit d51df35 into main Jan 28, 2024
45 checks passed
@nagisa nagisa deleted the nagisa/config-struct branch January 28, 2024 00:01
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.

3 participants