Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]
members = [
"opentelemetry-aws",
"opentelemetry-config",
"opentelemetry-config-stdout",
"opentelemetry-contrib",
"opentelemetry-datadog",
"opentelemetry-etw-logs",
Expand Down
9 changes: 9 additions & 0 deletions opentelemetry-config-stdout/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## vNext

## v0.1.0

### Added

- Initial declarative configuration for stdout (console)
5 changes: 5 additions & 0 deletions opentelemetry-config-stdout/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code owners file.
# This file controls who is tagged for review for any given pull request.

# For anything not explicitly taken by someone else:
* @open-telemetry/rust-approvers
17 changes: 17 additions & 0 deletions opentelemetry-config-stdout/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "opentelemetry-config-stdout"
version = "0.1.0"
description = "Declarative configuration for OpenTelemetry SDK using console (stdout) configuration"
license = "Apache-2.0"
edition = "2021"
rust-version = "1.75.0"

[dependencies]
opentelemetry-config = { path = "../opentelemetry-config" }
opentelemetry_sdk = { version = "0.31.0" }
opentelemetry-stdout = { version = "0.31.0" }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = { version = "0.9.34" }

[lints]
workspace = true
119 changes: 119 additions & 0 deletions opentelemetry-config-stdout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# OpenTelemetry Declarative Configuration for stdout (console)

![OpenTelemetry — An observability framework for cloud-native software.][splash]

[splash]: https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/main/assets/logo-text.png

Declarative configuration for applications instrumented with [`OpenTelemetry`].

[`OpenTelemetry`]: https://crates.io/crates/opentelemetry

## Overview

This crate provides a declarative configuration extension for OpenTelemetry that enables stdout (console) metric exports. It integrates with the `opentelemetry-config` crate to allow YAML-based configuration of the console exporter.

### Features

- Console/stdout metrics exporter configuration via YAML
- Support for both Delta and Cumulative temporality
- Integration with OpenTelemetry declarative configuration
- Simple registration API for declarative configuration

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
opentelemetry-config-stdout = "0.1.0"
```

## Quick Start

### 1. Create a YAML Configuration File

Create a file named `otel-config.yaml`:

```yaml
metrics:
readers:
- periodic:
exporter:
console:
temporality: delta

resource:
service.name: "my-service"
service.version: "1.0.0"
```

### 2. Load and Apply Configuration

```rust
use opentelemetry_config::{ConfigurationProvidersRegistry, TelemetryProvider};
use opentelemetry_config_stdout::ConsolePeriodicExporterProvider;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create configuration registry and register stdout exporter
let mut registry = ConfigurationProvidersRegistry::new();
ConsolePeriodicExporterRegistry::register_into(&mut registry);

// Load configuration from YAML file
let telemetry_provider = TelemetryProvider::new();
let providers = telemetry_provider
.configure_from_yaml_file(&registry, "otel-config.yaml")?;

// Use the configured providers
if let Some(meter_provider) = providers.meter_provider() {
// Your application code here

// Shutdown the created meter provider.
meter_provider.shutdown()?;
}

Ok(())
}
```

## Examples

### Console Exporter Example

See the [examples/console](examples/console) directory for a complete working example that demonstrates:

- Setting up a console exporter provider
- Loading configuration from a YAML file
- Configuring a meter provider
- Proper shutdown handling

To run the example:

```bash
cd examples/console
cargo run -- --file ../metrics_console.yaml
```

## Configuration Schema

### Metrics Configuration

```yaml
metrics:
readers:
- periodic:
exporter:
console:
temporality: delta # or cumulative
```

## Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

## License

This project is licensed under the Apache-2.0 license.

## Release Notes

You can find the release notes (changelog) [here](https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-config-stdout/CHANGELOG.md).
13 changes: 13 additions & 0 deletions opentelemetry-config-stdout/examples/console/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "opentelemetry-config-console-example"
version = "0.1.0"
description = "Declarative configuration for OpenTelemetry SDK example using console configuration"
license = "Apache-2.0"
edition = "2021"
rust-version = "1.75.0"

[workspace]

[dependencies]
opentelemetry-config-stdout = { path = "../../" }
opentelemetry-config = { path = " ../../../../../opentelemetry-config" }
56 changes: 56 additions & 0 deletions opentelemetry-config-stdout/examples/console/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! # Example OpenTelemetry Config Console
//!
//! This example demonstrates how to configure OpenTelemetry Metrics
//! using the OpenTelemetry Config crate with a Console Exporter.

use opentelemetry_config::{providers::TelemetryProvider, ConfigurationProvidersRegistry};
use opentelemetry_config_stdout::ConsolePeriodicExporterProvider;

use std::env;

pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();

if args.len() == 1 || (args.len() > 1 && args[1] == "--help") {
println!("Usage: cargo run -- --file ../metrics_console.yaml");
println!("This example demonstrates how to configure OpenTelemetry Metrics using the OpenTelemetry Config crate with a Console Exporter.");
return Ok(());
}
if args.len() < 3 || args[1] != "--file" {
println!("Error: Configuration file path not provided.");
println!("Usage: cargo run -- --file ../metrics_console.yaml");
return Ok(());
}
let config_file = &args[2];

// Setup configuration registry with console exporter provider.
let mut configuration_providers_registry = ConfigurationProvidersRegistry::new();
ConsolePeriodicExporterProvider::register_into(&mut configuration_providers_registry);

let telemetry_provider = TelemetryProvider::new();
let providers = telemetry_provider
.provide_from_yaml_file(&configuration_providers_registry, config_file)?;

if let Some(meter_provider) = providers.meter_provider() {
println!("Meter provider is configured. Shutting it down...");
meter_provider.shutdown()?;
} else {
println!("No Meter Provider configured.");
}

if let Some(logs_provider) = providers.logs_provider() {
println!("Logs provider is configured. Shutting it down...");
logs_provider.shutdown()?;
} else {
println!("No Logs Provider configured.");
}

if let Some(traces_provider) = providers.traces_provider() {
println!("Traces provider is configured. Shutting it down...");
traces_provider.shutdown()?;
} else {
println!("No Traces Provider configured.");
}

Ok(())
}
9 changes: 9 additions & 0 deletions opentelemetry-config-stdout/examples/metrics_console.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
metrics:
readers:
- periodic:
exporter:
console:
temporality: delta
resource:
service.name: "test-service"
service.version: "1.0.0"
Loading