Skip to content

Commit 8dec601

Browse files
committed
Only set span as errored in variables when it might not be bad user input
Signed-off-by: Ryan Levick <[email protected]>
1 parent bf339fc commit 8dec601

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/factor-variables/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = { workspace = true }
77
[dependencies]
88
spin-expressions = { path = "../expressions" }
99
spin-factors = { path = "../factors" }
10+
spin-telemetry = { path = "../telemetry" }
1011
spin-world = { path = "../world" }
1112
tracing = { workspace = true }
1213

crates/factor-variables/src/host.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use spin_factors::anyhow;
2+
use spin_telemetry::OpenTelemetrySpanExt as _;
23
use spin_world::{v1, v2::variables, wasi::config as wasi_config};
3-
use tracing::{instrument, Level};
4+
use tracing::instrument;
45

56
use crate::InstanceState;
67

78
impl variables::Host for InstanceState {
8-
#[instrument(name = "spin_variables.get", skip(self), err(level = Level::INFO), fields(otel.kind = "client"))]
9+
#[instrument(name = "spin_variables.get", skip(self), fields(otel.kind = "client"))]
910
async fn get(&mut self, key: String) -> Result<String, variables::Error> {
1011
let key = spin_expressions::Key::new(&key).map_err(expressions_to_variables_err)?;
1112
self.expression_resolver
@@ -20,6 +21,7 @@ impl variables::Host for InstanceState {
2021
}
2122

2223
impl v1::config::Host for InstanceState {
24+
#[instrument(name = "spin_config.get", skip(self), fields(otel.kind = "client"))]
2325
async fn get_config(&mut self, key: String) -> Result<String, v1::config::Error> {
2426
<Self as variables::Host>::get(self, key)
2527
.await
@@ -36,6 +38,7 @@ impl v1::config::Host for InstanceState {
3638
}
3739

3840
impl wasi_config::store::Host for InstanceState {
41+
#[instrument(name = "wasi_config.get", skip(self), fields(otel.kind = "client"))]
3942
async fn get(&mut self, key: String) -> Result<Option<String>, wasi_config::store::Error> {
4043
match <Self as variables::Host>::get(self, key).await {
4144
Ok(value) => Ok(Some(value)),
@@ -46,6 +49,7 @@ impl wasi_config::store::Host for InstanceState {
4649
}
4750
}
4851

52+
#[instrument(name = "wasi_config.get_all", skip(self), fields(otel.kind = "client"))]
4953
async fn get_all(&mut self) -> Result<Vec<(String, String)>, wasi_config::store::Error> {
5054
let all = self
5155
.expression_resolver
@@ -74,7 +78,14 @@ fn expressions_to_variables_err(err: spin_expressions::Error) -> variables::Erro
7478
match err {
7579
Error::InvalidName(msg) => variables::Error::InvalidName(msg),
7680
Error::Undefined(msg) => variables::Error::Undefined(msg),
77-
Error::Provider(err) => variables::Error::Provider(err.to_string()),
78-
other => variables::Error::Other(format!("{other}")),
81+
other @ Error::InvalidTemplate(_) => variables::Error::Other(format!("{other}")),
82+
Error::Provider(err) => {
83+
// This error may not be caused by bad user input, so set the span status to error.
84+
let current_span = tracing::Span::current();
85+
current_span.set_status(spin_telemetry::opentelemetry::trace::Status::error(
86+
err.to_string(),
87+
));
88+
variables::Error::Provider(err.to_string())
89+
}
7990
}
8091
}

crates/telemetry/src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub(crate) fn otel_sdk_disabled() -> bool {
7777
}
7878

7979
/// The protocol to use for OTLP exporter.
80+
#[derive(Debug)]
8081
pub(crate) enum OtlpProtocol {
8182
Grpc,
8283
HttpProtobuf,

crates/telemetry/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub mod metrics;
1515
mod propagation;
1616
mod traces;
1717

18+
pub use opentelemetry;
19+
pub use tracing_opentelemetry::OpenTelemetrySpanExt;
20+
1821
#[cfg(feature = "testing")]
1922
pub mod testing;
2023

hack/o11y-stack/docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21
services:
32
otel-collector:
43
image: otel/opentelemetry-collector-contrib:0.98.0

0 commit comments

Comments
 (0)