Expand description

The OpenTelemetry Dynatrace Exporter supports exporting metric data to Dynatrace.

This exporter only supports the ingestion of metric data using the Dynatrace Metrics ingestion protocol. For trace data, use opentelemetry-otlp as described in the Dynatrace documentation for Rust.

Quickstart

You can start a new Dynatrace metrics pipeline by using DynatracePipelineBuilder::metrics().

use opentelemetry::runtime;
use opentelemetry_sdk::export::metrics::aggregation::cumulative_temporality_selector;
use opentelemetry_sdk::metrics::selectors;
use opentelemetry_sdk::util::tokio_interval_stream;
use opentelemetry_dynatrace::ExportConfig;

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    // First, create a Dynatrace exporter builder. This is a minimal example. The exporter
    // will try to connect to the local OneAgent by default, if no endpoint is set.
    let dynatrace_exporter = opentelemetry_dynatrace::new_exporter();

    // Then pass the exporter into pipeline builder
    let meter = opentelemetry_dynatrace::new_pipeline()
        .metrics(
            selectors::simple::inexpensive(),
            cumulative_temporality_selector(),
            runtime::Tokio,
        )
        .with_exporter(dynatrace_exporter)
        .build();

    Ok(())
}

Kitchen Sink Full Configuration

Example showing how to override all configuration options.

Generally there are two parts of configuration. One part is metrics configuration. Users can set metrics configuration using DynatraceMetricsPipeline. The other part is the exporter configuration. Users can set the exporter configuration using ExportConfig.

use opentelemetry::runtime;
use opentelemetry_sdk::metrics::selectors;
use opentelemetry_sdk::export::metrics::aggregation::cumulative_temporality_selector;
use opentelemetry::KeyValue;
use opentelemetry_dynatrace::transform::DimensionSet;
use opentelemetry_dynatrace::ExportConfig;
use std::collections::HashMap;
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    let export_config = ExportConfig {
        endpoint: Some("https://example.live.dynatrace.com/api/v2/metrics/ingest".to_string()),
        token: Some("*****".to_string())
    };

    let meter = opentelemetry_dynatrace::new_pipeline()
        .metrics(
            selectors::simple::inexpensive(),
            cumulative_temporality_selector(),
            runtime::Tokio,
        )
        .with_exporter(
            opentelemetry_dynatrace::new_exporter()
                .with_export_config(
                    export_config
                        // The export config can also be set by using the with_* functions
                        .with_endpoint("https://example.live.dynatrace.com/api/v2/metrics/ingest")
                        .with_token("*****".to_string())
                )
                .with_headers(HashMap::from([
                    (http::header::USER_AGENT.to_string(), "custom-ua-string".to_string()),
                ]))
        )
        // Send metric data in batches every 3 seconds
        .with_period(Duration::from_secs(3))
        .with_timeout(Duration::from_secs(10))
        //Prefix all metric data keys with a custom prefix
        .with_prefix("quickstart".to_string())
        // Key value pairs that will be added to all metric data
        .with_default_dimensions(DimensionSet::from(vec![
            KeyValue::new("version", env!("CARGO_PKG_VERSION")),
        ]))
        .build();

    Ok(())
}

Modules

Structs

Enums

  • Wrap type for errors from this crate.

Functions

  • Create a new DynatraceExporterBuilder with the default configuration.
  • Create a new pipeline builder with the default configuration.