From 3c72e44fc4efc4a6c181169b0b048d1b189a820d Mon Sep 17 00:00:00 2001 From: David Stevens Date: Thu, 27 Jun 2024 10:38:18 +0200 Subject: [PATCH] fix: Report span status on probe error --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/probe/probe_logic.rs | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba40990..caf255d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1392,7 +1392,7 @@ dependencies = [ [[package]] name = "prodzilla" -version = "0.0.3-rc.2" +version = "0.0.3-rc.3" dependencies = [ "axum 0.7.5", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 849b583..979e428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "prodzilla" -version = "0.0.3-rc.2" +version = "0.0.3-rc.3" edition = "2021" [dependencies] diff --git a/src/probe/probe_logic.rs b/src/probe/probe_logic.rs index 5529453..7b56e0d 100644 --- a/src/probe/probe_logic.rs +++ b/src/probe/probe_logic.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use chrono::Utc; use opentelemetry::global; +use opentelemetry::global::ObjectSafeSpan; use opentelemetry::trace; use opentelemetry::trace::FutureExt; use opentelemetry::trace::Status; @@ -74,9 +75,10 @@ impl Monitorable for Story { let url = substitute_variables(&step.url, &story_variables); let input_parameters = substitute_input_parameters(&step.with, &story_variables); - let call_endpoint_result = call_endpoint(&step.http_method, &url, &input_parameters, step.sensitive) - .with_context(step_cx.clone()) - .await; + let call_endpoint_result = + call_endpoint(&step.http_method, &url, &input_parameters, step.sensitive) + .with_context(step_cx.clone()) + .await; match call_endpoint_result { Ok(endpoint_result) => { @@ -215,9 +217,11 @@ impl Monitorable for Probe { let root_span = global::tracer("probe_logic").start(self.name.clone()); - let call_endpoint_result = call_endpoint(&self.http_method, &self.url, &self.with, self.sensitive) - .with_context(Context::current_with_span(root_span)) - .await; + let root_cx = Context::default().with_span(root_span); + let call_endpoint_result = + call_endpoint(&self.http_method, &self.url, &self.with, self.sensitive) + .with_context(root_cx.clone()) + .await; let probe_result = match call_endpoint_result { Ok(endpoint_result) => { @@ -229,6 +233,10 @@ impl Monitorable for Probe { &self.expectations, ); + if let Err(err) = expectations_result.as_ref() { + root_cx.span().record_error(&err); + } + ProbeResult { probe_name: self.name.clone(), timestamp_started: endpoint_result.timestamp_request_started, @@ -240,6 +248,7 @@ impl Monitorable for Probe { } Err(e) => { error!("Error calling endpoint: {}", e); + root_cx.span().record_error(&*e); ProbeResult { success: false, probe_name: self.name.clone(), @@ -253,8 +262,12 @@ impl Monitorable for Probe { if probe_result.success { app_state.metrics.errors.add(0, &probe_attributes); + root_cx.span().set_status(Status::Ok); } else { app_state.metrics.errors.add(1, &probe_attributes); + root_cx.span().set_status(Status::Error { + description: "Expectation failed".into(), + }); } let timestamp = probe_result.timestamp_started;