Use correct version of opentelemetry
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Valentin Brandl 2021-03-29 16:29:41 +02:00
parent 6ac399a41b
commit cbdda8a561
2 changed files with 17 additions and 10 deletions

View File

@ -1,16 +1,18 @@
use hoc::{config::Settings, telemetry};
use std::net::TcpListener;
fn init() {
fn init() -> opentelemetry_jaeger::Uninstall {
dotenv::dotenv().ok();
openssl_probe::init_ssl_cert_env_vars();
telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info"))
let (subscriber, uninstall) = telemetry::get_subscriber("hoc", "info");
telemetry::init_subscriber(subscriber);
uninstall
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
init();
let _uninstall = init();
// TODO: error handling
let settings = Settings::load().expect("Cannot load config");

View File

@ -1,27 +1,32 @@
use opentelemetry::global;
use opentelemetry_jaeger::Uninstall;
use tracing::{subscriber::set_global_default, Subscriber};
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_log::LogTracer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send + Sync {
// TODO: don't pass `Uninstall` around...
pub fn get_subscriber(name: &str, env_filter: &str) -> (impl Subscriber + Send + Sync, Uninstall) {
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout);
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let (tracer, _) = opentelemetry_jaeger::new_pipeline()
let (tracer, uninstall) = opentelemetry_jaeger::new_pipeline()
.with_service_name(name)
.install()
.expect("cannot install jaeger pipeline");
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
Registry::default()
.with(telemetry)
.with(env_filter)
.with(JsonStorageLayer)
.with(formatting_layer)
(
Registry::default()
.with(telemetry)
.with(env_filter)
.with(JsonStorageLayer)
.with(formatting_layer),
uninstall,
)
}
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {