-
Notifications
You must be signed in to change notification settings - Fork 15
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
refactor(stackable-telemetry): Support Option<T> in subscriber methods #951
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Techassi <[email protected]>
/// Console Subscriber log event output format. | ||
pub log_format: Format, | ||
} | ||
pub enum ConsoleLogSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to implement this toggle separately for each variant, instead of just reusing Option<ConsoleLogSettings>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to abide by the orphan rule - because of impls we needed:
impl<T> From<Option<T>> for BlahSettings
where
T: Into<BlahSettings>,
{ ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or did you mean providing something like:
pub struct GenericSettings<T> {
Disabled,
Enabled<T>,
}
// where T could be Settings or ConsoleSettings, OtlpTraceSettings, etc...
impl<T, U> From<Option<T>> for GenericSettings<U>
where
T: Into<U>,
{ ... }
then
pub struct ConsoleSettings {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I'd avoid the From
entirely; with_file_output
takes an Option<FileLogSettings>
and that's that. But I understand if that's too extreme, or if that ship has sailed already...
As a compromise, we could define our own trait with a blanket impl:
trait IntoLogSettings<S> {
fn into_log_settings(self) -> Option<S>;
}
impl<T: IntoLogSettings, S> IntoLogSettings<S> for Option<T> {
fn into_log_settings(self) -> Option<S> {
self.and_then(|x| x.into_log_settings())
}
}
Part of stackabletech/issues#639
As requested in #901 (comment), this PR enables this: