-
Notifications
You must be signed in to change notification settings - Fork 482
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
Conversation
What are you trying to achieve with this change? What's your use case? |
Looks like CI isn't passing, but this does appear to simplify the external interface which I'm supportive of 👍 |
7296c6c
to
41671e4
Compare
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 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)
} |
Ha, but I see this isn't compatible with the MSRV:
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 ReportAttention:
📢 Thoughts on this report? Let us know!. |
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.
I think we can maybe bump the MSRV to 1.65?
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.
I can push a patch on bumping msrv
Yeah, I don't know how to make this work without generic associated types. Bumping the MSRV sounds good to me. |
The goal of this is to enable GATs https://blog.rust-lang.org/2022/10/28/gats-stabilization.html Relates to open-telemetry#1314
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>
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>
41671e4
to
7731f6e
Compare
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.
7731f6e
to
a3edffd
Compare
Thanks for bumping the MSRV, hdost@. I rebased and also updated the changelog. |
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.
Thank you @frigus02 !
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.
Thanks!
Changes
RuntimeChannel::batch_message_channel
needs to be generic over the message type. The type used to be declared on theRuntimeChannel<T>
trait. This means aRuntimeChannel
can only be used with one particular message type, which feels unfortunate.This change moves the type argument to the
batch_message_channel<T>
function and the associated typesReceiver<T>
andSender<T>
. Channels are still specific to a message type, but aRuntimeChannel
can be used with any number of message types.This also means the
BatchMessage
types no longer need to be public.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changeslogs::BatchMessage
andtrace::BatchMessage