opentelemetry-application-insights 0.2.0

OpenTelemetry exporter for Azure Application Insights
Documentation

Crates.io 0.2.0 Documentation 0.2.0 Workflow Status

opentelemetry-application-insights

An Azure Application Insights exporter implementation for OpenTelemetry Rust.

Disclaimer: This is not an official Microsoft product.

Usage

Configure the exporter:

use opentelemetry::{global, sdk};

fn init_tracer() {
    let instrumentation_key = "...".to_string();
    let exporter = opentelemetry_application_insights::Exporter::new(instrumentation_key);
    let provider = sdk::Provider::builder()
        .with_simple_exporter(exporter)
        .build();
    global::set_provider(provider);
}

Then follow the documentation of opentelemetry to create spans and events.

Attribute mapping

OpenTelemetry and Application Insights are using different terminology. This crate tries it's best to map OpenTelemetry fields to their correct Application Insights pendant.

The OpenTelemetry SpanKind determines the Application Insights telemetry type:

OpenTelemetry SpanKind Application Insights telemetry type
CLIENT, PRODUCER, INTERNAL Dependency
SERVER, CONSUMER Request

The Span's list of Events are converted to Trace telemetry.

The Span's status determines the Success field of a Dependency or Request. Success is true if the status is OK; otherwise false.

For INTERNAL Spans the Dependency Type is always "InProc" and Success is true.

The following of the Span's attributes map to special fields in Application Insights (the mapping tries to follow OpenTelemetry semantic conventions).

OpenTelemetry attribute key Application Insights field
enduser.id Context: Authenticated user id
http.url Dependency Data
db.statement Dependency Data
http.host Dependency Target
net.peer.name Dependency Target
db.instance Dependency Target
http.status_code Dependency Result code
db.type Dependency Type
messaging.system Dependency Type
"HTTP" if any http. attribute exists Dependency Type
"DB" if any db. attribute exists Dependency Type
http.url Request Url
http.target Request Url
http.status_code Request Response code

All other attributes are be directly converted to custom properties.

For Requests the attributes http.method and http.route override the Name.

Thanks

This is based on the amazing work by Denis Molokanov. Check out the appinsights crate, if you want a more direct integration with Application Insights.

Application Insights integration

The integration is based on resources mentioned here:

Can I send telemetry to the Application Insights portal?

We recommend you use our SDKs and use the SDK API. There are variants of the SDK for various platforms. These SDKs handle buffering, compression, throttling, retries, and so on. However, the ingestion schema and endpoint protocol are public.

https://docs.microsoft.com/en-us/azure/azure-monitor/faq#can-i-send-telemetry-to-the-application-insights-portal