@@ -36,20 +36,23 @@ pub struct LocalBoundaryExec {
3636 provider_credentials : ProviderCredentialState ,
3737 user_environment : HashMap < String , String > ,
3838 runtime : Arc < crate :: boundary_io:: BoundaryRuntimeState > ,
39+ otlp_relay_active : bool ,
3940 #[ cfg( target_os = "linux" ) ]
4041 launcher : crate :: linux:: workload_launcher:: WorkloadLauncher ,
4142}
4243
4344impl LocalBoundaryExec {
4445 /// Construct the executor owned by an active sandbox boundary.
4546 #[ must_use]
47+ #[ allow( clippy:: too_many_arguments) ]
4648 pub fn new (
4749 policy : SandboxPolicy ,
4850 base_workdir : Option < String > ,
4951 ca_file_paths : Option < Arc < ( std:: path:: PathBuf , std:: path:: PathBuf ) > > ,
5052 provider_credentials : ProviderCredentialState ,
5153 user_environment : HashMap < String , String > ,
5254 runtime : Arc < crate :: boundary_io:: BoundaryRuntimeState > ,
55+ otlp_relay_active : bool ,
5356 #[ cfg( target_os = "linux" ) ] launcher : crate :: linux:: workload_launcher:: WorkloadLauncher ,
5457 ) -> Self {
5558 Self {
@@ -59,6 +62,7 @@ impl LocalBoundaryExec {
5962 provider_credentials,
6063 user_environment,
6164 runtime,
65+ otlp_relay_active,
6266 #[ cfg( target_os = "linux" ) ]
6367 launcher,
6468 }
@@ -182,18 +186,17 @@ impl LocalBoundaryExec {
182186 }
183187 }
184188 crate :: process:: strip_proxy_env_std ( & mut command) ;
185- // Point OTel SDKs at the supervisor's trace relay, after the creation
189+ // Point OTel SDKs at the supervisor's trace relay after the creation
186190 // request's environment and the provider variables, matching the main
187- // process, and only when the creation request named no endpoint of
188- // its own. A per-exec `spec.env` value applied below still wins for
189- // that exec only.
190- if let Some ( relay_env) =
191- crate :: child_env:: otlp_relay_env_vars_unless_configured ( & self . user_environment )
192- {
193- for ( key, value) in relay_env {
194- command. env ( key, value) ;
195- }
196- }
191+ // process. An endpoint in the creation request, the image, or this
192+ // exec's `spec.env` suppresses it, and any other `spec.env` value
193+ // applied below still wins for this exec only.
194+ crate :: child_env:: apply_otlp_relay_env (
195+ & mut command,
196+ self . otlp_relay_active ,
197+ & self . user_environment ,
198+ & spec. env ,
199+ ) ;
197200 for ( key, value) in & spec. env {
198201 if !key. starts_with ( crate :: process:: RESERVED_ENV_PREFIX ) {
199202 command. env ( key, value) ;
@@ -693,6 +696,10 @@ mod tests {
693696 use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
694697
695698 fn executor ( ) -> LocalBoundaryExec {
699+ executor_with_relay ( true )
700+ }
701+
702+ fn executor_with_relay ( otlp_relay_active : bool ) -> LocalBoundaryExec {
696703 let ( launcher, listener) =
697704 crate :: linux:: workload_launcher:: start ( ) . expect ( "start test workload launcher" ) ;
698705 std:: thread:: spawn ( move || {
@@ -728,6 +735,7 @@ mod tests {
728735 ) ,
729736 HashMap :: new ( ) ,
730737 crate :: boundary_io:: BoundaryRuntimeState :: new ( ) ,
738+ otlp_relay_active,
731739 launcher,
732740 )
733741 }
@@ -822,12 +830,22 @@ mod tests {
822830 Some ( "http/protobuf" )
823831 ) ;
824832
833+ assert_eq ! (
834+ env_of(
835+ & command,
836+ openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
837+ ) ,
838+ None ,
839+ "only the generic default is injected"
840+ ) ;
841+
825842 // A per-exec environment is a developer's explicit instruction and
826- // is applied last (contracts/sandbox-environment.md).
843+ // is applied last (contracts/sandbox-environment.md). An endpoint in
844+ // it suppresses the whole relay default, protocol included.
827845 let command = executor
828846 . command ( & spec ( vec ! [ (
829847 openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_ENDPOINT . to_string( ) ,
830- "http://127.0.0.1:4318 " . to_string( ) ,
848+ "http://127.0.0.1:4317 " . to_string( ) ,
831849 ) ] ) )
832850 . expect ( "resolve exec" ) ;
833851 assert_eq ! (
@@ -836,8 +854,40 @@ mod tests {
836854 openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_ENDPOINT
837855 )
838856 . as_deref( ) ,
839- Some ( "http://127.0.0.1:4318 " )
857+ Some ( "http://127.0.0.1:4317 " )
840858 ) ;
859+ assert_eq ! (
860+ env_of(
861+ & command,
862+ openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_PROTOCOL
863+ ) ,
864+ None
865+ ) ;
866+ }
867+
868+ #[ test]
869+ fn exec_children_get_no_relay_endpoint_while_the_relay_is_inactive ( ) {
870+ let command = executor_with_relay ( false )
871+ . command ( & ExecSpec {
872+ program : "/bin/true" . to_string ( ) ,
873+ args : Vec :: new ( ) ,
874+ shell : None ,
875+ runtime_helper : None ,
876+ env : Vec :: new ( ) ,
877+ workdir : None ,
878+ pty : false ,
879+ } )
880+ . expect ( "resolve exec" ) ;
881+ for key in [
882+ openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_ENDPOINT ,
883+ openshell_core:: sandbox_env:: OTEL_EXPORTER_OTLP_PROTOCOL ,
884+ ] {
885+ assert_eq ! (
886+ env_of( & command, key) ,
887+ None ,
888+ "{key} injected without a relay"
889+ ) ;
890+ }
841891 }
842892
843893 #[ tokio:: test]
0 commit comments