@@ -17,6 +17,8 @@ import (
1717 "github.com/chainguard-dev/terraform-provider-imagetest/internal/drivers"
1818 "github.com/chainguard-dev/terraform-provider-imagetest/internal/entrypoint"
1919 "github.com/google/go-containerregistry/pkg/name"
20+ "go.opentelemetry.io/otel/attribute"
21+ "go.opentelemetry.io/otel/trace"
2022 authv1 "k8s.io/api/authorization/v1"
2123 corev1 "k8s.io/api/core/v1"
2224 rbacv1 "k8s.io/api/rbac/v1"
@@ -85,15 +87,19 @@ func Run(ctx context.Context, kcfg *rest.Config, options ...RunOpts) (*drivers.R
8587 }
8688 o .client = kcli
8789
90+ span := trace .SpanFromContext (ctx )
91+
8892 if err := o .preflight (ctx ); err != nil {
8993 return nil , err
9094 }
95+ span .AddEvent ("pod.preflight.complete" )
9196
9297 pobj , err := o .client .CoreV1 ().Pods (o .Namespace ).
9398 Create (ctx , o .pod (), metav1.CreateOptions {})
9499 if err != nil {
95100 return nil , fmt .Errorf ("failed to create pod: %w" , err )
96101 }
102+ span .AddEvent ("pod.created" )
97103
98104 pw , err := o .client .CoreV1 ().Pods (pobj .Namespace ).Watch (ctx , metav1.ListOptions {
99105 FieldSelector : fmt .Sprintf ("metadata.name=%s" , pobj .Name ),
@@ -121,6 +127,8 @@ func Run(ctx context.Context, kcfg *rest.Config, options ...RunOpts) (*drivers.R
121127 result := & drivers.RunResult {Artifact : & drivers.RunArtifactResult {}}
122128 if err := o .getArtifact (ctx , pobj , result ); err != nil {
123129 clog .ErrorContext (ctx , "failed to get artifact" , "error" , err )
130+ } else {
131+ span .AddEvent ("pod.artifact.retrieved" )
124132 }
125133
126134 return result , monitorErr
@@ -253,6 +261,7 @@ func monitor(ctx context.Context, cli kubernetes.Interface, pod *corev1.Pod) err
253261
254262 if ! logStarted && p .Status .Phase == corev1 .PodRunning {
255263 logStarted = true
264+ trace .SpanFromContext (ctx ).AddEvent ("pod.running" )
256265 clog .InfoContext (ctx , "starting log stream" )
257266 logch = startLogStream (ctx , cli , pod )
258267 }
@@ -263,6 +272,9 @@ func monitor(ctx context.Context, cli kubernetes.Interface, pod *corev1.Pod) err
263272
264273 for _ , cs := range p .Status .ContainerStatuses {
265274 if cs .Name == SandboxContainerName && cs .State .Terminated != nil {
275+ trace .SpanFromContext (ctx ).AddEvent ("pod.completed" ,
276+ trace .WithAttributes (attribute .Int64 ("exit_code" , int64 (cs .State .Terminated .ExitCode ))),
277+ )
266278 clog .InfoContext (ctx , "sandbox container terminated" ,
267279 "exit_code" , cs .State .Terminated .ExitCode ,
268280 "reason" , cs .State .Terminated .Reason ,
0 commit comments