Skip to content
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

feat: migrate from legacy jaeger to native otlp #750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,587 changes: 1,457 additions & 1,130 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions binaries/daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ telemetry = ["dep:tracing-opentelemetry"]
eyre = "0.6.8"
tokio = { version = "1.20.1", features = ["full"] }
tokio-stream = { version = "0.1.11", features = ["net"] }
tracing = "0.1.36"
tracing-opentelemetry = { version = "0.18.0", optional = true }
tracing = "0.1.41"
tracing-opentelemetry = { version = "0.28.0", optional = true }
futures-concurrency = "7.1.0"
serde_json = "1.0.86"
dora-core = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions binaries/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ tokio = { version = "1.24.2", features = ["full"] }
tokio-stream = "0.1.8"
# pyo3-abi3 flag allow simpler linking. See: https://pyo3.rs/v0.13.2/building_and_distribution.html
pyo3 = { workspace = true, features = ["eyre", "abi3-py37"], optional = true }
tracing = "0.1.36"
tracing = "0.1.41"
dora-download = { workspace = true }
flume = "0.10.14"
tracing-opentelemetry = { version = "0.18.0", optional = true }
tracing-opentelemetry = { version = "0.28.0", optional = true }
pythonize = { workspace = true, optional = true }
arrow = { workspace = true, features = ["ffi"] }
aligned-vec = "0.5.0"
Expand Down
9 changes: 5 additions & 4 deletions libraries/extensions/telemetry/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
opentelemetry = { version = "0.22.0", features = ["metrics"] }
opentelemetry-otlp = { version = "0.15.0", features = ["tonic", "metrics"] }
opentelemetry_sdk = { version = "0.22.0", features = ["rt-tokio", "metrics"] }
opentelemetry = { version = "0.27.1", features = ["metrics"] }
opentelemetry-otlp = { version = "0.27.0", features = ["tonic", "metrics"] }
opentelemetry_sdk = { version = "0.27.1", features = ["rt-tokio", "metrics"] }
eyre = "0.6.12"
opentelemetry-system-metrics = { version = "0.1.8" }
# TODO: change to crate new version once https://github.com/haixuanTao/opentelemetry-system-metrics/pull/7 is merged
opentelemetry-system-metrics = { git = "https://github.com/wiseaidev/opentelemetry-system-metrics", branch = "opentelemetry" }
44 changes: 26 additions & 18 deletions libraries/extensions/telemetry/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@
use std::time::Duration;

use eyre::{Context, Result};
use opentelemetry::metrics::{self, MeterProvider as _};
use opentelemetry_otlp::{ExportConfig, WithExportConfig};
use opentelemetry_sdk::{metrics::SdkMeterProvider, runtime};
use opentelemetry::metrics::MeterProvider;
use opentelemetry_otlp::Protocol;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::metrics::{MetricResult, SdkMeterProvider};
use opentelemetry_system_metrics::init_process_observer;
/// Init opentelemetry meter
///
/// Use the default Opentelemetry exporter with default config
/// TODO: Make Opentelemetry configurable
///
pub fn init_metrics() -> metrics::Result<SdkMeterProvider> {
pub fn init_metrics() -> MetricResult<SdkMeterProvider> {
let endpoint = std::env::var("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT")
.unwrap_or_else(|_| "http://localhost:4317".to_string());
let export_config = ExportConfig {
endpoint,
..ExportConfig::default()
};
.unwrap_or_else(|_| "http://localhost:4318/v1/metrics".to_string());

opentelemetry_otlp::new_pipeline()
.metrics(runtime::Tokio)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(export_config),
)
.with_period(Duration::from_secs(10))
let exporter = opentelemetry_otlp::MetricExporter::builder()
.with_tonic()
.with_endpoint(endpoint)
.with_protocol(Protocol::Grpc)
.with_timeout(Duration::from_secs(10))
.build()
.unwrap();

let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(
exporter,
opentelemetry_sdk::runtime::Tokio,
)
.with_interval(std::time::Duration::from_secs(10))
.with_timeout(Duration::from_secs(10))
.build();

Ok(opentelemetry_sdk::metrics::SdkMeterProvider::builder()
.with_reader(reader)
.build())
}

pub fn init_meter_provider(meter_id: String) -> Result<SdkMeterProvider> {
let meter_id: &'static str = Box::leak(meter_id.into_boxed_str());
let meter_provider = init_metrics().context("Could not create opentelemetry meter")?;
let meter = meter_provider.meter(meter_id);
init_process_observer(meter).context("could not initiate system metrics observer")?;
init_process_observer(meter.clone()).context("could not initiate system metrics observer")?;
Ok(meter_provider)
}
10 changes: 6 additions & 4 deletions libraries/extensions/telemetry/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ repository.workspace = true

[dependencies]
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tracing-opentelemetry = { version = "0.18.0" }
tracing-opentelemetry = { version = "0.28.0" }
eyre = "0.6.8"
tracing = "0.1.36"
opentelemetry = { version = "0.18.0", features = ["rt-tokio", "metrics"] }
opentelemetry-jaeger = { version = "0.17.0", features = ["rt-tokio"] }
tracing = "0.1.41"
opentelemetry = { version = "0.27.1" }
opentelemetry-otlp = { version = "0.27.0", default-features = false, features = ["http-proto", "http-json", "logs", "internal-logs"] }
opentelemetry_sdk = { version = "0.27.1", features = ["rt-tokio", "logs"]}
opentelemetry-appender-tracing = { version = "0.27.0"}
9 changes: 4 additions & 5 deletions libraries/extensions/telemetry/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing_subscriber::{
};

use eyre::ContextCompat;
use tracing_subscriber::Registry;
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
pub mod telemetry;

pub fn set_up_tracing(name: &str) -> eyre::Result<()> {
Expand Down Expand Up @@ -62,13 +62,12 @@ pub fn set_up_tracing_opts(
let endpoint = endpoint
.to_str()
.wrap_err("Could not parse env variable: DORA_JAEGER_TRACING")?;
let tracer = crate::telemetry::init_jaeger_tracing(name, endpoint)
let tracer = crate::telemetry::init_jaeger_tracing(name.to_string(), endpoint)
.wrap_err("Could not instantiate tracing")?;
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
layers.push(telemetry.boxed());
layers.push(Box::new(OpenTelemetryTracingBridge::new(&tracer)));
}

let registry = Registry::default().with(layers);
let registry = tracing_subscriber::registry().with(layers);
tracing::subscriber::set_global_default(registry).context(format!(
"failed to set tracing global subscriber for {name}"
))
Expand Down
27 changes: 20 additions & 7 deletions libraries/extensions/telemetry/tracing/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use opentelemetry::propagation::Extractor;
use opentelemetry::sdk::{propagation::TraceContextPropagator, trace as sdktrace};
use opentelemetry::trace::TraceError;
use opentelemetry::{global, Context};
use opentelemetry::{Key, KeyValue, Value};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_otlp::{LogExporter, Protocol};
use opentelemetry_sdk::{logs::LoggerProvider, Resource};
use std::collections::HashMap;

struct MetadataMap<'a>(HashMap<&'a str, &'a str>);
Expand Down Expand Up @@ -32,12 +34,23 @@ impl<'a> Extractor for MetadataMap<'a> {
///
/// TODO: Make Jaeger configurable
///
pub fn init_jaeger_tracing(name: &str, endpoint: &str) -> Result<sdktrace::Tracer, TraceError> {
global::set_text_map_propagator(TraceContextPropagator::new());
opentelemetry_jaeger::new_agent_pipeline()
pub fn init_jaeger_tracing(
name: String,
endpoint: &str,
) -> Result<LoggerProvider, opentelemetry_sdk::logs::LogError> {
let exporter = LogExporter::builder()
.with_http()
.with_endpoint(endpoint)
.with_service_name(name)
.install_simple()
.with_protocol(Protocol::HttpBinary)
.build()?;

Ok(LoggerProvider::builder()
.with_simple_exporter(exporter)
.with_resource(Resource::new([KeyValue::new(
Key::new("name"),
Value::String(name.into()),
)]))
.build())
}

pub fn serialize_context(context: &Context) -> String {
Expand Down
Loading