pub struct TelemetryClient { /* private fields */ }
Expand description

Application Insights telemetry client provides an interface to track telemetry items.

Implementations

Creates a new telemetry client that submits telemetry with specified instrumentation key.

Creates a new telemetry client configured with specified configuration.

Determines whether this client is enabled and will accept telemetry.

Examples
let client = TelemetryClient::new("<instrumentation key>".to_string());
assert!(client.is_enabled());

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!(client.is_enabled());

client.enabled(false);
assert_eq!(client.is_enabled(), false);

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"));

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()));

Logs a user action with the specified name.

Examples
client.track_event("app is running");

Logs a trace message with a specified severity level.

Examples
client.track_trace("Unable to connect to a gateway", SeverityLevel::Warning);

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", 113.0);

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");

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",
    "HTTP",
    "api.github.com",
    true
);

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",
    Duration::from_millis(100),
    true
);

Submits a specific telemetry event.

Examples
use appinsights::telemetry::AggregateMetricTelemetry;

let mut telemetry = AggregateMetricTelemetry::new("device_message_latency_per_min");
telemetry.stats_mut().add_data(&[113.0, 250.0, 316.0]);

client.track(telemetry);

Forces all pending telemetry items to be submitted. The current task 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");
    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;
    }
}

Flushes and tears down the submission flow and closes internal channels. It blocks the current task 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");
}

// wait until pending telemetry is sent at most once and tear down submission flow
client.close_channel().await;

// unable to sent any telemetry after client closes its channel
// client.track_event("app is stopped".to_string());

Tears down the submission flow and closes internal channels. Any telemetry waiting to be sent is discarded. This is a more abrupt version of close_channel. This method consumes the value of client so it makes impossible to use a client with close channel.

This method should be used in cases when the client should be stopped. It is a separate function until async_drop is implemented in rust.

Examples
// send heartbeats while application is running
let running = true;
while running {
    client.track_event("app is running");
}

// wait until pending telemetry is sent at most once and tear down submission flow
client.terminate().await;

// unable to sent any telemetry after client closes its channel
// client.track_event("app is stopped".to_string());

Trait Implementations

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more