@@ -480,6 +480,8 @@ impl VerifiedControlPolicy {
480480pub enum KubernetesDriverError {
481481 #[error("sandbox already exists")]
482482 AlreadyExists,
483+ #[error("prepared bootstrap no longer matches observed runtime coordinates")]
484+ StalePreparation,
483485 #[error("sandbox not found")]
484486 NotFound,
485487 #[error("{0}")]
@@ -587,6 +589,7 @@ impl From<KubernetesDriverError> for openshell_core::ComputeDriverError {
587589 match err {
588590 KubernetesDriverError::AlreadyExists => Self::AlreadyExists,
589591 KubernetesDriverError::NotFound => Self::NotFound,
592+ KubernetesDriverError::StalePreparation => Self::Precondition(err.to_string()),
590593 KubernetesDriverError::InvalidArgument(m) => Self::InvalidArgument(m),
591594 KubernetesDriverError::Precondition(m) => Self::Precondition(m),
592595 KubernetesDriverError::Message(m) => Self::Message(m),
@@ -1107,12 +1110,11 @@ impl std::fmt::Debug for KubernetesComputeDriver {
11071110}
11081111
11091112impl KubernetesComputeDriver {
1110- /// Environment that lets a supervisor export spans, joining the current
1111- /// trace, OCSF events, and relayed workload traces, identifying the
1112- /// gateway that launched it.
1113- fn supervisor_otlp_environment(&self) -> Vec<(&'static str, String)> {
1113+ /// Prepared Pods are rendered across requests. Only a cold launch inherits
1114+ /// the provisioning span; exporter settings and gateway identity apply to both.
1115+ fn supervisor_otlp_environment(&self, inherit_trace: bool) -> Vec<(&'static str, String)> {
11141116 let mut environment = self.config.supervisor_otlp.environment();
1115- if self.config.supervisor_otlp.traces.is_some() {
1117+ if inherit_trace && self.config.supervisor_otlp.traces.is_some() {
11161118 environment.extend(openshell_otel::current_trace_context_environment());
11171119 }
11181120 if let Some(name) = &self.config.supervisor_gateway_name {
@@ -3607,7 +3609,6 @@ impl KubernetesComputeDriver {
36073609 upstream_proxy_ca_bundle_staged: bool,
36083610 warm: bool,
36093611 network_additional_ca: Option<(&str, &str)>,
3610- tracing_environment: &[(&str, String)],
36113612 ) -> Result<Pod, KubernetesDriverError> {
36123613 let mut pod = crate::sandbox_runtime::with_runtime_class(
36133614 crate::app_listener::configure_supervisor_pod(
@@ -3644,7 +3645,7 @@ impl KubernetesComputeDriver {
36443645 ),
36453646 network_additional_ca,
36463647 owner,
3647- tracing_environment ,
3648+ &self.supervisor_otlp_environment(!warm) ,
36483649 self.config.sandbox_attach_request_timeout_seconds,
36493650 )
36503651 .map_err(KubernetesDriverError::Message)?,
@@ -3700,7 +3701,6 @@ impl KubernetesComputeDriver {
37003701 network_additional_ca
37013702 .as_ref()
37023703 .map(|generation| (generation.name.as_str(), generation.digest.as_str())),
3703- &self.supervisor_otlp_environment(),
37043704 )?;
37053705 let stored = match pods.create(&PostParams::default(), &pod).await {
37063706 Ok(stored) => stored,
@@ -9420,7 +9420,7 @@ mod tests {
94209420 supervisor_otlp,
94219421 ..Default::default()
94229422 })
9423- .supervisor_otlp_environment()
9423+ .supervisor_otlp_environment(true )
94249424 };
94259425 let names = |supervisor_otlp| {
94269426 environment(supervisor_otlp)
@@ -9484,7 +9484,7 @@ mod tests {
94849484 ..Default::default()
94859485 });
94869486 assert_eq!(
9487- driver.supervisor_otlp_environment(),
9487+ driver.supervisor_otlp_environment(true ),
94889488 [(
94899489 openshell_core::sandbox_env::GATEWAY_NAME,
94909490 "prod-west".to_string()
@@ -10122,7 +10122,7 @@ mod tests {
1012210122 }
1012310123
1012410124 #[tokio::test]
10125- async fn sandbox_annotation_propagates_the_active_w3c_trace_context () {
10125+ async fn provisioning_trace_propagates_to_sandbox_annotations_and_cold_supervisors () {
1012610126 use opentelemetry_sdk::trace::{InMemorySpanExporterBuilder, SdkTracerProvider};
1012710127 use tracing_subscriber::layer::SubscriberExt as _;
1012810128
@@ -10137,6 +10137,22 @@ mod tests {
1013710137 let annotations = tracing::subscriber::with_default(subscriber, || {
1013810138 let span = tracing::info_span!("kubernetes.provision");
1013910139 let _entered = span.enter();
10140+ let mut driver =
10141+ KubernetesComputeDriver::new_for_test(KubernetesComputeConfig::default());
10142+ driver.config.supervisor_otlp.traces = Some(openshell_core::sandbox_env::OtlpExport {
10143+ endpoint: "http://traces:4317".into(),
10144+ protocol: openshell_core::sandbox_env::OtlpProtocol::Grpc,
10145+ });
10146+ assert!(
10147+ driver
10148+ .supervisor_otlp_environment(true)
10149+ .iter()
10150+ .any(|(name, _)| *name == openshell_otel::TRACEPARENT_ENV)
10151+ );
10152+ assert_eq!(
10153+ driver.supervisor_otlp_environment(false),
10154+ driver.config.supervisor_otlp.environment()
10155+ );
1014010156 let mut annotations = BTreeMap::new();
1014110157 add_trace_context_annotation(&mut annotations);
1014210158 annotations
0 commit comments