[][src]Crate opentelemetry_application_insights

An Azure Application Insights exporter implementation for OpenTelemetry Rust.

Disclaimer: This is not an official Microsoft product.


Configure a OpenTelemetry pipeline using the Application Insights exporter and start creating spans (this example requires the reqwest-client-blocking feature):

use opentelemetry::{api::trace::Tracer as _, sdk::trace::Tracer};
use opentelemetry_application_insights::Uninstall;

fn init_tracer() -> (Tracer, Uninstall)  {
    let instrumentation_key = std::env::var("INSTRUMENTATION_KEY").unwrap();

fn main() {
    let (tracer, _uninstall) = init_tracer();
    tracer.in_span("main", |_cx| {});


The functions build and install automatically configure an asynchronous batch exporter if you enable either the async-std or tokio feature for the opentelemetry crate. Otherwise spans will be exported synchronously.

In order to support different async runtimes, the exporter requires you to specify an HTTP client that works with your chosen runtime. This crate comes with support for:

  • surf for async-std: enable the surf-client and opentelemetry/async-std features and configure the exporter with with_client(surf::Client::new()).
  • reqwest for tokio: enable the reqwest-client and opentelemetry/tokio features and configure the exporter with with_client(reqwest::Client::new()).
  • reqwest for synchronous exports: enable the reqwest-blocking-client feature and configure the exporter with with_client(reqwest::blocking::Client::new()).

Alternatively you can bring any other HTTP client by implementing the HttpClient trait.

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 SpanKindApplication Insights telemetry type

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 the OpenTelemetry semantic conventions for trace and resource).

OpenTelemetry attribute keyApplication Insights field
service.versionContext: Application version
enduser.idContext: Authenticated user id
service.namespace + service.nameContext: Cloud role
service.instance.idContext: Cloud role instance
telemetry.sdk.name + telemetry.sdk.versionContext: Internal SDK version
http.urlDependency Data
db.statementDependency Data
http.hostDependency Target
net.peer.name + net.peer.portDependency Target
net.peer.ip + net.peer.portDependency Target
db.nameDependency Target
http.status_codeDependency Result code
db.systemDependency Type
messaging.systemDependency Type
rpc.systemDependency Type
"HTTP" if any http. attribute existsDependency Type
"DB" if any db. attribute existsDependency Type
http.urlRequest Url
http.scheme + http.host + http.targetRequest Url
http.client_ipRequest Source
net.peer.ipRequest Source
http.status_codeRequest Response code

All other attributes are directly converted to custom properties.

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


Events are converted into Exception telemetry if the event name equals "exception" (see OpenTelemetry semantic conventions for exceptions) with the following mapping:

OpenTelemetry attribute keyApplication Insights field
exception.typeException type
exception.messageException message
exception.stacktraceException call stack

All other events are converted into Trace telemetry.

All other attributes are directly converted to custom properties.



Application Insights span exporter


Application Insights exporter pipeline builder


Guard that uninstalls the Application Insights trace pipeline when dropped



HTTP client used by the exporter to send telemetry to Application Insights



Create a new Application Insights exporter pipeline builder