Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ rustls-tls = ["reqwest/rustls-tls"]
travis-ci = { repository = "nlopes/libhoney-rust", branch = "master" }

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
crossbeam-channel = "0.5"
async-channel = "1.5"
# Need the `unstable` feature to enable `Condvar`. Note that this is unrelated to unstable Rust
# features and does not require a nightly Rust. This pins to the exact version since unstable
# features may not respect SemVer.
async-std = { version = "1.9.0", features = ["unstable"] }
async-trait = "0.1"
chrono = { version = "0.4", default-features = false, features = ["clock", "serde", "std"] }
derivative = "2.2"
futures = "0.3"
log = "0.4"
parking_lot = "0.11"
rand = "0.8"
reqwest = { version = "0.11.0", features = ["blocking", "json"], default-features = false }
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.61"
tokio = { version = "1.0", features = ["time"], default-features = false }

[dev-dependencies]
async_executors = { version = "0.4", features = ["async_std", "tokio_tp"] }
env_logger = "0.8"
mockito = "0.29"
tokio = { version = "1.0", features = ["time"], default-features = false }
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ up background threads to handle sending all the events. Calling .close() on the
will terminate all background threads.

```rust
let client = libhoney::init(libhoney::Config{
use std::sync::Arc;
use async_executors::TokioTpBuilder;

let mut builder = TokioTpBuilder::new();
builder
.tokio_builder()
.enable_io();
let executor = Arc::new(builder.build().expect("failed to build Tokio executor"));
let client = libhoney::init(libhoney::Config {
executor,
options: libhoney::client::Options {
api_key: "YOUR_API_KEY".to_string(),
dataset: "honeycomb-rust-example".to_string(),
..libhoney::client::Options::default()
},
transmission_options: libhoney::transmission::Options::default(),
});
}).expect("failed to spawn Honeycomb client");

client.close();
```
Expand Down Expand Up @@ -112,23 +121,34 @@ you.
#### Simple: send an event
```rust

use std::sync::Arc;
use libhoney::FieldHolder; // Add trait to allow for adding fields
// Call init to get a client
let mut client = init(libhoney::Config {
options: options,
transmission_options: libhoney::transmission::Options::default(),
});

let mut data: HashMap<String, Value> = HashMap::new();
data.insert("duration_ms".to_string(), json!(153.12));
data.insert("method".to_string(), Value::String("get".to_string()));
data.insert("hostname".to_string(), Value::String("appserver15".to_string()));
data.insert("payload_length".to_string(), json!(27));

let mut ev = client.new_event();
ev.add(data);
// In production code, please check return of `.send()`
ev.send(&mut client).err();
use async_executors::TokioTpBuilder;

let mut builder = TokioTpBuilder::new();
builder
.tokio_builder()
.enable_io();
let executor = Arc::new(builder.build().expect("failed to build Tokio executor"));
executor.block_on(async {
// Call init to get a client
let mut client = init(libhoney::Config {
executor: executor.clone(),
options: options,
transmission_options: libhoney::transmission::Options::default(),
}).expect("failed to spawn Honeycomb client");

let mut data: HashMap<String, Value> = HashMap::new();
data.insert("duration_ms".to_string(), json!(153.12));
data.insert("method".to_string(), Value::String("get".to_string()));
data.insert("hostname".to_string(), Value::String("appserver15".to_string()));
data.insert("payload_length".to_string(), json!(27));

let mut ev = client.new_event();
ev.add(data);
// In production code, please check return of `.send()`
ev.send(&mut client).await.err();
})
```

[API reference]: https://docs.rs/libhoney-rust
Expand Down
25 changes: 19 additions & 6 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
use libhoney::{Error, FieldHolder};
use std::sync::Arc;

use async_executors::TokioTpBuilder;
use libhoney::{Error, FieldHolder, FutureExecutor};

fn main() -> Result<(), Error> {
env_logger::init();

let mut client = libhoney::init(libhoney::Config {
let mut builder = TokioTpBuilder::new();
builder.tokio_builder().enable_io().enable_time();
let executor = Arc::new(builder.build().expect("failed to build Tokio executor"));
executor.block_on(async_main(executor.clone()))
}

async fn async_main(executor: FutureExecutor) -> Result<(), Error> {
let client = libhoney::init(libhoney::Config {
executor,
options: libhoney::client::Options {
api_key: std::env::var("HONEYCOMB_API_KEY").expect("need to set HONEYCOMB_API_KEY"),
dataset: std::env::var("HONEYCOMB_DATASET").expect("need to set HONEYCOMB_DATASET"),
..Default::default()
},
transmission_options: libhoney::transmission::Options::default(),
});
})
.expect("failed to spawn Honeycomb client");
let mut event = client.new_event();
event.add_field("extra", libhoney::Value::String("wheeee".to_string()));
event.add_field("extra_ham", libhoney::Value::String("cheese".to_string()));
match event.send(&mut client) {
match event.send(&client).await {
Ok(()) => {
let response = client.responses().iter().next().unwrap();
let response = client.responses().recv().await.unwrap();
assert_eq!(response.error, None);
}
Err(e) => {
log::error!("Could not send event: {}", e);
}
}
client.close()
client.close().await?;
Ok(())
}
Loading