Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"opentelemetry-*",
"opentelemetry-*/examples/*",
"opentelemetry-otlp/tests/*",
"opentelemetry-declarative-config",
"examples/*",
"stress",
]
Expand Down
9 changes: 9 additions & 0 deletions opentelemetry-declarative-config/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
47 changes: 47 additions & 0 deletions opentelemetry-declarative-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "opentelemetry-declarative-config"
version = "0.29.1"
description = "Declarative configuration for OpenTelemetry SDK"
homepage = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-declarative-config"
repository = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-declarative-config"
readme = "README.md"
categories = [
"development-tools::debugging",
"development-tools::profiling",
]
keywords = ["opentelemetry", "declarative", "metrics", "configuration"]
license = "Apache-2.0"
edition = "2021"
rust-version = "1.75.0"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
opentelemetry = { version = "0.31.0" }
opentelemetry_sdk = { version = "0.31.0", features = ["experimental_metrics_custom_reader"] }
opentelemetry-stdout = { version = "0.31.0" }
opentelemetry-otlp = { version = "0.31.0" }
opentelemetry-http = { workspace = true, optional = true, default-features = false }
serde = { workspace = true, features = ["derive"] }
reqwest = { workspace = true, optional = true }
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think opentelemetry-http and reqwest need to be added as direct dependencies. You already have opentelemetry-otlp dependency which should transitively pull these two dependencies.

Once you remove these two, you can also remove the cargo-machete section as well.

serde_yaml = "0.9.34"

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[features]
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
hyper-client = ["opentelemetry-http/hyper"]
reqwest-client = ["reqwest", "opentelemetry-http/reqwest"]
reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest-blocking"]

# Keep tonic as the default client
default = ["tonic-client"]

[package.metadata.cargo-machete]
ignored = [
"reqwest", # needed for otlp features
"opentelemetry-http" # needed for otlp features
]
30 changes: 30 additions & 0 deletions opentelemetry-declarative-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OpenTelemetry Declarative Configuration

![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 Overview
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This README should talk about OpenTelemetry Declarative Configuration and not general OpenTelemetry overview.


OpenTelemetry is an Observability framework and toolkit designed to create and
manage telemetry data such as traces, metrics, and logs. OpenTelemetry is
vendor- and tool-agnostic, meaning that it can be used with a broad variety of
Observability backends, including open source tools like [Jaeger] and
[Prometheus], as well as commercial offerings.

OpenTelemetry is *not* an observability backend like Jaeger, Prometheus, or other
commercial vendors. OpenTelemetry is focused on the generation, collection,
management, and export of telemetry. A major goal of OpenTelemetry is that you
can easily instrument your applications or systems, no matter their language,
infrastructure, or runtime environment. Crucially, the storage and visualization
of telemetry is intentionally left to other tools.

[`Prometheus`]: https://prometheus.io
[`OpenTelemetry`]: https://crates.io/crates/opentelemetry
[`Jaeger`]: https://www.jaegertracing.io

## Release Notes

You can find the release notes (changelog) [here](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-declarative-config/CHANGELOG.md).
44 changes: 44 additions & 0 deletions opentelemetry-declarative-config/examples/declarative_basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use opentelemetry_declarative_config::Configurator;

/// Example of configuring OpenTelemetry telemetry using declarative YAML configuration.

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a regular main method. We don't need this to be async.

  1. That would clearly convey that this crate does not have any asynchronous APIs
  2. You can also remove the dependency on tokio.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the OTLP implementation requires it. Let's chat on how to avoid it.

let configurator = Configurator::new();
let config_yaml = r#"
metrics:
readers:
- periodic:
exporter:
otlp:
protocol: http/protobuf
endpoint: https://backend:4318
stdout:
temporality: cumulative
logs:
processors:
- batch:
exporter:
stdout:
otlp:
protocol: http/protobuf
endpoint: https://backend:4318
resource:
service.name: sample-service
service.version: "1.0.0"
"#;
Comment on lines +8 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this to an actual .yaml instead of using raw string literal? That would make the example more helpful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this will be embedded most likely in other configurations, the most common use case is actually a string or the object composition itself. I'll add another one with a file for more coverage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples are for our users. Wouldn't the common use case for users be to provide the config in a file? For our tests, we can always use a string.

let result = configurator.configure_telemetry_from_yaml(config_yaml.into());
if let Err(ref e) = result {
panic!("Failed to configure telemetry from YAML string: {}", e);
}
assert!(result.is_ok());
let telemetry_providers = result.unwrap();
assert!(telemetry_providers.meter_provider().is_some());
assert!(telemetry_providers.logs_provider().is_some());
assert!(telemetry_providers.traces_provider().is_none());

println!("All the expected telemetry providers were configured successfully. Shutting down...");

telemetry_providers.shutdown()?;
Ok(())
}
Loading
Loading