Skip to content

Commit

Permalink
Merge pull request #978 from jvanz/otel-update
Browse files Browse the repository at this point in the history
chore(deps): updates OpenTelemetry dependencies
  • Loading branch information
flavio authored Nov 15, 2024
2 parents 6c9af94 + b00d961 commit 02dd53f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
24 changes: 13 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ k8s-openapi = { version = "0.23.0", default-features = false, features = [
lazy_static = "1.4.0"
mime = "0.3"
num_cpus = "1.16.0"
opentelemetry-otlp = { version = "0.26.0", features = ["metrics", "tonic"] }
opentelemetry = { version = "0.26.0", default-features = false, features = [
opentelemetry-otlp = { version = "0.27.0", features = ["metrics", "tonic"] }
opentelemetry = { version = "0.27.0", default-features = false, features = [
"metrics",
"trace",
] }
opentelemetry_sdk = { version = "0.26.0", features = ["rt-tokio"] }
opentelemetry_sdk = { version = "0.27.0", features = ["rt-tokio"] }
pprof = { version = "0.14", features = ["prost-codec"] }
policy-evaluator = { git = "https://github.com/kubewarden/policy-evaluator", tag = "v0.19.3" }
rustls = { version = "0.23", default-features = false, features = [
Expand All @@ -46,7 +46,7 @@ sha2 = "0.10"
thiserror = "2.0"
tokio = { version = "^1.41.0", features = ["full"] }
tracing = "0.1"
tracing-opentelemetry = "0.27.0"
tracing-opentelemetry = "0.28.0"
tracing-subscriber = { version = "0.3", features = ["ansi", "fmt", "json"] }
semver = { version = "1.0.22", features = ["serde"] }
mockall_double = "0.3"
Expand Down
23 changes: 12 additions & 11 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ pub use policy_evaluations_latency::record_policy_latency;
const METER_NAME: &str = "kubewarden";

pub fn setup_metrics() -> Result<()> {
let meter_provider = opentelemetry_otlp::new_pipeline()
.metrics(runtime::Tokio)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(ExportConfig::default()),
)
.build()?;

global::set_meter_provider(meter_provider.clone());

let meter_reader = opentelemetry_sdk::metrics::PeriodicReader::builder(
opentelemetry_otlp::MetricExporter::builder()
.with_tonic()
.with_export_config(ExportConfig::default())
.build()?,
runtime::Tokio,
)
.build();
let meter_provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()
.with_reader(meter_reader)
.build();
global::set_meter_provider(meter_provider);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/metrics/policy_evaluations_latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lazy_static! {
static ref POLICY_EVALUATION_LATENCY: Histogram<u64> =
opentelemetry::global::meter(super::METER_NAME)
.u64_histogram("kubewarden_policy_evaluation_latency_milliseconds")
.init();
.build();
}

pub fn record_policy_latency(latency: Duration, policy_evaluation: impl PolicyEvaluationMetric) {
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/policy_evaluations_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ lazy_static! {
static ref POLICY_EVALUATIONS_TOTAL: Counter<u64> =
opentelemetry::global::meter(super::METER_NAME)
.u64_counter("kubewarden_policy_evaluations_total")
.init();
.build();
}

pub fn add_policy_evaluation(policy_evaluation: impl PolicyEvaluationMetric) {
Expand Down
26 changes: 16 additions & 10 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ pub fn setup_tracing(log_level: &str, log_fmt: &str, log_no_color: bool) -> Resu
// OpenTelemetry collector using the OTLP format.
// The collector must run on localhost (eg: use a sidecar inside of k8s)
// using GRPC
let tracer_provider = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(opentelemetry_otlp::new_exporter().tonic())
.with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource(
opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
config::SERVICE_NAME,
)]),
))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.build()?;

let tracer_config = opentelemetry_sdk::trace::Config::default().with_resource(
opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
config::SERVICE_NAME,
)]),
);

let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
.with_config(tracer_config)
.with_batch_exporter(otlp_exporter, opentelemetry_sdk::runtime::Tokio)
.build();

let tracer = tracer_provider.tracer(config::SERVICE_NAME);

// Create a tracing layer with the configured tracer
Expand Down

0 comments on commit 02dd53f

Please sign in to comment.