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

chore(deps): updates OpenTelemetry dependencies #978

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
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 @@
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()?,

Check warning on line 18 in src/metrics.rs

View check run for this annotation

Codecov / codecov/patch

src/metrics.rs#L15-L18

Added lines #L15 - L18 were not covered by tests
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 @@
// 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()

Check warning on line 42 in src/tracing.rs

View check run for this annotation

Codecov / codecov/patch

src/tracing.rs#L42

Added line #L42 was not covered by tests
.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,

Check warning on line 49 in src/tracing.rs

View check run for this annotation

Codecov / codecov/patch

src/tracing.rs#L46-L49

Added lines #L46 - L49 were not covered by tests
)]),
);

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

Check warning on line 55 in src/tracing.rs

View check run for this annotation

Codecov / codecov/patch

src/tracing.rs#L53-L55

Added lines #L53 - L55 were not covered by tests
.build();

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

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