chore: add opentelemtry dependencies

🚀 chore(Cargo.toml): update dependencies and add optional tracing-opentelemetry feature
 feat(Cargo.toml): add opentelemetry and opentelemetry-jaeger dependencies as optional features
🚀 chore(Cargo.toml): update tracing and tracing-subscriber dependencies
The dependencies in the Cargo.toml file have been updated to their latest versions. The tracing-opentelemetry feature has been added as an optional feature to the dagger-core and dagger-sdk crates. The opentelemetry and opentelemetry-jaeger dependencies have been added as optional features to the dagger-sdk crate. This allows for the use of OpenTelemetry tracing in the application.
This commit is contained in:
2023-04-30 13:50:05 +02:00
parent 107d3ca0bf
commit bb74617d3f
5 changed files with 242 additions and 23 deletions

View File

@@ -17,6 +17,7 @@ tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
thiserror.workspace = true
tracing-opentelemetry = { workspace = true, optional = true }
base64 = "0.21.0"
dirs = "4.0.0"
@@ -37,3 +38,8 @@ sha2 = "0.10.6"
tar = "0.4.38"
tempfile = "3.3.0"
async-trait = "0.1.67"
[features]
default = []
otel = ["dep:tracing-opentelemetry"]

View File

@@ -20,6 +20,9 @@ serde_json = { workspace = true }
tracing.workspace = true
tracing-subscriber.workspace = true
thiserror.workspace = true
tracing-opentelemetry = { workspace = true, optional = true }
opentelemetry = { workspace = true, optional = true }
opentelemetry-jaeger = { workspace = true, optional = true }
futures = "0.3.28"
derive_builder = "0.12.0"
@@ -29,3 +32,11 @@ pretty_assertions = "1.3.0"
rand = "0.8.5"
genco = "0.17.3"
tracing-test = "0.2.4"
[features]
default = ["otel"]
otel = [
"dep:tracing-opentelemetry",
"dep:opentelemetry",
"dep:opentelemetry-jaeger",
]

View File

@@ -1,11 +1,30 @@
use dagger_core::logger::{DynLogger, Logger};
use tracing::Level;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;
pub fn default_logging() -> eyre::Result<()> {
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
Ok(())
}
#[cfg(feature = "otel")]
pub fn otel_logging() -> eyre::Result<()> {
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_service_name("dagger_sdk")
.install_simple()?;
// Create a tracing layer with the configured tracer
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)?;
Ok(())
}
pub struct StdLogger {}
impl Default for StdLogger {