-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Instrument API for observability (#45)
- Loading branch information
Showing
26 changed files
with
864 additions
and
246 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// Wire format for instrumentation data. | ||
#[derive(Debug, Clone)] | ||
pub struct InstrumentData { | ||
/// Unique identifier for the instrument. | ||
pub id: u64, | ||
/// Message to be sent. | ||
pub message: String, | ||
} | ||
|
||
impl InstrumentData { | ||
pub fn encode_string(&self) -> String { | ||
format!("{}:{}", self.id, self.message) | ||
} | ||
|
||
pub fn decode_string(encoded: &str) -> Option<Self> { | ||
let mut parts = encoded.splitn(2, ':'); | ||
let id = parts.next()?.parse::<u64>().ok()?; | ||
let message = parts.next()?.to_string(); | ||
Some(Self { id, message }) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_instrument_data() { | ||
let data = InstrumentData { | ||
id: 1234, | ||
message: "hello".to_string(), | ||
}; | ||
let encoded = data.encode_string(); | ||
assert_eq!(encoded, "1234:hello"); | ||
let decoded = InstrumentData::decode_string(&encoded).unwrap(); | ||
assert_eq!(decoded.id, data.id); | ||
assert_eq!(decoded.message, data.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod instrument; | ||
pub mod multiplex; | ||
pub mod rpc; | ||
mod schema; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.