GithubHelp home page GithubHelp logo

appinsights-rs's Introduction

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.

๐Ÿšฉ 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

$ cargo add appinsights

or just add this to your Cargo.toml:

[dependencies]
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.

use appinsights::TelemetryClient;

#[tokio::main]
async fn main() {
    // configure telemetry client with default settings
    let client = TelemetryClient::new("<instrumentation key>".to_string());
    
    // send event telemetry to the Application Insights server
    client.track_event("application started");

    // stop the client
    client.close_channel().await;
}

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

use std::time::Duration;
use appinsights::{TelemetryClient, TelemetryConfig};
use appinsights::telemetry::SeverityLevel;

#[tokio::main]
async fn main() {
    // configure telemetry config with custom settings
    let config = TelemetryConfig::builder()
        // provide an instrumentation key for a client
        .i_key("<instrumentation key>")
        // set a new maximum time to wait until data will be sent to the server
        .interval(Duration::from_secs(5))
        // construct a new instance of telemetry configuration
        .build();

    // configure telemetry client with default settings
    let client = TelemetryClient::from_config(config);

    // send trace telemetry to the Application Insights server
    client.track_trace("A database error occurred", SeverityLevel::Warning);

    // stop the client
    client.close_channel().await;
}

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.