[−][src]Struct appinsights::TelemetryClient
Application Insights telemetry client provides an interface to track telemetry items.
Methods
impl TelemetryClient<InMemoryChannel>
[src]
pub fn new(i_key: String) -> Self
[src]
Creates a new telemetry client that submits telemetry with specified instrumentation key.
impl TelemetryClient<InMemoryChannel>
[src]
pub fn from_config(config: TelemetryConfig) -> Self
[src]
Creates a new telemetry client configured with specified configuration.
impl<C> TelemetryClient<C> where
C: TelemetryChannel,
[src]
C: TelemetryChannel,
pub fn is_enabled(&self) -> bool
[src]
Determines whether this client is enabled and will accept telemetry.
Examples
let client = TelemetryClient::new("<instrumentation key>".to_string()); assert!(client.is_enabled(), true);
pub fn enabled(&mut self, enabled: bool)
[src]
Enables or disables telemetry client. When disabled, telemetry is silently swallowed by the client. Defaults to enabled.
Examples
let mut client = TelemetryClient::new("<instrumentation key>".to_string()); assert_eq!(client.is_enabled(), true); client.enabled(false); assert_eq!(client.is_enabled(), false);
pub fn context(&self) -> &TelemetryContext
[src]
Returns an immutable reference to a collection of tag data to attach to the telemetry item.
Examples
let mut client = TelemetryClient::new("<instrumentation key>".to_string()); client.context_mut().tags_mut().cloud_mut().set_role("rust_server".to_string()); assert_eq!(client.context().tags().cloud().role(), Some("rust_server"));
pub fn context_mut(&mut self) -> &mut TelemetryContext
[src]
Returns a mutable reference to a collection of tag data to attach to the telemetry item.
Examples
let mut client = TelemetryClient::new("<instrumentation key>".to_string()); client.context_mut().tags_mut().insert("app_version".into(), "v0.1.1".to_string()); client.context_mut().properties_mut().insert("Resource Group".into(), "my-rg".to_string()); assert_eq!(client.context().tags().get("app_version"), Some(&"v0.1.1".to_string())); assert_eq!(client.context().properties().get("Resource Group"), Some(&"my-rg".to_string()));
pub fn track_event(&self, name: String)
[src]
Logs a user action with the specified name.
Examples
client.track_event("app is running".to_string());
pub fn track_trace(&self, message: String, severity: SeverityLevel)
[src]
Logs a trace message with a specified severity level.
Examples
client.track_trace("Unable to connect to a gateway".to_string(), SeverityLevel::Warning);
pub fn track_metric(&self, name: String, value: f64)
[src]
Logs a numeric value that is not specified with a specific event. Typically used to send regular reports of performance indicators.
Examples
client.track_metric("gateway_latency_ms".to_string(), 113.0);
pub fn track_request(
&self,
method: Method,
uri: Uri,
duration: Duration,
response_code: String
)
[src]
&self,
method: Method,
uri: Uri,
duration: Duration,
response_code: String
)
Logs a HTTP request with the specified method, URL, duration and response code.
Examples
use http::{Method, Uri}; use std::time::Duration; let uri: Uri = "https://api.github.com/dmolokanov/appinsights-rs".parse().unwrap(); client.track_request(Method::GET, uri, Duration::from_millis(100), "200".to_string());
pub fn track_remote_dependency(
&self,
name: String,
dependency_type: String,
target: String,
success: bool
)
[src]
&self,
name: String,
dependency_type: String,
target: String,
success: bool
)
Logs a dependency with the specified name, type, target, and success status.
Examples
client.track_remote_dependency( "GET https://api.github.com/dmolokanov/appinsights-rs".to_string(), "HTTP".to_string(), "api.github.com".to_string(), true );
pub fn track_availability(
&self,
name: String,
duration: Duration,
success: bool
)
[src]
&self,
name: String,
duration: Duration,
success: bool
)
Logs an availability test result with the specified test name, duration, and success status.
Examples
use std::time::Duration; client.track_availability( "GET https://api.github.com/dmolokanov/appinsights-rs".to_string(), Duration::from_millis(100), true );
pub fn track<E>(&self, event: E) where
E: Telemetry,
(TelemetryContext, E): Into<Envelope>,
[src]
E: Telemetry,
(TelemetryContext, E): Into<Envelope>,
Submits a specific telemetry event.
Examples
use appinsights::telemetry::AggregateMetricTelemetry; let mut telemetry = AggregateMetricTelemetry::new("device_message_latency_per_min".into()); telemetry.stats_mut().add_data(&[113.0, 250.0, 316.0]); client.track(telemetry);
pub fn close_channel(self)
[src]
Flushes and tears down the submission flow and closes internal channels. It block current thread until all pending telemetry items have been submitted and it is safe to shutdown without losing telemetry. This method consumes the value of client so it makes impossible to use a client with close channel.
Examples
// send heartbeats while application is running let running = true; while running { client.track_event("app is running".to_string()); } // wait until pending telemetry is sent at most once and tear down submission flow client.close_channel(); // unable to sent any telemetry after client closes its channel // client.track_event("app is stopped".to_string());
pub fn flush_channel(&self)
[src]
Forces all pending telemetry items to be submitted. The current thread will not be blocked.
Examples
let mut counter = 0; // send heartbeats while application is running let running = true; while running { client.track_event("app is running".to_string()); counter += 1; // if the rate is bigger than submission interval you can make sure that data is // triggered for submission (each 100 items) if counter == 100 { // trigger submission of all pending items client.flush_channel(); counter = 0; } }
Trait Implementations
impl From<(TelemetryConfig, TelemetryContext)> for TelemetryClient<InMemoryChannel>
[src]
fn from((config, context): (TelemetryConfig, TelemetryContext)) -> Self
[src]
Auto Trait Implementations
impl<C> RefUnwindSafe for TelemetryClient<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for TelemetryClient<C> where
C: Send,
C: Send,
impl<C> Sync for TelemetryClient<C> where
C: Sync,
C: Sync,
impl<C> Unpin for TelemetryClient<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for TelemetryClient<C> where
C: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,