telemetry_batteries_macros/
lib.rs

1use proc_macro::TokenStream;
2
3mod metrics;
4mod tracing;
5
6/// Macro to initialize Datadog instrumentation
7///
8/// # Parameters
9///
10/// - `service_name`: Required string literal that specifies the name of the service.
11///
12/// - `endpoint`: Optional string literal that specifies the Datadog agent's endpoint
13///   to which telemetry data will be sent. If not specified, this value defaults to http://localhost:8126.
14///
15/// - `location`: Optional boolean indicates whether to include the location in traces. Defaults to `false` if not specified.
16///
17/// # Usage
18///
19/// To use the `datadog` macro, apply it to the main function
20/// of your application. You must provide the `service_name` parameter, and you may optionally
21/// include `endpoint` and `location` parameters. Due to how the `datadog_layer` from `telemetry-batteries` is configured
22/// the `main` function must be asynchronous and use the `tokio::main` macro after the `datadog` macro.
23#[proc_macro_attribute]
24pub fn datadog(attr: TokenStream, item: TokenStream) -> TokenStream {
25    tracing::datadog::datadog(attr, item)
26}
27
28/// Macro to initialize Stastd metrics backend
29///
30/// # Parameters
31///
32/// - `host`: Optional string literal specifying the StatsD server's IP. Defaults to `"localhost"` if not provided.
33///
34/// - `port`: Optional u16 specifying the port on which the StatsD server is listening.  Defaults to `8125` if not provided.
35///
36/// - `buffer_size`: Optional usize specifying the buffer size (in bytes) that should be buffered in StatsdClient's memory before the data is sent to the server. Defaults to 256 if not provided.
37///
38/// - `queue_size`: Optional usize specifying the size of the queue for storing metrics
39///   before sending to the server. Defaults to 5000 if not provided.
40///
41/// - `prefix`: Optional string literal used as a prefix for all metrics sent. No prefix is added if not provided.
42///
43/// # Usage
44///
45/// To use the `statsd` macro, apply it to the main function
46/// of your application. Due to how the `StatsdBattery` from `telemetry-batteries` is configured
47/// the `main` function must be asynchronous and use the `tokio::main` macro after the `statsd` macro.
48#[proc_macro_attribute]
49pub fn statsd(attr: TokenStream, item: TokenStream) -> TokenStream {
50    metrics::statsd::statsd(attr, item)
51}