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

refactor(stackable-telemetry): Support Option<T> in subscriber methods #951

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Techassi
Copy link
Member

@Techassi Techassi commented Jan 28, 2025

Part of stackabletech/issues#639

As requested in #901 (comment), this PR enables this:

.with_otlp_log_exporter(
  otlp_log_flag.then(|| Settings::builder()
    .with_environment_variable("ABC_OTLP_LOG")
    .with_default_level(LevelFilter::INFO)
    .build()
  )
)

@Techassi Techassi changed the title refactor: Support Option<T> in subscriber methods refactor(stackable-telemetry): Support Option<T> in subscriber methods Jan 28, 2025
@Techassi Techassi marked this pull request as ready for review January 28, 2025 16:12
/// Console Subscriber log event output format.
pub log_format: Format,
}
pub enum ConsoleLogSettings {
Copy link
Member

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>?

Copy link
Member

@NickLarsenNZ NickLarsenNZ Jan 29, 2025

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>,
{ ... }

Copy link
Member

@NickLarsenNZ NickLarsenNZ Jan 29, 2025

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 {
  ...
}

Copy link
Member

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())
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Development: In Review
Development

Successfully merging this pull request may close these issues.

3 participants