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

Move RuntimeChannel type arg T to batch_message_channel and associated types #1314

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

frigus02
Copy link
Member

@frigus02 frigus02 commented Oct 23, 2023

Changes

RuntimeChannel::batch_message_channel needs to be generic over the message type. The type used to be declared on the RuntimeChannel<T> trait. This means a RuntimeChannel can only be used with one particular message type, which feels unfortunate.

fn install<R: RuntimeChannel<??::BatchMessage>>(runtime: R) {
    // Can't use the same runtime here. :-(
    TracerProvider::builder().with_batch_exporter(e, runtime);
    LoggerProvider::builder().with_batch_exporter(e, runtime);
}

This change moves the type argument to the batch_message_channel<T> function and the associated types Receiver<T> and Sender<T>. Channels are still specific to a message type, but a RuntimeChannel can be used with any number of message types.

fn install<R: RuntimeChannel>(runtime: R) {
    // It works. :-)
    TracerProvider::builder().with_batch_exporter(e, runtime);
    LoggerProvider::builder().with_batch_exporter(e, runtime);
}

This also means the BatchMessage types no longer need to be public.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
    • not applicable, I think
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)
    • Removes logs::BatchMessage and trace::BatchMessage
    • RuntimeChannel is public, so all changes to it here are breaking

@frigus02 frigus02 requested a review from a team October 23, 2023 20:19
@djc
Copy link
Contributor

djc commented Oct 24, 2023

What are you trying to achieve with this change? What's your use case?

@jtescher
Copy link
Member

Looks like CI isn't passing, but this does appear to simplify the external interface which I'm supportive of 👍

@frigus02
Copy link
Member Author

Sorry, I should have really described my use case first:

I recently added live metrics support to opentelemetry-application-insights. It's a separate span processor, which polls Application Insights and sends a handful of automatically collected metrics (e.g. requests per second) in a much more frequent interval to the server as long as a user is watching the metrics.

I couldn't quite use the batch span processor because the polling interval varies. It's shorter when someone is watching. Otherwise it has the same structure: a separate task/thread that calls the server comminuates with the main task via a channel. I think the nicest API here uses RuntimeChannel. Developers already have to provide that when configuring OpenTelemetry and it has everything I need. But I want to use my own message enum and I don't want developers to have to provide 2 different RuntimeChannels.

I want to provide a function like:

fn install_batch<R: RuntimeChannel>(runtime: R) {
    let live_metrics = LiveMetrics::new(runtime.clone());
    TracerProvider::builder().with_batch_exporter(e, runtime).with_span_processor(live_metrics)
}

@frigus02
Copy link
Member Author

Ha, but I see this isn't compatible with the MSRV:

error[E0658]: generic associated types are unstable

I think they were stabilised in https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#generic-associated-types-gats

I might try if that's possible without generic associated types somehow.

@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Files Coverage Δ
...elemetry-contrib/src/trace/exporter/jaeger_json.rs 0.0% <ø> (ø)
opentelemetry-jaeger/src/exporter/runtime.rs 0.0% <ø> (ø)
opentelemetry-otlp/src/span.rs 59.4% <100.0%> (ø)
opentelemetry-sdk/src/runtime.rs 92.9% <100.0%> (+0.8%) ⬆️
opentelemetry-sdk/src/trace/mod.rs 100.0% <ø> (ø)
opentelemetry-sdk/src/trace/span_processor.rs 82.8% <ø> (ø)
opentelemetry-datadog/src/exporter/mod.rs 50.7% <0.0%> (+0.4%) ⬆️
opentelemetry-sdk/src/logs/log_emitter.rs 0.0% <0.0%> (ø)
opentelemetry-sdk/src/logs/log_processor.rs 0.0% <0.0%> (ø)
opentelemetry-sdk/src/trace/provider.rs 89.8% <0.0%> (-0.6%) ⬇️
... and 5 more

📢 Thoughts on this report? Let us know!.

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

I think we can maybe bump the MSRV to 1.65?

Copy link
Contributor

@hdost hdost left a comment

Choose a reason for hiding this comment

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

I can push a patch on bumping msrv

@frigus02
Copy link
Member Author

Yeah, I don't know how to make this work without generic associated types. Bumping the MSRV sounds good to me.

hdost added a commit to hdost/opentelemetry-rust that referenced this pull request Oct 25, 2023
hdost added a commit to hdost/opentelemetry-rust that referenced this pull request Oct 25, 2023
The goal of this is to enable GATs https://blog.rust-lang.org/2022/10/28/gats-stabilization.html

Relates to open-telemetry#1314

Signed-off-by: Harold Dost <h.dost@criteo.com>
@hdost hdost mentioned this pull request Oct 25, 2023
4 tasks
djc pushed a commit that referenced this pull request Oct 26, 2023
The goal of this is to enable GATs https://blog.rust-lang.org/2022/10/28/gats-stabilization.html

Relates to #1314

Signed-off-by: Harold Dost <h.dost@criteo.com>
RuntimeChannel::batch_message_channel needs to be generic over the
message type. The type used to be declared on the RuntimeChannel<T>
trait. This means a RuntimeChannel can only be used with one particular
message type, which feels unfortunate.

    fn install<R: RuntimeChannel<??::BatchMessage>>(runtime: R) {
        // Can't use the same runtime here. :-(
	TracerProvider::builder().with_batch_exporter(e, runtime);
	LoggerProvider::builder().with_batch_exporter(e, runtime);
    }

This change moves the type argument to the batch_message_channel<T>
function and the associated types Receiver<T> and Sender<T>. Channels
are still specific to a message type, but a RuntimeChannel can be used
with any number of message types.

    fn install<R: RuntimeChannel>(runtime: R) {
        // It works. :-)
	TracerProvider::builder().with_batch_exporter(e, runtime);
	LoggerProvider::builder().with_batch_exporter(e, runtime);
    }

This also means the BatchMessage types no longer need to be public.
@frigus02
Copy link
Member Author

Thanks for bumping the MSRV, hdost@. I rebased and also updated the changelog.

Copy link
Contributor

@hdost hdost left a comment

Choose a reason for hiding this comment

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

Thank you @frigus02 !

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

Thanks!

@TommyCpp TommyCpp merged commit 2022ace into open-telemetry:main Oct 27, 2023
@frigus02 frigus02 deleted the runtimechannel branch October 27, 2023 05:28
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.

5 participants