Skip to content

Commit

Permalink
feat: Instrument API for observability (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op authored Aug 9, 2024
2 parents b639925 + 04c6da1 commit a0c9e52
Show file tree
Hide file tree
Showing 26 changed files with 864 additions and 246 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions boltapi/src/instrument.rs
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);
}
1 change: 1 addition & 0 deletions boltapi/src/lib.rs
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;
Expand Down
1 change: 1 addition & 0 deletions boltconn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ rusqlite = { version = "0.29.0", features = ["bundled"] }
rustls-pemfile = "2.1.1"
webpki-roots = "0.26.1"
x25519-dalek = "2.0.0-pre.1"
interpolator = "0.5.0"
# Proxies
fast-socks5 = "0.9.1"
boringtun = "0.6.0"
Expand Down
Loading

0 comments on commit a0c9e52

Please sign in to comment.