项目作者: dmolokanov

项目描述 :
Application Insights SDK for Rust
高级语言: Rust
项目地址: git://github.com/dmolokanov/appinsights-rs.git
创建时间: 2019-10-31T06:12:08Z
项目社区:https://github.com/dmolokanov/appinsights-rs

开源协议:MIT License

下载


Application Insights for Rust

build-status
crate-status
docs-status
dependabot-status

This project provides a Rust SDK for Application Insights. Application Insights is an APM service that helps to monitor running applications. This Rust crate allows to send various kinds of telemetry information to the server to be visualized later on Azure Portal.

:triangular_flag_on_post: Disclaimer
This project is not an officially recognized Microsoft product and is not an endorsement of any future product offering from Microsoft.

Microsoft and Azure are registered trademarks of Microsoft Corporation.

Installation

  1. $ cargo add appinsights

or just add this to your Cargo.toml:

  1. [dependencies]
  2. appinisghts = "0.2"

Usage

To start tracking telemetry for your application first thing you need to do is to obtain an Instrumentation Key and initialize TelemetryClient with it.

This client will be used to send all telemetry data to Application Insights. This SDK doesn’t collect any telemetry automatically, so this client should be used everywhere in the code to report health information about an application.

  1. use appinsights::TelemetryClient;
  2. #[tokio::main]
  3. async fn main() {
  4. // configure telemetry client with default settings
  5. let client = TelemetryClient::new("<instrumentation key>".to_string());
  6. // send event telemetry to the Application Insights server
  7. client.track_event("application started");
  8. // stop the client
  9. client.close_channel().await;
  10. }

If you need more control over the client’s behavior, you can create a new instance of TelemetryConfig and initialize a TelemetryClient with it.

  1. use std::time::Duration;
  2. use appinsights::{TelemetryClient, TelemetryConfig};
  3. use appinsights::telemetry::SeverityLevel;
  4. #[tokio::main]
  5. async fn main() {
  6. // configure telemetry config with custom settings
  7. let config = TelemetryConfig::builder()
  8. // provide an instrumentation key for a client
  9. .i_key("<instrumentation key>")
  10. // set a new maximum time to wait until data will be sent to the server
  11. .interval(Duration::from_secs(5))
  12. // construct a new instance of telemetry configuration
  13. .build();
  14. // configure telemetry client with default settings
  15. let client = TelemetryClient::from_config(config);
  16. // send trace telemetry to the Application Insights server
  17. client.track_trace("A database error occurred", SeverityLevel::Warning);
  18. // stop the client
  19. client.close_channel().await;
  20. }

License

This project is licensed under the terms of the MIT license.