datadog_apm/
lib.rs

1//! Unofficial Datadog APM for Rust.
2//!
3//! Based on [datadog documentation](https://docs.datadoghq.com/api/?lang=bash#send-traces).
4//!
5//! # Overview
6//!
7//! - built for high throughput without block the caller (using tokio channel);
8//! - high configurable with sensible defaults;
9//! - efficient network and resource usage: `traces` buffering + serializing to messagepack;
10//! - discard traces when the buffer queue is full;
11//! - low-level, so it does not automatically instrument your code;
12//!
13//! # Usage
14//!
15//! Add `datadog_apm` and `tokio` to your dependencies:
16//!```not_rust
17//!tokio = { version = "0.2", features = ["full"] }
18//!datadog-apm = "0.2"
19//!```
20//!
21//! - Create the client:
22//! (remember to reuse the same client instead of create a new one everytime, so the buffer can work)
23//! ```no_run
24//! use datadog_apm::{Client, Config};
25//!
26//! let client = Client::new(Config {
27//!     env: Some("production".to_string()),
28//!     service: "my-crate".to_string(),
29//!     ..Default::default()
30//! });
31//! ```
32//!
33//! - create a trace with spans:
34//! (for this example there is a span for a http request and a child-span for the sql transaction)
35//! ```
36//! use datadog_apm::{Trace, Span, HttpInfo, ErrorInfo, SqlInfo};
37//! use std::collections::HashMap;
38//! use std::time::{Duration, SystemTime};
39//!
40//! let trace = Trace {
41//!     id: 123,
42//!     priority: 1,
43//!     spans: vec![Span {
44//!          id: 1,
45//!          parent_id: None,
46//!          name: "request".to_string(),
47//!          resource: "GET /path".to_string(),
48//!          r#type: "web".to_string(),
49//!          start: SystemTime::now(),
50//!          duration: Duration::from_millis(50),
51//!          http: Some(HttpInfo {
52//!              url: String::from("/path/2?param=true"),
53//!              method: String::from("GET"),
54//!              status_code: String::from("500"),
55//!          }),
56//!          error: Some(ErrorInfo {
57//!             r#type: "unknown".to_string(),
58//!             msg: "Internal error".to_string(),
59//!             stack: "stack here".to_string(),
60//!          }),
61//!          sql: None,
62//!          tags: HashMap::new(),
63//!     }, Span {
64//!          id: 2,
65//!          parent_id: Some(1),
66//!          name: "database".to_string(),
67//!          resource: "select".to_string(),
68//!          r#type: "db".to_string(),
69//!          start: SystemTime::now(),
70//!          duration: Duration::from_millis(20),
71//!          http: None,
72//!          error: None,
73//!          sql: Some(SqlInfo {
74//!             query: "select 1".to_string(),
75//!             rows: "1".to_string(),
76//!             db: "test".to_string(),
77//!          }),
78//!          tags: HashMap::new(),
79//!     }]
80//! };
81//! ```
82//!
83//! - send the trace:
84//! ```not_run
85//! client.send_trace(trace);
86//! ```
87//!
88//! And that's it! The trace will be buffered and sent without block the current caller.
89//!
90//!
91//! # Config
92//!
93//! Check [`Config`](struct.Config.html) for all available configurations.
94//!
95//!
96//! # Features that are not included yet: (Contributions welcome!)
97//!
98//! - [ ] [async-std](https://github.com/async-rs/async-std) support.
99//! - [ ] [tracing](https://github.com/tokio-rs/tracing) integration.
100//!
101#[macro_use]
102extern crate log;
103extern crate rmp;
104extern crate rmp_serde as rmps;
105extern crate serde;
106
107mod client;
108
109pub use crate::client::{Client, Config, ErrorInfo, HttpInfo, Span, SqlInfo, Trace};