11use spin_factors:: anyhow;
2+ use spin_telemetry:: OpenTelemetrySpanExt as _;
23use spin_world:: { v1, v2:: variables, wasi:: config as wasi_config} ;
3- use tracing:: { instrument, Level } ;
4+ use tracing:: instrument;
45
56use crate :: InstanceState ;
67
78impl 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
2223impl 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
3840impl 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}
0 commit comments