-
Notifications
You must be signed in to change notification settings - Fork 592
Add declarative configuration initial version #3226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Changelog | ||
|
|
||
| ## vNext | ||
|
|
||
| ## v0.1.0 | ||
|
|
||
| ### Added | ||
|
|
||
| - Initial declarative configuration |
| 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 } | ||
| 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 | ||
| ] | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
andborja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [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). | ||
| 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>> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we move this to an actual
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
| } | ||
There was a problem hiding this comment.
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-httpandreqwestneed to be added as direct dependencies. You already haveopentelemetry-otlpdependency which should transitively pull these two dependencies.Once you remove these two, you can also remove the
cargo-machetesection as well.