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)!: Improve stackable-telemetry to make it easier to build the TraceGuard #901

Merged
merged 19 commits into from
Nov 27, 2024

Conversation

NickLarsenNZ
Copy link
Member

@NickLarsenNZ NickLarsenNZ commented Oct 24, 2024

Description

Part of stackabletech/issues#639.

Problem

It is cumbersome to configured the various subscribers to be enabled at runtime. Using @soenkeliebau's code example:

// Instead of building a TraceGuard, a mutable builer needs to be assigned so that...
let mut builder = Tracing::builder()
    .service_name("whoyougonnacall")
    .with_console_output("WYGC_CONSOLE", LevelFilter::INFO);

// ... builder methods can be called conditionally:
if enable_trace_exporter().context(ParseConfigSnafu)? {
    builder = builder.with_otlp_trace_exporter("TEST_OTLP_TRACE", LevelFilter::TRACE);
}
if enable_log_exporter().context(ParseConfigSnafu)? {
    builder = builder.with_otlp_log_exporter("TEST_OTLP_LOG", LevelFilter::TRACE);
}

// Then finally the trace TraceGuard is returned.
let _tracing_guard = builder.build().init().context(InitializeTelemetrySnafu)?;

The purpose of the builder is to allow overriding of the the defaults, however in the current state, the function parameters for the subscribers (console and otlp exporters) break that, and it will only get messier as config options are added.

Solution

Add common and subscriber specific configuration through a Settings builder (suggested by @Techassi). The previous example would then look like:

let _trace_guard = Tracing::builder()
    .service_name("whoyougonnacall")
    .with_console_output(
        Settings::builder()
            .env_var("WYGC_CONSOLE")
            .default_level(LevelFilter::INFO)
            .enabled(true)
            // 👇 this part is new, and has no analogue in the example from the problem statement above.
            .console_log_settings_builder()
            .log_format(Format::Plain)
            // ☝️
            .build(),
    )
    .with_otlp_trace_exporter(
        Settings::builder()
            .env_var("TEST_OTLP_TRACE")
            .default_level(LevelFilter::TRACE)
            .enabled(enable_trace_exporter().context(ParseConfigSnafu)?)
            .build(),
    )
    .with_otlp_log_exporter(
        Settings::builder()
            .env_var("TEST_OTLP_LOG")
            .default_level(LevelFilter::TRACE)
            .enabled(enable_log_exporter().context(ParseConfigSnafu)?)
            .build(),
    )
    .build();

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

Preview Give feedback

Reviewer

Preview Give feedback

@NickLarsenNZ NickLarsenNZ self-assigned this Oct 24, 2024
@NickLarsenNZ NickLarsenNZ force-pushed the stackable-telemetry-builder-improvements branch 4 times, most recently from 36abd6a to 9468ff6 Compare October 25, 2024 09:56
@soenkeliebau
Copy link
Member

I like it!

@NickLarsenNZ
Copy link
Member Author

NickLarsenNZ commented Oct 25, 2024

I like it!

Thanks.

It is basically done, there is one thing left to refactor (and enable console log formats), but before merging I will document the pub items (and enable warn on missing docs).

@NickLarsenNZ NickLarsenNZ force-pushed the stackable-telemetry-builder-improvements branch from 9468ff6 to 71ec75f Compare October 25, 2024 15:39
@NickLarsenNZ NickLarsenNZ force-pushed the stackable-telemetry-builder-improvements branch from ce7266d to 951f5cc Compare November 27, 2024 10:09
@NickLarsenNZ NickLarsenNZ marked this pull request as ready for review November 27, 2024 10:09
@NickLarsenNZ
Copy link
Member Author

NickLarsenNZ commented Nov 27, 2024

This PR was going to include the following items:

  • complete docs
  • tuples for quicker setup
  • console json format output as an option

But they were dropped in order to unblock @xeniape for the RollingFileAppender implementation. I am promising to come back and do those things in a separate PR.

Copy link
Member

@nightkr nightkr left a comment

Choose a reason for hiding this comment

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

Not really relevant since it's excluded from this PR, but the tuple variant smells a lot like "From magic" that I would rather avoid.

crates/stackable-telemetry/src/tracing/settings/mod.rs Outdated Show resolved Hide resolved
crates/stackable-telemetry/src/tracing/settings/mod.rs Outdated Show resolved Hide resolved
@NickLarsenNZ NickLarsenNZ requested a review from nightkr November 27, 2024 14:33
Techassi
Techassi previously approved these changes Nov 27, 2024
@NickLarsenNZ NickLarsenNZ changed the title feat(stackable-telemetry): Improve stackable-telemetry to make it easier to build the TraceGuard refactor(stackable-telemetry)!: Improve stackable-telemetry to make it easier to build the TraceGuard Nov 27, 2024
@NickLarsenNZ NickLarsenNZ added this pull request to the merge queue Nov 27, 2024
Merged via the queue into main with commit 5b152c7 Nov 27, 2024
10 checks passed
@NickLarsenNZ NickLarsenNZ deleted the stackable-telemetry-builder-improvements branch November 27, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants