From b568af86b08fc0924bf16b10a3f83bef7a2494bc Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Mon, 21 Oct 2024 12:55:26 -0500 Subject: [PATCH 1/4] [skip ci] yolo --- Cargo.lock | 157 +++++++++++++-- crates/cli/Cargo.toml | 9 +- crates/cli/src/commands/mod.rs | 328 ++++++++++++++++++------------- crates/cli/src/lib.rs | 4 +- crates/cli/src/tracing_bridge.rs | 223 --------------------- crates/cli_bin/Cargo.toml | 8 +- 6 files changed, 342 insertions(+), 387 deletions(-) delete mode 100644 crates/cli/src/tracing_bridge.rs diff --git a/Cargo.lock b/Cargo.lock index d24571252..5169772b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2176,9 +2176,9 @@ dependencies = [ "marzano-gritmodule", "marzano-util", "ntest", - "opentelemetry", + "opentelemetry 0.26.0", "opentelemetry-otlp", - "opentelemetry_sdk", + "opentelemetry_sdk 0.26.0", "predicates", "rayon", "regex", @@ -2187,7 +2187,7 @@ dependencies = [ "tempfile", "tokio", "tracing", - "tracing-opentelemetry", + "tracing-opentelemetry 0.26.0", "tracing-subscriber", ] @@ -2245,9 +2245,11 @@ dependencies = [ "notify", "notify-debouncer-mini", "openssl", - "opentelemetry", + "opentelemetry 0.26.0", + "opentelemetry-appender-tracing", "opentelemetry-otlp", - "opentelemetry_sdk", + "opentelemetry-stdout", + "opentelemetry_sdk 0.26.0", "rayon", "regex", "reqwest 0.11.24", @@ -2258,7 +2260,7 @@ dependencies = [ "tokio", "tracing", "tracing-log", - "tracing-opentelemetry", + "tracing-opentelemetry 0.26.0", "tracing-subscriber", "trim-margin", "uuid", @@ -2293,7 +2295,7 @@ dependencies = [ "sha2", "similar", "tracing", - "tracing-opentelemetry", + "tracing-opentelemetry 0.22.0", "tree-sitter-facade-sg", "trim-margin", "uuid", @@ -2397,7 +2399,7 @@ dependencies = [ "tower", "tower-lsp", "tracing", - "tracing-opentelemetry", + "tracing-opentelemetry 0.22.0", "uuid", ] @@ -2831,6 +2833,46 @@ dependencies = [ "urlencoding", ] +[[package]] +name = "opentelemetry" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "803801d3d3b71cd026851a53f974ea03df3d179cb758b260136a6c9e22e196af" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + +[[package]] +name = "opentelemetry" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570074cc999d1a58184080966e5bd3bf3a9a4af650c3b05047c2621e7405cd17" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + +[[package]] +name = "opentelemetry-appender-tracing" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14f62d9a23c680ab91c74605f5006110768eb67600bb654937fef5c852fb8ec7" +dependencies = [ + "opentelemetry 0.26.0", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "opentelemetry-http" version = "0.10.0" @@ -2840,7 +2882,7 @@ dependencies = [ "async-trait", "bytes", "http 0.2.12", - "opentelemetry", + "opentelemetry 0.21.0", "reqwest 0.11.24", ] @@ -2853,11 +2895,11 @@ dependencies = [ "async-trait", "futures-core", "http 0.2.12", - "opentelemetry", + "opentelemetry 0.21.0", "opentelemetry-http", "opentelemetry-proto", "opentelemetry-semantic-conventions", - "opentelemetry_sdk", + "opentelemetry_sdk 0.21.2", "prost 0.11.9", "reqwest 0.11.24", "thiserror", @@ -2871,8 +2913,8 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2e155ce5cc812ea3d1dffbd1539aed653de4bf4882d60e6e04dcf0901d674e1" dependencies = [ - "opentelemetry", - "opentelemetry_sdk", + "opentelemetry 0.21.0", + "opentelemetry_sdk 0.21.2", "prost 0.11.9", "tonic", ] @@ -2883,7 +2925,24 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5774f1ef1f982ef2a447f6ee04ec383981a3ab99c8e77a1a7b30182e65bbc84" dependencies = [ - "opentelemetry", + "opentelemetry 0.21.0", +] + +[[package]] +name = "opentelemetry-stdout" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5c185afbc26decc6f10d728971847e3f96532d2b3fb7db2569c1bce154509b" +dependencies = [ + "async-trait", + "chrono", + "futures-util", + "opentelemetry 0.26.0", + "opentelemetry_sdk 0.26.0", + "ordered-float", + "serde", + "serde_json", + "thiserror", ] [[package]] @@ -2899,12 +2958,48 @@ dependencies = [ "futures-util", "glob", "once_cell", - "opentelemetry", + "opentelemetry 0.21.0", "ordered-float", "percent-encoding", "rand", "serde_json", "thiserror", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0da0d6b47a3dbc6e9c9e36a0520e25cf943e046843818faaa3f87365a548c82" +dependencies = [ + "async-trait", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry 0.25.0", + "percent-encoding", + "rand", + "thiserror", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c627d9f4c9cdc1f21a29ee4bfbd6028fcb8bcf2a857b43f3abdf72c9c862f3" +dependencies = [ + "async-trait", + "futures-channel", + "futures-executor", + "futures-util", + "glob", + "once_cell", + "opentelemetry 0.26.0", + "percent-encoding", + "rand", + "serde_json", + "thiserror", "tokio", "tokio-stream", ] @@ -4300,12 +4395,28 @@ checksum = "c67ac25c5407e7b961fafc6f7e9aa5958fd297aada2d20fa2ae1737357e55596" dependencies = [ "js-sys", "once_cell", - "opentelemetry", - "opentelemetry_sdk", + "opentelemetry 0.21.0", + "opentelemetry_sdk 0.21.2", + "tracing", + "tracing-core", + "tracing-subscriber", + "web-time 0.2.4", +] + +[[package]] +name = "tracing-opentelemetry" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eabc56d23707ad55ba2a0750fc24767125d5a0f51993ba41ad2c441cc7b8dea" +dependencies = [ + "js-sys", + "once_cell", + "opentelemetry 0.25.0", + "opentelemetry_sdk 0.25.0", "tracing", "tracing-core", "tracing-subscriber", - "web-time", + "web-time 1.1.0", ] [[package]] @@ -5278,6 +5389,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "web-tree-sitter-sg" version = "1.3.4" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 4edaf29e5..3591c9618 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -69,12 +69,15 @@ opentelemetry-otlp = { version = "0.14.0", optional = true, default-features = f "trace", "grpc-tonic", ] } -opentelemetry = { version = "0.21.0", optional = true } -opentelemetry_sdk = { version = "0.21.1", optional = true, features = [ + +opentelemetry-stdout = "0.26.0" +opentelemetry-appender-tracing = { version = "0.26.0" } +opentelemetry = { version = "0.26.0", optional = true } +opentelemetry_sdk = { version = "0.26.0", optional = true, features = [ "rt-tokio", "logs", ] } -tracing-opentelemetry = { version = "0.22.0", optional = true, default-features = false } +tracing-opentelemetry = { version = "0.26.0", optional = true, default-features = false } tracing = { version = "0.1.40", default-features = false, features = [] } notify = "6.1.1" diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index fb46cbb0c..283c954c9 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -499,159 +499,213 @@ fn get_otel_key(env_name: &str) -> Option { } #[cfg(feature = "grit_tracing")] -fn get_otel_setup() -> Result> { - let grafana_key = get_otel_key("GRAFANA_OTEL_KEY"); - let honeycomb_key = get_otel_key("HONEYCOMB_OTEL_KEY"); - let baselime_key = get_otel_key("BASELIME_OTEL_KEY"); - let hyperdx_key = get_otel_key("HYPERDX_OTEL_KEY"); - - let env = get_otel_key("GRIT_DEPLOYMENT_ENV").unwrap_or_else(|| "prod".to_string()); - - let (endpoint, headers) = match (grafana_key, honeycomb_key, baselime_key, hyperdx_key) { - (None, None, None, None) => { - if let Some(endpoint) = get_otel_key("OTEL_EXPORTER_OTLP_ENDPOINT") { - eprintln!( - "No explicit OTLP key found, using default OTLP endpoint: {}", - endpoint - ); - (Some(endpoint), None) - } else { - #[cfg(feature = "server")] - eprintln!("No OTLP key found, tracing will be disabled"); - return Ok(None); - } - } - - (Some(grafana_key), _, _, _) => { - let instance_id = "665534"; - let encoded = - base64::encode_from_string(format!("{}:{}", instance_id, grafana_key).as_str())?; - let endpoint = "https://otlp-gateway-prod-us-central-0.grafana.net/otlp".to_string(); - let headers = - HashMap::from([("Authorization".to_string(), format!("Basic {}", encoded))]); - eprintln!("Using Grafana OTLP key for {}", env); - (Some(endpoint), Some(headers)) - } - (_, Some(honeycomb_key), _, _) => { - let endpoint = "https://api.honeycomb.io".to_string(); - let headers = HashMap::from([("x-honeycomb-team".to_string(), honeycomb_key)]); - eprintln!("Using Honeycomb OTLP key for {}", env); - (Some(endpoint), Some(headers)) - } - (_, _, Some(baselime_key), _) => { - let endpoint = "https://otel.baselime.io/v1/".to_string(); - let headers = HashMap::from([ - ("x-api-key".to_string(), baselime_key), - ("x-baselime-dataset".to_string(), "otel".to_string()), - ]); - eprintln!("Using Baselime OTLP key for {}", env); - (Some(endpoint), Some(headers)) - } - (_, _, _, Some(hyperdx_key)) => { - let endpoint = "https://in-otel.hyperdx.io".to_string(); - let headers = HashMap::from([("authorization".to_string(), hyperdx_key)]); - eprintln!("Using HyperDX OTLP key for {}", env); - (Some(endpoint), Some(headers)) - } - }; - - let client = reqwest::Client::new(); - - let mut resource_attrs = vec![ - KeyValue::new("service.name", "grit_marzano".to_string()), - KeyValue::new("deployment.environment.name", env), - ]; - - if let Some(execution_id) = get_otel_key("GRIT_EXECUTION_ID") { - resource_attrs.push(KeyValue::new("grit.execution.id", execution_id)); - } - - let resource = Resource::new(resource_attrs); +// fn get_otel_setup() -> Result> { +// let grafana_key = get_otel_key("GRAFANA_OTEL_KEY"); +// let honeycomb_key = get_otel_key("HONEYCOMB_OTEL_KEY"); +// let baselime_key = get_otel_key("BASELIME_OTEL_KEY"); +// let hyperdx_key = get_otel_key("HYPERDX_OTEL_KEY"); + +// let env = get_otel_key("GRIT_DEPLOYMENT_ENV").unwrap_or_else(|| "prod".to_string()); + +// let (endpoint, headers) = match (grafana_key, honeycomb_key, baselime_key, hyperdx_key) { +// (None, None, None, None) => { +// if let Some(endpoint) = get_otel_key("OTEL_EXPORTER_OTLP_ENDPOINT") { +// eprintln!( +// "No explicit OTLP key found, using default OTLP endpoint: {}", +// endpoint +// ); +// (Some(endpoint), None) +// } else { +// #[cfg(feature = "server")] +// eprintln!("No OTLP key found, tracing will be disabled"); +// return Ok(None); +// } +// } + +// (Some(grafana_key), _, _, _) => { +// let instance_id = "665534"; +// let encoded = +// base64::encode_from_string(format!("{}:{}", instance_id, grafana_key).as_str())?; +// let endpoint = "https://otlp-gateway-prod-us-central-0.grafana.net/otlp".to_string(); +// let headers = +// HashMap::from([("Authorization".to_string(), format!("Basic {}", encoded))]); +// eprintln!("Using Grafana OTLP key for {}", env); +// (Some(endpoint), Some(headers)) +// } +// (_, Some(honeycomb_key), _, _) => { +// let endpoint = "https://api.honeycomb.io".to_string(); +// let headers = HashMap::from([("x-honeycomb-team".to_string(), honeycomb_key)]); +// eprintln!("Using Honeycomb OTLP key for {}", env); +// (Some(endpoint), Some(headers)) +// } +// (_, _, Some(baselime_key), _) => { +// let endpoint = "https://otel.baselime.io/v1/".to_string(); +// let headers = HashMap::from([ +// ("x-api-key".to_string(), baselime_key), +// ("x-baselime-dataset".to_string(), "otel".to_string()), +// ]); +// eprintln!("Using Baselime OTLP key for {}", env); +// (Some(endpoint), Some(headers)) +// } +// (_, _, _, Some(hyperdx_key)) => { +// let endpoint = "https://in-otel.hyperdx.io".to_string(); +// let headers = HashMap::from([("authorization".to_string(), hyperdx_key)]); +// eprintln!("Using HyperDX OTLP key for {}", env); +// (Some(endpoint), Some(headers)) +// } +// }; + +// let client = reqwest::Client::new(); + +// let mut resource_attrs = vec![ +// KeyValue::new("service.name", "grit_marzano".to_string()), +// KeyValue::new("deployment.environment.name", env), +// ]; + +// if let Some(execution_id) = get_otel_key("GRIT_EXECUTION_ID") { +// resource_attrs.push(KeyValue::new("grit.execution.id", execution_id)); +// } + +// let resource = Resource::new(resource_attrs); + +// let mut logger_exporter = opentelemetry_otlp::new_exporter() +// .http() +// .with_http_client(client.clone()) +// .with_timeout(std::time::Duration::from_millis(500)); +// if let Some(endpoint) = &endpoint { +// logger_exporter = logger_exporter.with_endpoint(endpoint.clone()); +// } +// if let Some(headers) = &headers { +// logger_exporter = logger_exporter.with_headers(headers.clone()); +// } + +// let mut tracer_exporter = opentelemetry_otlp::new_exporter() +// .http() +// .with_http_client(client.clone()) +// .with_timeout(std::time::Duration::from_millis(500)); +// if let Some(endpoint) = endpoint { +// tracer_exporter = tracer_exporter.with_endpoint(endpoint); +// } +// if let Some(headers) = headers { +// tracer_exporter = tracer_exporter.with_headers(headers); +// } + +// let logger = opentelemetry_otlp::new_pipeline() +// .logging() +// .with_exporter(logger_exporter) +// .with_log_config( +// opentelemetry_sdk::logs::BatchConfig::default().with_resource(resource.clone()), +// ) +// .install_batch(opentelemetry_sdk::runtime::Tokio)?; + +// let tracer = opentelemetry_otlp::new_pipeline() +// .tracing() +// .with_exporter(tracer_exporter) +// .with_trace_config(trace::config().with_resource(resource)) +// .install_batch(opentelemetry_sdk::runtime::Tokio)?; + +// let logger_provider = logger.provider().unwrap(); + +// Ok(Some((tracer, logger_provider))) +// } - let mut logger_exporter = opentelemetry_otlp::new_exporter() - .http() - .with_http_client(client.clone()) - .with_timeout(std::time::Duration::from_millis(500)); - if let Some(endpoint) = &endpoint { - logger_exporter = logger_exporter.with_endpoint(endpoint.clone()); - } - if let Some(headers) = &headers { - logger_exporter = logger_exporter.with_headers(headers.clone()); - } +pub async fn run_command_with_tracing() -> Result<()> { + #[cfg(feature = "grit_tracing")] + { + // let otel = get_otel_setup()?; + + use opentelemetry::global; + use opentelemetry::trace::FutureExt; + use opentelemetry::trace::TraceContextExt; + use opentelemetry::trace::Tracer; + use opentelemetry_appender_tracing::layer; + use opentelemetry_sdk::logs::LoggerProvider; + use opentelemetry_sdk::trace::TracerProvider; + use opentelemetry_stdout as stdout; + use tracing::info; + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::Registry; + + // Create a new OpenTelemetry trace pipeline that prints to stdout + let tracer_provider = TracerProvider::builder() + .with_simple_exporter(stdout::SpanExporter::default()) + .build(); + global::set_tracer_provider(tracer_provider); + + let tracing_layer = tracing_opentelemetry::layer(); + + let log_provider = LoggerProvider::builder() + .with_simple_exporter(stdout::LogExporter::default()) + .build(); + + //let log_layer = layer::OpenTelemetryTracingBridge::new(&log_provider); + let log_layer = layer::OpenTelemetryTracingBridge::new(&log_provider); + + let subscriber = Registry::default().with(tracing_layer).with(log_layer); + tracing::subscriber::set_global_default(subscriber) + .expect("setting tracing default failed"); + + // let root_span = span!(Level::INFO, "grit_marzano.run_command"); + + // tracing::subscriber::with_default(subscriber, || { + // Spans will be sent to the configured OpenTelemetry exporter + let tracer = global::tracer("dash0"); + + // let root_span = span!(Level::INFO, "grit_marzano.run_command"); + let root_span = tracer.start("grit_marzano.run_command"); + + // Perform some async work with this span as the currently active parent. + run_command(true) + .with_context(opentelemetry::Context::current_with_span(root_span)) + .await; - let mut tracer_exporter = opentelemetry_otlp::new_exporter() - .http() - .with_http_client(client.clone()) - .with_timeout(std::time::Duration::from_millis(500)); - if let Some(endpoint) = endpoint { - tracer_exporter = tracer_exporter.with_endpoint(endpoint); - } - if let Some(headers) = headers { - tracer_exporter = tracer_exporter.with_headers(headers); - } + log::info!("ending the CLI!"); - let logger = opentelemetry_otlp::new_pipeline() - .logging() - .with_exporter(logger_exporter) - .with_log_config(opentelemetry_sdk::logs::config().with_resource(resource.clone())) - .install_batch(opentelemetry_sdk::runtime::Tokio)?; + // }); - let tracer = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(tracer_exporter) - .with_trace_config(trace::config().with_resource(resource)) - .install_batch(opentelemetry_sdk::runtime::Tokio)?; + // Spans will be sent to the configured OpenTelemetry exporter + // let res = async move { + // event!(Level::INFO, "starting the CLI!"); - let logger_provider = logger.provider().unwrap(); + // let res = run_command(true).await; - Ok(Some((tracer, logger_provider))) -} + // event!(Level::INFO, "ending the CLI!"); -pub async fn run_command_with_tracing() -> Result<()> { - #[cfg(feature = "grit_tracing")] - { - let otel = get_otel_setup()?; + // res + // } + // .instrument(root_span) + // .await; - if let Some((tracer, logger)) = otel { - let env_filter = EnvFilter::try_from_default_env() - .unwrap_or(EnvFilter::new("TRACE")) - // Exclude noisy tokio stuff "h2::proto::streams::prioritize - .add_directive("h2=off".parse().unwrap()) - // This is also noisy - .add_directive("axum::serve=DEBUG".parse().unwrap()) - // We don't want to trace the tracing library itself - .add_directive("hyper=off".parse().unwrap()); + return Ok(()); - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - let logger_layer = crate::tracing_bridge::OpenTelemetryTracingBridge::new(&logger); + // if let Some((tracer, logger)) = otel { + // let env_filter = EnvFilter::try_from_default_env() + // .unwrap_or(EnvFilter::new("TRACE")) + // // Exclude noisy tokio stuff "h2::proto::streams::prioritize + // .add_directive("h2=off".parse().unwrap()) + // // This is also noisy + // .add_directive("axum::serve=DEBUG".parse().unwrap()) + // // We don't want to trace the tracing library itself + // .add_directive("hyper=off".parse().unwrap()); - let subscriber = Registry::default() - .with(env_filter) - .with(telemetry) - .with(logger_layer); + // let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + // let logger_layer = opentelemOpenTelemetryTracingBridge::new(&logger); - global::set_text_map_propagator(TraceContextPropagator::new()); - tracing::subscriber::set_global_default(subscriber) - .expect("setting tracing default failed"); + // let subscriber = Registry::default() + // .with(env_filter) + // .with(telemetry) + // .with(logger_layer); - let root_span = span!(Level::INFO, "grit_marzano.cli_command",); + // global::set_text_map_propagator(TraceContextPropagator::new()); - let res = async move { - event!(Level::INFO, "starting the CLI!"); + // // tracer.in_span("app_init", res); - let res = run_command(true).await; + // // let res = async move { res } - event!(Level::INFO, "ending the CLI!"); + // opentelemetry::global::shutdown_tracer_provider(); - res - } - .instrument(root_span) - .await; - - opentelemetry::global::shutdown_tracer_provider(); - - return res; - } + // return res; + // } } let subscriber = tracing::subscriber::NoSubscriber::new(); tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index f952c302e..486adebad 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -19,8 +19,8 @@ mod ux; #[cfg(feature = "workflows_v2")] mod workflows; -#[cfg(feature = "grit_tracing")] -mod tracing_bridge; +// #[cfg(feature = "grit_tracing")] +// mod tracing_bridge; // We use git2, which depends on openssl, which by-default wants to // dynamically link libopenssl. We explicitly depend on openssl to diff --git a/crates/cli/src/tracing_bridge.rs b/crates/cli/src/tracing_bridge.rs deleted file mode 100644 index a3379f6cc..000000000 --- a/crates/cli/src/tracing_bridge.rs +++ /dev/null @@ -1,223 +0,0 @@ -/// This file is a modified version of the opentelemetry-appender-tracing crate. -/// We need to use this to bridge between the opentelemetry and the tracing crate. -/// The opentelemetry-appender-tracing crate has version mismatch issues. -/// Source: https://github.com/open-telemetry/opentelemetry-rust/blob/v0.22.1/opentelemetry-appender-tracing/src/layer.rs -/// -/// Includes the workaround for https://github.com/open-telemetry/opentelemetry-rust/issues/1378 -/// From https://github.com/open-telemetry/opentelemetry-rust/pull/1394 -/// -/// Copyright The OpenTelemetry Authors -/// Modified by Iuvo AI, Inc. -use opentelemetry::{ - logs::{AnyValue, LogRecord, Logger, LoggerProvider, Severity}, - Key, -}; -use std::borrow::Cow; -use tracing_subscriber::registry::LookupSpan; - -use tracing::{field::Field, Level, Metadata}; -#[cfg(feature = "experimental_metadata_attributes")] -use tracing_log::NormalizeEvent; -use tracing_subscriber::Layer; - -const INSTRUMENTATION_LIBRARY_NAME: &str = "opentelemetry-appender-tracing"; - -/// Visitor to record the fields from the event record. -#[derive(Default)] -struct EventVisitor { - log_record_attributes: Vec<(Key, AnyValue)>, - log_record_body: Option, -} - -/// Logs from the log crate have duplicated attributes that we removed here. -#[cfg(feature = "experimental_metadata_attributes")] -fn is_duplicated_metadata(field: &'static str) -> bool { - field - .strip_prefix("log.") - .map(|remainder| matches!(remainder, "file" | "line" | "module_path" | "target")) - .unwrap_or(false) -} - -#[cfg(feature = "experimental_metadata_attributes")] -fn get_filename(filepath: &str) -> &str { - if let Some((_, filename)) = filepath.rsplit_once('/') { - return filename; - } - if let Some((_, filename)) = filepath.rsplit_once('\\') { - return filename; - } - filepath -} - -impl EventVisitor { - fn visit_metadata(&mut self, meta: &Metadata) { - self.log_record_attributes - .push(("name".into(), meta.name().into())); - - #[cfg(feature = "experimental_metadata_attributes")] - self.visit_experimental_metadata(meta); - } - - #[cfg(feature = "experimental_metadata_attributes")] - fn visit_experimental_metadata(&mut self, meta: &Metadata) { - self.log_record_attributes - .push(("log.target".into(), meta.target().to_owned().into())); - - if let Some(module_path) = meta.module_path() { - self.log_record_attributes - .push(("code.namespace".into(), module_path.to_owned().into())); - } - - if let Some(filepath) = meta.file() { - self.log_record_attributes - .push(("code.filepath".into(), filepath.to_owned().into())); - self.log_record_attributes.push(( - "code.filename".into(), - get_filename(filepath).to_owned().into(), - )); - } - - if let Some(line) = meta.line() { - self.log_record_attributes - .push(("code.lineno".into(), line.into())); - } - } - - fn push_to_otel_log_record(self, log_record: &mut LogRecord) { - log_record.body = self.log_record_body; - log_record.attributes = Some(self.log_record_attributes); - } -} - -impl tracing::field::Visit for EventVisitor { - fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) { - #[cfg(feature = "experimental_metadata_attributes")] - if is_duplicated_metadata(field.name()) { - return; - } - if field.name() == "message" { - self.log_record_body = Some(format!("{value:?}").into()); - } else { - self.log_record_attributes - .push((field.name().into(), format!("{value:?}").into())); - } - } - - fn record_str(&mut self, field: &Field, value: &str) { - #[cfg(feature = "experimental_metadata_attributes")] - if is_duplicated_metadata(field.name()) { - return; - } - self.log_record_attributes - .push((field.name().into(), value.to_owned().into())); - } - - fn record_bool(&mut self, field: &Field, value: bool) { - self.log_record_attributes - .push((field.name().into(), value.into())); - } - - fn record_f64(&mut self, field: &tracing::field::Field, value: f64) { - self.log_record_attributes - .push((field.name().into(), value.into())); - } - - fn record_i64(&mut self, field: &tracing::field::Field, value: i64) { - #[cfg(feature = "experimental_metadata_attributes")] - if is_duplicated_metadata(field.name()) { - return; - } - self.log_record_attributes - .push((field.name().into(), value.into())); - } - - // TODO: Remaining field types from AnyValue : Bytes, ListAny, Boolean -} - -pub struct OpenTelemetryTracingBridge -where - P: LoggerProvider + Send + Sync, - L: Logger + Send + Sync, -{ - logger: L, - _phantom: std::marker::PhantomData

, // P is not used. -} - -impl OpenTelemetryTracingBridge -where - P: LoggerProvider + Send + Sync, - L: Logger + Send + Sync, -{ - pub fn new(provider: &P) -> Self { - OpenTelemetryTracingBridge { - logger: provider.versioned_logger( - INSTRUMENTATION_LIBRARY_NAME, - Some(Cow::Borrowed(env!("CARGO_PKG_VERSION"))), - None, - None, - ), - _phantom: Default::default(), - } - } -} - -impl Layer for OpenTelemetryTracingBridge -where - S: tracing::Subscriber + for<'a> LookupSpan<'a>, - P: LoggerProvider + Send + Sync + 'static, - L: Logger + Send + Sync + 'static, -{ - fn on_event( - &self, - event: &tracing::Event<'_>, - _ctx: tracing_subscriber::layer::Context<'_, S>, - ) { - #[cfg(feature = "experimental_metadata_attributes")] - let normalized_meta = event.normalized_metadata(); - #[cfg(feature = "experimental_metadata_attributes")] - let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata()); - - #[cfg(not(feature = "experimental_metadata_attributes"))] - let meta = event.metadata(); - - let mut log_record: LogRecord = LogRecord::default(); - log_record.severity_number = Some(severity_of_level(meta.level())); - log_record.severity_text = Some(meta.level().to_string().into()); - - // Extract the trace_id & span_id from the opentelemetry extension. - // This isn't really working for us. - // set_trace_context(&mut log_record, &_ctx); - - // Not populating ObservedTimestamp, instead relying on OpenTelemetry - // API to populate it with current time. - - let mut visitor = EventVisitor::default(); - visitor.visit_metadata(meta); - // Visit fields. - event.record(&mut visitor); - visitor.push_to_otel_log_record(&mut log_record); - - self.logger.emit(log_record); - } - - #[cfg(feature = "logs_level_enabled")] - fn event_enabled( - &self, - _event: &Event<'_>, - _ctx: tracing_subscriber::layer::Context<'_, S>, - ) -> bool { - let severity = severity_of_level(_event.metadata().level()); - self.logger - .event_enabled(severity, _event.metadata().target()) - } -} - -const fn severity_of_level(level: &Level) -> Severity { - match *level { - Level::TRACE => Severity::Trace, - Level::DEBUG => Severity::Debug, - Level::INFO => Severity::Info, - Level::WARN => Severity::Warn, - Level::ERROR => Severity::Error, - } -} diff --git a/crates/cli_bin/Cargo.toml b/crates/cli_bin/Cargo.toml index 5a8c026f5..332aad5f0 100644 --- a/crates/cli_bin/Cargo.toml +++ b/crates/cli_bin/Cargo.toml @@ -25,12 +25,12 @@ opentelemetry-otlp = { version = "0.14.0", optional = true, features = [ "http-proto", "reqwest-client", ] } -opentelemetry = { version = "0.21.0", optional = true } -opentelemetry_sdk = { version = "0.21.1", optional = true, features = [ +opentelemetry = { version = "0.26.0", optional = true } +opentelemetry_sdk = { version = "0.26.0", optional = true, features = [ "rt-tokio", ] } -tracing-opentelemetry = { version = "0.22.0", optional = true, default-features = false } -tracing-subscriber = { version = "0.3", default-features = false, optional = true } +tracing-opentelemetry = { version = "0.26.0", optional = true, default-features = false } +tracing-subscriber = { version = "0.3.18", default-features = false, optional = true } [dev-dependencies] From 05040f508b738b7660ce067095341eed10f353c9 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Mon, 21 Oct 2024 13:03:49 -0500 Subject: [PATCH 2/4] [skip ci] yolo --- crates/cli/src/commands/mod.rs | 243 ++++++++++++++++----------------- 1 file changed, 121 insertions(+), 122 deletions(-) diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 283c954c9..2e8ff54f7 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -499,132 +499,131 @@ fn get_otel_key(env_name: &str) -> Option { } #[cfg(feature = "grit_tracing")] -// fn get_otel_setup() -> Result> { -// let grafana_key = get_otel_key("GRAFANA_OTEL_KEY"); -// let honeycomb_key = get_otel_key("HONEYCOMB_OTEL_KEY"); -// let baselime_key = get_otel_key("BASELIME_OTEL_KEY"); -// let hyperdx_key = get_otel_key("HYPERDX_OTEL_KEY"); - -// let env = get_otel_key("GRIT_DEPLOYMENT_ENV").unwrap_or_else(|| "prod".to_string()); - -// let (endpoint, headers) = match (grafana_key, honeycomb_key, baselime_key, hyperdx_key) { -// (None, None, None, None) => { -// if let Some(endpoint) = get_otel_key("OTEL_EXPORTER_OTLP_ENDPOINT") { -// eprintln!( -// "No explicit OTLP key found, using default OTLP endpoint: {}", -// endpoint -// ); -// (Some(endpoint), None) -// } else { -// #[cfg(feature = "server")] -// eprintln!("No OTLP key found, tracing will be disabled"); -// return Ok(None); -// } -// } - -// (Some(grafana_key), _, _, _) => { -// let instance_id = "665534"; -// let encoded = -// base64::encode_from_string(format!("{}:{}", instance_id, grafana_key).as_str())?; -// let endpoint = "https://otlp-gateway-prod-us-central-0.grafana.net/otlp".to_string(); -// let headers = -// HashMap::from([("Authorization".to_string(), format!("Basic {}", encoded))]); -// eprintln!("Using Grafana OTLP key for {}", env); -// (Some(endpoint), Some(headers)) -// } -// (_, Some(honeycomb_key), _, _) => { -// let endpoint = "https://api.honeycomb.io".to_string(); -// let headers = HashMap::from([("x-honeycomb-team".to_string(), honeycomb_key)]); -// eprintln!("Using Honeycomb OTLP key for {}", env); -// (Some(endpoint), Some(headers)) -// } -// (_, _, Some(baselime_key), _) => { -// let endpoint = "https://otel.baselime.io/v1/".to_string(); -// let headers = HashMap::from([ -// ("x-api-key".to_string(), baselime_key), -// ("x-baselime-dataset".to_string(), "otel".to_string()), -// ]); -// eprintln!("Using Baselime OTLP key for {}", env); -// (Some(endpoint), Some(headers)) -// } -// (_, _, _, Some(hyperdx_key)) => { -// let endpoint = "https://in-otel.hyperdx.io".to_string(); -// let headers = HashMap::from([("authorization".to_string(), hyperdx_key)]); -// eprintln!("Using HyperDX OTLP key for {}", env); -// (Some(endpoint), Some(headers)) -// } -// }; - -// let client = reqwest::Client::new(); - -// let mut resource_attrs = vec![ -// KeyValue::new("service.name", "grit_marzano".to_string()), -// KeyValue::new("deployment.environment.name", env), -// ]; - -// if let Some(execution_id) = get_otel_key("GRIT_EXECUTION_ID") { -// resource_attrs.push(KeyValue::new("grit.execution.id", execution_id)); -// } - -// let resource = Resource::new(resource_attrs); - -// let mut logger_exporter = opentelemetry_otlp::new_exporter() -// .http() -// .with_http_client(client.clone()) -// .with_timeout(std::time::Duration::from_millis(500)); -// if let Some(endpoint) = &endpoint { -// logger_exporter = logger_exporter.with_endpoint(endpoint.clone()); -// } -// if let Some(headers) = &headers { -// logger_exporter = logger_exporter.with_headers(headers.clone()); -// } - -// let mut tracer_exporter = opentelemetry_otlp::new_exporter() -// .http() -// .with_http_client(client.clone()) -// .with_timeout(std::time::Duration::from_millis(500)); -// if let Some(endpoint) = endpoint { -// tracer_exporter = tracer_exporter.with_endpoint(endpoint); -// } -// if let Some(headers) = headers { -// tracer_exporter = tracer_exporter.with_headers(headers); -// } - -// let logger = opentelemetry_otlp::new_pipeline() -// .logging() -// .with_exporter(logger_exporter) -// .with_log_config( -// opentelemetry_sdk::logs::BatchConfig::default().with_resource(resource.clone()), -// ) -// .install_batch(opentelemetry_sdk::runtime::Tokio)?; - -// let tracer = opentelemetry_otlp::new_pipeline() -// .tracing() -// .with_exporter(tracer_exporter) -// .with_trace_config(trace::config().with_resource(resource)) -// .install_batch(opentelemetry_sdk::runtime::Tokio)?; - -// let logger_provider = logger.provider().unwrap(); - -// Ok(Some((tracer, logger_provider))) -// } +fn get_otel_setup() -> Result> { + let grafana_key = get_otel_key("GRAFANA_OTEL_KEY"); + let honeycomb_key = get_otel_key("HONEYCOMB_OTEL_KEY"); + let baselime_key = get_otel_key("BASELIME_OTEL_KEY"); + let hyperdx_key = get_otel_key("HYPERDX_OTEL_KEY"); + + let env = get_otel_key("GRIT_DEPLOYMENT_ENV").unwrap_or_else(|| "prod".to_string()); + + let (endpoint, headers) = match (grafana_key, honeycomb_key, baselime_key, hyperdx_key) { + (None, None, None, None) => { + if let Some(endpoint) = get_otel_key("OTEL_EXPORTER_OTLP_ENDPOINT") { + eprintln!( + "No explicit OTLP key found, using default OTLP endpoint: {}", + endpoint + ); + (Some(endpoint), None) + } else { + #[cfg(feature = "server")] + eprintln!("No OTLP key found, tracing will be disabled"); + return Ok(None); + } + } + + (Some(grafana_key), _, _, _) => { + let instance_id = "665534"; + let encoded = + base64::encode_from_string(format!("{}:{}", instance_id, grafana_key).as_str())?; + let endpoint = "https://otlp-gateway-prod-us-central-0.grafana.net/otlp".to_string(); + let headers = + HashMap::from([("Authorization".to_string(), format!("Basic {}", encoded))]); + eprintln!("Using Grafana OTLP key for {}", env); + (Some(endpoint), Some(headers)) + } + (_, Some(honeycomb_key), _, _) => { + let endpoint = "https://api.honeycomb.io".to_string(); + let headers = HashMap::from([("x-honeycomb-team".to_string(), honeycomb_key)]); + eprintln!("Using Honeycomb OTLP key for {}", env); + (Some(endpoint), Some(headers)) + } + (_, _, Some(baselime_key), _) => { + let endpoint = "https://otel.baselime.io/v1/".to_string(); + let headers = HashMap::from([ + ("x-api-key".to_string(), baselime_key), + ("x-baselime-dataset".to_string(), "otel".to_string()), + ]); + eprintln!("Using Baselime OTLP key for {}", env); + (Some(endpoint), Some(headers)) + } + (_, _, _, Some(hyperdx_key)) => { + let endpoint = "https://in-otel.hyperdx.io".to_string(); + let headers = HashMap::from([("authorization".to_string(), hyperdx_key)]); + eprintln!("Using HyperDX OTLP key for {}", env); + (Some(endpoint), Some(headers)) + } + }; + + let client = reqwest::Client::new(); + + let mut resource_attrs = vec![ + KeyValue::new("service.name", "grit_marzano".to_string()), + KeyValue::new("deployment.environment.name", env), + ]; + + if let Some(execution_id) = get_otel_key("GRIT_EXECUTION_ID") { + resource_attrs.push(KeyValue::new("grit.execution.id", execution_id)); + } + + let resource = Resource::new(resource_attrs); + + let mut logger_exporter = opentelemetry_otlp::new_exporter() + .http() + .with_http_client(client.clone()) + .with_timeout(std::time::Duration::from_millis(500)); + if let Some(endpoint) = &endpoint { + logger_exporter = logger_exporter.with_endpoint(endpoint.clone()); + } + if let Some(headers) = &headers { + logger_exporter = logger_exporter.with_headers(headers.clone()); + } + + let mut tracer_exporter = opentelemetry_otlp::new_exporter() + .http() + .with_http_client(client.clone()) + .with_timeout(std::time::Duration::from_millis(500)); + if let Some(endpoint) = endpoint { + tracer_exporter = tracer_exporter.with_endpoint(endpoint); + } + if let Some(headers) = headers { + tracer_exporter = tracer_exporter.with_headers(headers); + } + + let logger = opentelemetry_otlp::new_pipeline() + .logging() + .with_exporter(logger_exporter) + .with_log_config( + opentelemetry_sdk::logs::BatchConfig::default().with_resource(resource.clone()), + ) + .install_batch(opentelemetry_sdk::runtime::Tokio)?; + + let tracer = opentelemetry_otlp::new_pipeline() + .tracing() + .with_exporter(tracer_exporter) + .with_trace_config(trace::config().with_resource(resource)) + .install_batch(opentelemetry_sdk::runtime::Tokio)?; + + let logger_provider = logger.provider().unwrap(); + + Ok(Some((tracer, logger_provider))) +} pub async fn run_command_with_tracing() -> Result<()> { #[cfg(feature = "grit_tracing")] { - // let otel = get_otel_setup()?; - - use opentelemetry::global; - use opentelemetry::trace::FutureExt; - use opentelemetry::trace::TraceContextExt; - use opentelemetry::trace::Tracer; - use opentelemetry_appender_tracing::layer; - use opentelemetry_sdk::logs::LoggerProvider; - use opentelemetry_sdk::trace::TracerProvider; - use opentelemetry_stdout as stdout; - use tracing::info; - use tracing_subscriber::layer::SubscriberExt; - use tracing_subscriber::Registry; + let otel = get_otel_setup()?; + + // use opentelemetry::trace::FutureExt; + // use opentelemetry::trace::TraceContextExt; + // use opentelemetry::trace::Tracer; + // use opentelemetry_appender_tracing::layer; + // use opentelemetry_sdk::logs::LoggerProvider; + // use opentelemetry_sdk::trace::TracerProvider; + // use opentelemetry_stdout as stdout; + // use tracing::info; + // use tracing_subscriber::layer::SubscriberExt; + // use tracing_subscriber::Registry; // Create a new OpenTelemetry trace pipeline that prints to stdout let tracer_provider = TracerProvider::builder() From 489205b70c69b80e507d5e54057c56516fafe51a Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Mon, 21 Oct 2024 13:04:05 -0500 Subject: [PATCH 3/4] [skip ci] yolo --- crates/cli/src/commands/mod.rs | 113 +++++++++------------------------ 1 file changed, 30 insertions(+), 83 deletions(-) diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 2e8ff54f7..fb46cbb0c 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -593,9 +593,7 @@ fn get_otel_setup() -> Result Result<()> { { let otel = get_otel_setup()?; - // use opentelemetry::trace::FutureExt; - // use opentelemetry::trace::TraceContextExt; - // use opentelemetry::trace::Tracer; - // use opentelemetry_appender_tracing::layer; - // use opentelemetry_sdk::logs::LoggerProvider; - // use opentelemetry_sdk::trace::TracerProvider; - // use opentelemetry_stdout as stdout; - // use tracing::info; - // use tracing_subscriber::layer::SubscriberExt; - // use tracing_subscriber::Registry; + if let Some((tracer, logger)) = otel { + let env_filter = EnvFilter::try_from_default_env() + .unwrap_or(EnvFilter::new("TRACE")) + // Exclude noisy tokio stuff "h2::proto::streams::prioritize + .add_directive("h2=off".parse().unwrap()) + // This is also noisy + .add_directive("axum::serve=DEBUG".parse().unwrap()) + // We don't want to trace the tracing library itself + .add_directive("hyper=off".parse().unwrap()); - // Create a new OpenTelemetry trace pipeline that prints to stdout - let tracer_provider = TracerProvider::builder() - .with_simple_exporter(stdout::SpanExporter::default()) - .build(); - global::set_tracer_provider(tracer_provider); + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + let logger_layer = crate::tracing_bridge::OpenTelemetryTracingBridge::new(&logger); - let tracing_layer = tracing_opentelemetry::layer(); + let subscriber = Registry::default() + .with(env_filter) + .with(telemetry) + .with(logger_layer); - let log_provider = LoggerProvider::builder() - .with_simple_exporter(stdout::LogExporter::default()) - .build(); + global::set_text_map_propagator(TraceContextPropagator::new()); + tracing::subscriber::set_global_default(subscriber) + .expect("setting tracing default failed"); - //let log_layer = layer::OpenTelemetryTracingBridge::new(&log_provider); - let log_layer = layer::OpenTelemetryTracingBridge::new(&log_provider); + let root_span = span!(Level::INFO, "grit_marzano.cli_command",); - let subscriber = Registry::default().with(tracing_layer).with(log_layer); - tracing::subscriber::set_global_default(subscriber) - .expect("setting tracing default failed"); + let res = async move { + event!(Level::INFO, "starting the CLI!"); - // let root_span = span!(Level::INFO, "grit_marzano.run_command"); + let res = run_command(true).await; - // tracing::subscriber::with_default(subscriber, || { - // Spans will be sent to the configured OpenTelemetry exporter - let tracer = global::tracer("dash0"); + event!(Level::INFO, "ending the CLI!"); - // let root_span = span!(Level::INFO, "grit_marzano.run_command"); - let root_span = tracer.start("grit_marzano.run_command"); - - // Perform some async work with this span as the currently active parent. - run_command(true) - .with_context(opentelemetry::Context::current_with_span(root_span)) + res + } + .instrument(root_span) .await; - log::info!("ending the CLI!"); - - // }); - - // Spans will be sent to the configured OpenTelemetry exporter - // let res = async move { - // event!(Level::INFO, "starting the CLI!"); - - // let res = run_command(true).await; - - // event!(Level::INFO, "ending the CLI!"); - - // res - // } - // .instrument(root_span) - // .await; - - return Ok(()); + opentelemetry::global::shutdown_tracer_provider(); - // if let Some((tracer, logger)) = otel { - // let env_filter = EnvFilter::try_from_default_env() - // .unwrap_or(EnvFilter::new("TRACE")) - // // Exclude noisy tokio stuff "h2::proto::streams::prioritize - // .add_directive("h2=off".parse().unwrap()) - // // This is also noisy - // .add_directive("axum::serve=DEBUG".parse().unwrap()) - // // We don't want to trace the tracing library itself - // .add_directive("hyper=off".parse().unwrap()); - - // let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - // let logger_layer = opentelemOpenTelemetryTracingBridge::new(&logger); - - // let subscriber = Registry::default() - // .with(env_filter) - // .with(telemetry) - // .with(logger_layer); - - // global::set_text_map_propagator(TraceContextPropagator::new()); - - // // tracer.in_span("app_init", res); - - // // let res = async move { res } - - // opentelemetry::global::shutdown_tracer_provider(); - - // return res; - // } + return res; + } } let subscriber = tracing::subscriber::NoSubscriber::new(); tracing::subscriber::set_global_default(subscriber).expect("setting tracing default failed"); From 5caa433e9f8d6ffdfd86b32dd3ba09175da092eb Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Mon, 21 Oct 2024 13:18:43 -0500 Subject: [PATCH 4/4] [skip ci] yolo --- Cargo.lock | 286 +++++++++++++++++++++++++++++++-- crates/cli/Cargo.toml | 6 +- crates/cli/src/commands/mod.rs | 41 +++-- 3 files changed, 300 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5169772b6..8021cf142 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,28 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "async-trait" version = "0.1.77" @@ -150,6 +172,12 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "auto_impl" version = "1.2.0" @@ -231,7 +259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", @@ -252,6 +280,33 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core 0.4.5", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 1.0.1", + "tower", + "tower-layer", + "tower-service", +] + [[package]] name = "axum-core" version = "0.3.4" @@ -269,6 +324,26 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 1.0.1", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -1504,6 +1579,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", + "indexmap 2.2.5", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1638,7 +1732,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.24", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -1661,9 +1755,11 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2 0.4.6", "http 1.1.0", "http-body 1.0.1", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec", @@ -1701,6 +1797,19 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-timeout" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper 1.4.1", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -2177,7 +2286,7 @@ dependencies = [ "marzano-util", "ntest", "opentelemetry 0.26.0", - "opentelemetry-otlp", + "opentelemetry-otlp 0.14.0", "opentelemetry_sdk 0.26.0", "predicates", "rayon", @@ -2247,7 +2356,7 @@ dependencies = [ "openssl", "opentelemetry 0.26.0", "opentelemetry-appender-tracing", - "opentelemetry-otlp", + "opentelemetry-otlp 0.26.0", "opentelemetry-stdout", "opentelemetry_sdk 0.26.0", "rayon", @@ -2260,7 +2369,7 @@ dependencies = [ "tokio", "tracing", "tracing-log", - "tracing-opentelemetry 0.26.0", + "tracing-opentelemetry 0.25.0", "tracing-subscriber", "trim-margin", "uuid", @@ -2833,6 +2942,20 @@ dependencies = [ "urlencoding", ] +[[package]] +name = "opentelemetry" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c365a63eec4f55b7efeceb724f1336f26a9cf3427b70e59e2cd2a5b947fba96" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + [[package]] name = "opentelemetry" version = "0.25.0" @@ -2886,6 +3009,19 @@ dependencies = [ "reqwest 0.11.24", ] +[[package]] +name = "opentelemetry-http" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6351496aeaa49d7c267fb480678d85d1cd30c5edb20b497c48c56f62a8c14b99" +dependencies = [ + "async-trait", + "bytes", + "http 1.1.0", + "opentelemetry 0.26.0", + "reqwest 0.12.5", +] + [[package]] name = "opentelemetry-otlp" version = "0.14.0" @@ -2896,15 +3032,35 @@ dependencies = [ "futures-core", "http 0.2.12", "opentelemetry 0.21.0", - "opentelemetry-http", - "opentelemetry-proto", + "opentelemetry-http 0.10.0", + "opentelemetry-proto 0.4.0", "opentelemetry-semantic-conventions", "opentelemetry_sdk 0.21.2", "prost 0.11.9", "reqwest 0.11.24", "thiserror", "tokio", - "tonic", + "tonic 0.9.2", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e1f9c8b032d4f635c730c0efcf731d5e2530ea13fa8bef7939ddc8420696bd" +dependencies = [ + "async-trait", + "futures-core", + "http 1.1.0", + "opentelemetry 0.26.0", + "opentelemetry-http 0.26.0", + "opentelemetry-proto 0.26.1", + "opentelemetry_sdk 0.26.0", + "prost 0.13.3", + "reqwest 0.12.5", + "thiserror", + "tokio", + "tonic 0.12.3", ] [[package]] @@ -2916,7 +3072,19 @@ dependencies = [ "opentelemetry 0.21.0", "opentelemetry_sdk 0.21.2", "prost 0.11.9", - "tonic", + "tonic 0.9.2", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d3968ce3aefdcca5c27e3c4ea4391b37547726a70893aab52d3de95d5f8b34" +dependencies = [ + "opentelemetry 0.26.0", + "opentelemetry_sdk 0.26.0", + "prost 0.13.3", + "tonic 0.12.3", ] [[package]] @@ -2962,7 +3130,23 @@ dependencies = [ "ordered-float", "percent-encoding", "rand", - "serde_json", + "thiserror", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692eac490ec80f24a17828d49b40b60f5aeaccdfe6a503f939713afd22bc28df" +dependencies = [ + "async-trait", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry 0.24.0", + "percent-encoding", + "rand", "thiserror", ] @@ -3246,6 +3430,16 @@ dependencies = [ "prost-derive 0.12.3", ] +[[package]] +name = "prost" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +dependencies = [ + "bytes", + "prost-derive 0.13.3", +] + [[package]] name = "prost-derive" version = "0.11.9" @@ -3272,6 +3466,19 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "prost-derive" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +dependencies = [ + "anyhow", + "itertools 0.11.0", + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "psm" version = "0.1.21" @@ -3476,7 +3683,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", + "h2 0.3.24", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", @@ -3515,6 +3722,7 @@ checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" dependencies = [ "base64 0.22.1", "bytes", + "futures-channel", "futures-core", "futures-util", "http 1.1.0", @@ -4172,9 +4380,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -4256,16 +4464,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" dependencies = [ "async-trait", - "axum", + "axum 0.6.20", "base64 0.21.7", "bytes", "futures-core", "futures-util", - "h2", + "h2 0.3.24", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-timeout", + "hyper-timeout 0.4.1", "percent-encoding", "pin-project", "prost 0.11.9", @@ -4277,6 +4485,36 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" +dependencies = [ + "async-stream", + "async-trait", + "axum 0.7.5", + "base64 0.22.1", + "bytes", + "h2 0.4.6", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.4.1", + "hyper-timeout 0.5.1", + "hyper-util", + "percent-encoding", + "pin-project", + "prost 0.13.3", + "socket2", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -4403,6 +4641,22 @@ dependencies = [ "web-time 0.2.4", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9784ed4da7d921bc8df6963f8c80a0e4ce34ba6ba76668acadd3edbd985ff3b" +dependencies = [ + "js-sys", + "once_cell", + "opentelemetry 0.24.0", + "opentelemetry_sdk 0.24.1", + "tracing", + "tracing-core", + "tracing-subscriber", + "web-time 1.1.0", +] + [[package]] name = "tracing-opentelemetry" version = "0.26.0" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 3591c9618..536da0716 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -62,7 +62,7 @@ axoupdater = { version = "0.7.0", default-features = false, features = [ "github_releases", ] } -opentelemetry-otlp = { version = "0.14.0", optional = true, default-features = false, features = [ +opentelemetry-otlp = { version = "0.26.0", optional = true, default-features = false, features = [ "http-proto", "reqwest-client", "logs", @@ -77,12 +77,12 @@ opentelemetry_sdk = { version = "0.26.0", optional = true, features = [ "rt-tokio", "logs", ] } -tracing-opentelemetry = { version = "0.26.0", optional = true, default-features = false } +tracing-opentelemetry = { version = "0.25.0", optional = true, default-features = false } tracing = { version = "0.1.40", default-features = false, features = [] } notify = "6.1.1" notify-debouncer-mini = "0.4.1" -tracing-subscriber = { version = "0.3", default-features = false, optional = true } +tracing-subscriber = { version = "0.3.18", default-features = false, optional = true } tracing-log = { version = "0.2.0", optional = true } fs-err = { version = "2.11.0" } diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index fb46cbb0c..b327602ba 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -38,6 +38,7 @@ use crate::error::GoodError; #[cfg(feature = "grit_tracing")] use marzano_util::base64; +use opentelemetry::global::ObjectSafeTracerProvider; #[cfg(feature = "grit_tracing")] use opentelemetry::{global, KeyValue}; #[cfg(feature = "grit_tracing")] @@ -499,7 +500,12 @@ fn get_otel_key(env_name: &str) -> Option { } #[cfg(feature = "grit_tracing")] -fn get_otel_setup() -> Result> { +fn get_otel_setup() -> Result< + Option<( + opentelemetry_sdk::trace::TracerProvider, + opentelemetry_sdk::logs::LoggerProvider, + )>, +> { let grafana_key = get_otel_key("GRAFANA_OTEL_KEY"); let honeycomb_key = get_otel_key("HONEYCOMB_OTEL_KEY"); let baselime_key = get_otel_key("BASELIME_OTEL_KEY"); @@ -593,23 +599,24 @@ fn get_otel_setup() -> Result Result<()> { #[cfg(feature = "grit_tracing")] { + use opentelemetry::trace::TracerProvider; let otel = get_otel_setup()?; if let Some((tracer, logger)) = otel { @@ -622,17 +629,23 @@ pub async fn run_command_with_tracing() -> Result<()> { // We don't want to trace the tracing library itself .add_directive("hyper=off".parse().unwrap()); + let provider = opentelemetry_sdk::trace::TracerProvider::builder() + .with_simple_exporter(opentelemetry_stdout::SpanExporter::default()) + .build(); + let tracer = provider.tracer("readme_example"); + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - let logger_layer = crate::tracing_bridge::OpenTelemetryTracingBridge::new(&logger); - let subscriber = Registry::default() - .with(env_filter) - .with(telemetry) - .with(logger_layer); + // let logger_layer = crate::tracing_bridge::OpenTelemetryTracingBridge::new(&logger); + + // let subscriber = Registry::default() + // .with(env_filter) + // .with(telemetry) + // .with(logger_layer); - global::set_text_map_propagator(TraceContextPropagator::new()); - tracing::subscriber::set_global_default(subscriber) - .expect("setting tracing default failed"); + // global::set_text_map_propagator(TraceContextPropagator::new()); + // tracing::subscriber::set_global_default(subscriber) + // .expect("setting tracing default failed"); let root_span = span!(Level::INFO, "grit_marzano.cli_command",);