1
1
use spin_factors:: anyhow;
2
+ use spin_telemetry:: OpenTelemetrySpanExt as _;
2
3
use spin_world:: { v1, v2:: variables, wasi:: config as wasi_config} ;
3
- use tracing:: { instrument, Level } ;
4
+ use tracing:: instrument;
4
5
5
6
use crate :: InstanceState ;
6
7
7
8
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" ) ) ]
9
10
async fn get ( & mut self , key : String ) -> Result < String , variables:: Error > {
10
11
let key = spin_expressions:: Key :: new ( & key) . map_err ( expressions_to_variables_err) ?;
11
12
self . expression_resolver
@@ -20,6 +21,7 @@ impl variables::Host for InstanceState {
20
21
}
21
22
22
23
impl v1:: config:: Host for InstanceState {
24
+ #[ instrument( name = "spin_config.get" , skip( self ) , fields( otel. kind = "client" ) ) ]
23
25
async fn get_config ( & mut self , key : String ) -> Result < String , v1:: config:: Error > {
24
26
<Self as variables:: Host >:: get ( self , key)
25
27
. await
@@ -36,6 +38,7 @@ impl v1::config::Host for InstanceState {
36
38
}
37
39
38
40
impl wasi_config:: store:: Host for InstanceState {
41
+ #[ instrument( name = "wasi_config.get" , skip( self ) , fields( otel. kind = "client" ) ) ]
39
42
async fn get ( & mut self , key : String ) -> Result < Option < String > , wasi_config:: store:: Error > {
40
43
match <Self as variables:: Host >:: get ( self , key) . await {
41
44
Ok ( value) => Ok ( Some ( value) ) ,
@@ -46,6 +49,7 @@ impl wasi_config::store::Host for InstanceState {
46
49
}
47
50
}
48
51
52
+ #[ instrument( name = "wasi_config.get_all" , skip( self ) , fields( otel. kind = "client" ) ) ]
49
53
async fn get_all ( & mut self ) -> Result < Vec < ( String , String ) > , wasi_config:: store:: Error > {
50
54
let all = self
51
55
. expression_resolver
@@ -74,7 +78,14 @@ fn expressions_to_variables_err(err: spin_expressions::Error) -> variables::Erro
74
78
match err {
75
79
Error :: InvalidName ( msg) => variables:: Error :: InvalidName ( msg) ,
76
80
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
+ }
79
90
}
80
91
}
0 commit comments