Skip to content

Commit

Permalink
Gate the span propagation with a feature so it can be opted-out (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
slawlor authored Dec 11, 2024
1 parent 06f9fdf commit 6a08fe2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- name: Run the default tests
package: ractor
# flags:
- name: Test ractor without span propogation
package: ractor
flags: --no-default-features -F tokio_runtime,async-trait
- name: Test ractor with the `cluster` feature
package: ractor
flags: -F cluster
Expand Down
5 changes: 3 additions & 2 deletions ractor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor"
version = "0.13.4"
version = "0.13.5"
authors = ["Sean Lawlor", "Evan Au", "Dillon George"]
description = "A actor framework for Rust"
documentation = "https://docs.rs/ractor"
Expand All @@ -19,10 +19,11 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
[features]
### Other features
cluster = []
message_span_propogation = []
tokio_runtime = ["tokio/time", "tokio/rt", "tokio/macros", "tokio/tracing"]
blanket_serde = ["serde", "pot", "cluster"]

default = ["tokio_runtime", "async-trait"]
default = ["tokio_runtime", "async-trait", "message_span_propogation"]

[dependencies]
## Required dependencies
Expand Down
24 changes: 22 additions & 2 deletions ractor/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ pub trait Message: Any + Send + Sized + 'static {
/// Convert this message to a [BoxedMessage]
#[cfg(feature = "cluster")]
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr> {
let span = {
#[cfg(feature = "message_span_propogation")]
{
Some(tracing::Span::current())
}
#[cfg(not(feature = "message_span_propogation"))]
{
None
}
};
if Self::serializable() && !pid.is_local() {
// it's a message to a remote actor, serialize it and send it over the wire!
Ok(BoxedMessage {
Expand All @@ -145,7 +155,7 @@ pub trait Message: Any + Send + Sized + 'static {
Ok(BoxedMessage {
msg: Some(Box::new(self)),
serialized_msg: None,
span: Some(tracing::Span::current()),
span,
})
} else {
Err(BoxedDowncastErr)
Expand All @@ -156,9 +166,19 @@ pub trait Message: Any + Send + Sized + 'static {
#[cfg(not(feature = "cluster"))]
#[allow(unused_variables)]
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr> {
let span = {
#[cfg(feature = "message_span_propogation")]
{
Some(tracing::Span::current())
}
#[cfg(not(feature = "message_span_propogation"))]
{
None
}
};
Ok(BoxedMessage {
msg: Some(Box::new(self)),
span: Some(tracing::Span::current()),
span,
})
}

Expand Down
2 changes: 1 addition & 1 deletion ractor_cluster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor_cluster"
version = "0.13.4"
version = "0.13.5"
authors = ["Sean Lawlor", "Evan Au", "Dillon George"]
description = "Distributed cluster environment of Ractor actors"
documentation = "https://docs.rs/ractor"
Expand Down
2 changes: 1 addition & 1 deletion ractor_cluster_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ractor_cluster_derive"
version = "0.13.4"
version = "0.13.5"
authors = ["Sean Lawlor <seanlawlor@fb.com>"]
description = "Derives for ractor_cluster"
license = "MIT"
Expand Down

0 comments on commit 6a08fe2

Please sign in to comment.