Crate opentelemetry_stdout

source
Expand description

Export telemetry signals to stdout.

This exporter is designed for debugging and learning purposes. It is not recommended for use in production environments. The output format might not be exhaustive and is subject to change at any time.

§Feature Flags

The following feature flags can enable exporters for different telemetry signals:

  • trace: Includes the trace exporters.
  • metrics: Includes the metrics exporters.
  • logs: Includes the logs exporters.

The following feature flags generate additional code and types:

  • populate-logs-event-name: Enables sending LogRecord::event_name as an attribute with the key name

§Examples

{
use opentelemetry::metrics::MeterProvider;
use opentelemetry::trace::{Span, Tracer, TracerProvider as _};
use opentelemetry::{Context, KeyValue};

use opentelemetry_sdk::metrics::{SdkMeterProvider, PeriodicReader};
use opentelemetry_sdk::runtime;
use opentelemetry_sdk::trace::TracerProvider;

use opentelemetry_sdk::logs::LoggerProvider;

fn init_trace() -> TracerProvider {
    let exporter = opentelemetry_stdout::SpanExporter::default();
    TracerProvider::builder()
        .with_simple_exporter(exporter)
        .build()
}

fn init_metrics() -> SdkMeterProvider {
    let exporter = opentelemetry_stdout::MetricsExporter::default();
    let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();
    SdkMeterProvider::builder().with_reader(reader).build()
}

fn init_logs() -> LoggerProvider {
    let exporter = opentelemetry_stdout::LogExporter::default();
    LoggerProvider::builder()
        .with_simple_exporter(exporter)
        .build()
}

let tracer_provider = init_trace();
let meter_provider = init_metrics();
let logger_provider = init_logs();

// recorded traces, metrics and logs will now be sent to stdout:

Structs§

  • An OpenTelemetry exporter that writes Logs to stdout on export.
  • An OpenTelemetry exporter that writes to stdout on export.
  • Configuration for the stdout metrics exporter
  • An OpenTelemetry exporter that writes Spans to stdout on export.