-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add otel support for query and compaction service (#2122)
## Description of changes Export traces and spans in open telemetry format so that it can be consumed by backends like Jaeger and Honeycomb. For Jaeger verified that it works locally. Will test honeycomb once it is merged ## Test plan All existing tests pass. Verified locally via tilt up and tilt down that traces are exported to Jaeger ## Documentation Changes NA ---------
- Loading branch information
1 parent
3eb26d5
commit b34f90c
Showing
8 changed files
with
329 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod opentelemetry_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use opentelemetry::global; | ||
use opentelemetry::sdk::propagation::TraceContextPropagator; | ||
use opentelemetry::sdk::trace; | ||
use opentelemetry_otlp::WithExportConfig; | ||
use tracing_bunyan_formatter::BunyanFormattingLayer; | ||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer}; | ||
|
||
pub(crate) fn init_otel_tracing(service_name: &String, otel_endpoint: &String) { | ||
println!( | ||
"Registering jaeger subscriber for {} at endpoint {}", | ||
service_name, otel_endpoint | ||
); | ||
let resource = opentelemetry::sdk::Resource::new(vec![opentelemetry::KeyValue::new( | ||
"service.name", | ||
service_name.clone(), | ||
)]); | ||
// Prepare trace config. | ||
let trace_config = trace::config() | ||
.with_sampler(opentelemetry::sdk::trace::Sampler::AlwaysOn) | ||
.with_resource(resource); | ||
// Prepare exporter. | ||
let exporter = opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint(otel_endpoint); | ||
let otlp_tracer = opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_exporter(exporter) | ||
.with_trace_config(trace_config) | ||
.install_batch(opentelemetry::runtime::Tokio) | ||
.expect("Error - Failed to create tracer."); | ||
// Layer for adding our configured tracer. | ||
// Export everything at this layer. The backend i.e. honeycomb or jaeger will filter at its end. | ||
let exporter_layer = tracing_opentelemetry::layer() | ||
.with_tracer(otlp_tracer) | ||
.with_filter(tracing_subscriber::filter::LevelFilter::TRACE); | ||
// Layer for printing spans to stdout. Only print INFO logs by default. | ||
let stdout_layer = | ||
BunyanFormattingLayer::new(service_name.clone().to_string(), std::io::stdout) | ||
.with_filter(tracing_subscriber::filter::LevelFilter::INFO); | ||
// global filter layer. Don't filter anything at global layer. | ||
let global_layer = EnvFilter::new("TRACE"); | ||
// Create subscriber. | ||
let subscriber = tracing_subscriber::registry() | ||
.with(global_layer) | ||
.with(stdout_layer) | ||
.with(exporter_layer); | ||
global::set_text_map_propagator(TraceContextPropagator::new()); | ||
tracing::subscriber::set_global_default(subscriber) | ||
.expect("Set global default subscriber failed"); | ||
println!("Set global subscriber for {}", service_name); | ||
} |