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

feat: add opentelemetry tracing and metrics #202

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 212 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ metrics = [
"lunatic-timer-api/metrics",
"dep:lunatic-metrics-api",
]
prometheus = ["dep:metrics-exporter-prometheus", "metrics"]

[dependencies]
hash-map-id = { workspace = true }
Expand All @@ -59,12 +58,16 @@ async-ctrlc = "1.2.0"
clap = { version = "4.0", features = ["cargo", "derive"] }
dashmap = { workspace = true }
env_logger = "0.9"
hyper = { version = "0.14", features = ["full"] }
log = { workspace = true }
metrics-exporter-prometheus = { version = "0.11.0", optional = true }
opentelemetry = { workspace = true, features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.18.0", git = "https://github.com/tqwewe/opentelemetry-rust", branch = "cow", features = ["rt-tokio"] }
opentelemetry-prometheus = { version = "0.12.0", git = "https://github.com/tqwewe/opentelemetry-rust", branch = "cow" }
prometheus = "0.13"
regex = "1.7"
reqwest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "net"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "net", "signal"] }
toml = "0.5"
uuid = { workspace = true }
wasmtime = { workspace = true }
Expand Down Expand Up @@ -127,6 +130,7 @@ anyhow = "1.0"
bincode = "1.3"
dashmap = "5.4"
log = "0.4"
opentelemetry = { version = "0.19", git = "https://github.com/tqwewe/opentelemetry-rust", branch = "cow", features = ["metrics"] }
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately this PR uses some changes in opentelemetry-rust which are not yet published.

The two PR's are:
open-telemetry/opentelemetry-rust#1009
open-telemetry/opentelemetry-rust#1018

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw PRs got merged, do they plan to release the newer version soon?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at their previous releases, it seems they don't push releases very frequently :(

I've just made a discussion on it, hopefully we can get more insight there
open-telemetry/opentelemetry-rust#1031

metrics = "0.20.1"
reqwest = "0.11"
rustls-pemfile = "1.0"
Expand Down
7 changes: 7 additions & 0 deletions crates/hash-map-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ where
pub fn get(&self, id: u64) -> Option<&T> {
self.store.get(&id)
}

pub fn get_last(&self) -> Option<&T> {
self.store
.iter()
.max_by_key(|(k, _)| **k)
.map(|(_, value)| value)
}
}

impl<T> Default for HashMapId<T>
Expand Down
12 changes: 6 additions & 6 deletions crates/lunatic-messaging-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn take_module<T: ProcessState + ProcessCtx<T> + NetworkingCtx + 'static>(
.or_trap("lunatic::message::take_module")?;
let module = match message {
Message::Data(data) => data
.take_module(index as usize)
.take_resource(index as usize)
.or_trap("lunatic::message::take_module")?,
Message::LinkDied(_) => {
return Err(anyhow!("Unexpected `Message::LinkDied` in scratch area"))
Expand All @@ -316,10 +316,10 @@ fn take_module<T: ProcessState + ProcessCtx<T> + NetworkingCtx + 'static>(
}

// Adds a tcp stream resource to the message that is currently in the scratch area and returns
// the new location of it. This will remove the tcp stream from the current process' resources.
// the new location of it. This will remove the tcp stream from the current process' resources.
//
// Traps:
// * If TCP stream ID doesn't exist
// * If TCP stream ID doesn't exist.
// * If no data message is in the scratch area.
fn push_tcp_stream<T: ProcessState + ProcessCtx<T> + NetworkingCtx>(
mut caller: Caller<T>,
Expand Down Expand Up @@ -361,7 +361,7 @@ fn take_tcp_stream<T: ProcessState + ProcessCtx<T> + NetworkingCtx>(
.or_trap("lunatic::message::take_tcp_stream")?;
let tcp_stream = match message {
Message::Data(data) => data
.take_tcp_stream(index as usize)
.take_resource(index as usize)
.or_trap("lunatic::message::take_tcp_stream")?,
Message::LinkDied(_) => {
return Err(anyhow!("Unexpected `Message::LinkDied` in scratch area"))
Expand Down Expand Up @@ -417,7 +417,7 @@ fn take_tls_stream<T: ProcessState + ProcessCtx<T> + NetworkingCtx>(
.or_trap("lunatic::message::take_tls_stream")?;
let tls_stream = match message {
Message::Data(data) => data
.take_tls_stream(index as usize)
.take_resource(index as usize)
.or_trap("lunatic::message::take_tls_stream")?,
Message::LinkDied(_) => {
return Err(anyhow!("Unexpected `Message::LinkDied` in scratch area"))
Expand Down Expand Up @@ -608,7 +608,7 @@ fn take_udp_socket<T: ProcessState + ProcessCtx<T> + NetworkingCtx>(
.or_trap("lunatic::message::take_udp_socket")?;
let udp_socket = match message {
Message::Data(data) => data
.take_udp_socket(index as usize)
.take_resource(index as usize)
.or_trap("lunatic::message::take_udp_socket")?,
Message::LinkDied(_) => {
return Err(anyhow!("Unexpected `Message::LinkDied` in scratch area"))
Expand Down
11 changes: 8 additions & 3 deletions crates/lunatic-metrics-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ license = "Apache-2.0/MIT"

[dependencies]
anyhow = { workspace = true }
wasmtime = { workspace = true }
metrics = { workspace = true }
lunatic-common-api = { workspace = true }
hash-map-id = { workspace = true }
log = { workspace = true }
lunatic-common-api = { workspace = true }
lunatic-process = { workspace = true }
lunatic-process-api = { workspace = true }
opentelemetry = { workspace = true }
serde_json = "1.0"
metrics = { workspace = true }
wasmtime = { workspace = true }
Loading