[−][src]Crate opentelemetry_application_insights
An Azure Application Insights exporter implementation for OpenTelemetry Rust.
Disclaimer: This is not an official Microsoft product.
Usage
Configure a OpenTelemetry pipeline using the Application Insights exporter and start creating spans (this example requires the reqwest-client-blocking feature):
use opentelemetry::trace::Tracer as _; fn main() { let instrumentation_key = std::env::var("INSTRUMENTATION_KEY").unwrap(); let (tracer, _uninstall) = opentelemetry_application_insights::new_pipeline(instrumentation_key) .with_client(reqwest::blocking::Client::new()) .install(); tracer.in_span("main", |_cx| {}); }
Features
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
forasync-std
: enable the surf-client and opentelemetry/async-std features and configure the exporter withwith_client(surf::Client::new())
.reqwest
fortokio
: enable the reqwest-client and opentelemetry/tokio features and configure the exporter withwith_client(reqwest::Client::new())
.reqwest
for synchronous exports: enable the reqwest-blocking-client feature and configure the exporter withwith_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.
Spans
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 status determines the Success field of a Dependency or Request. Success is false
if
the status Error
; otherwise 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).
Note: for INTERNAL
Spans the Dependency Type is always "InProc"
.
OpenTelemetry attribute key | Application Insights field |
---|---|
service.version | Context: Application version |
enduser.id | Context: Authenticated user id |
service.namespace + service.name | Context: Cloud role |
service.instance.id | Context: Cloud role instance |
telemetry.sdk.name + telemetry.sdk.version | Context: Internal SDK version |
http.url | Dependency Data |
db.statement | Dependency Data |
http.host | Dependency Target |
net.peer.name + net.peer.port | Dependency Target |
net.peer.ip + net.peer.port | Dependency Target |
db.name | Dependency Target |
http.status_code | Dependency Result code |
db.system | Dependency Type |
messaging.system | Dependency Type |
rpc.system | Dependency Type |
"HTTP" if any http. attribute exists | Dependency Type |
"DB" if any db. attribute exists | Dependency Type |
http.url | Request Url |
http.scheme + http.host + http.target | Request Url |
http.client_ip | Request Source |
net.peer.ip | Request Source |
http.status_code | Request Response code |
All other attributes are directly converted to custom properties.
For Requests the attributes http.method
and http.route
override the Name.
Events
Events are converted into Exception telemetry if the event name equals "exception"
(see
OpenTelemetry semantic conventions for exceptions) with the following mapping:
OpenTelemetry attribute key | Application Insights field |
---|---|
exception.type | Exception type |
exception.message | Exception message |
exception.stacktrace | Exception call stack |
All other events are converted into Trace telemetry.
All other attributes are directly converted to custom properties.
Structs
Exporter | Application Insights span exporter |
PipelineBuilder | Application Insights exporter pipeline builder |
Uninstall | Guard that uninstalls the Application Insights trace pipeline when dropped |
Traits
HttpClient | HTTP client used by the exporter to send telemetry to Application Insights |
Functions
new_pipeline | Create a new Application Insights exporter pipeline builder |