diff --git a/agent/executable.go b/agent/executable.go index 0e2fe76..52a1b8b 100644 --- a/agent/executable.go +++ b/agent/executable.go @@ -18,6 +18,7 @@ func SetExecutablePattern(ctx context.Context, pattern string) { matches, err := filepath.Glob(pattern) if err != nil { + span.RecordError(err) span.SetStatus(codes.Error, err.Error()) return } @@ -35,6 +36,7 @@ func ensureExecutable(ctx context.Context, app string) { stat, err := os.Stat(app) if err != nil { + span.RecordError(err) span.SetStatus(codes.Error, err.Error()) return } @@ -52,6 +54,7 @@ func ensureExecutable(ctx context.Context, app string) { err := os.Chmod(app, stat.Mode()|0111) if err != nil { span.SetAttributes(attribute.String("mode.final", stat.Mode().String())) + span.RecordError(err) span.SetStatus(codes.Error, err.Error()) } else { span.SetAttributes(attribute.String("mode.final", (stat.Mode() | 0111).String())) diff --git a/agent/launcher.go b/agent/launcher.go index 6654632..298d6b6 100644 --- a/agent/launcher.go +++ b/agent/launcher.go @@ -13,7 +13,7 @@ import ( ) func RunApp(ctx context.Context, app string, args []string) error { - ctx, span := otel.Tracer("vault").Start(ctx, "launcher.RunApp") + ctx, span := otel.Tracer("vault").Start(ctx, "launcher.RunApp", trace.WithSpanKind(trace.SpanKindServer)) defer span.End() ensureExecutable(ctx, app) @@ -39,6 +39,7 @@ func RunApp(ctx context.Context, app string, args []string) error { select { case s := <-c: if cmd.Process != nil { + span.AddEvent("Propagating signal to child process.", trace.WithAttributes(attribute.String("signal", s.String()))) cmd.Process.Signal(s) } case <-exit: @@ -52,6 +53,7 @@ func RunApp(ctx context.Context, app string, args []string) error { err = cmd.Run() if err != nil { + span.RecordError(err) span.SetStatus(codes.Error, err.Error()) } diff --git a/agent/telemetry.go b/agent/telemetry.go index 3c24c5e..64c0e69 100644 --- a/agent/telemetry.go +++ b/agent/telemetry.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "os" - "time" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" @@ -65,8 +66,13 @@ func NewTelemetryLogStream(ctx context.Context, span trace.Span) *TelemetryLogSt } func (s *TelemetryLogStream) Write(p []byte) (n int, err error) { + _, span := otel.Tracer("vault").Start(s.ctx, "launcher.TelemetryLogStream.Write", trace.WithSpanKind(trace.SpanKindConsumer)) + defer span.End() + props := map[string]string{} if err := json.Unmarshal(p, &props); err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) s.span.AddEvent( "Failed to parse log message", trace.WithAttributes(attribute.String("message", string(p)), attribute.String("error", err.Error())), @@ -75,18 +81,13 @@ func (s *TelemetryLogStream) Write(p []byte) (n int, err error) { return os.Stdout.Write(p) } - options := []trace.EventOption{} - if ts, err := time.Parse(time.RFC3339, props["@timestamp"]); err == nil { - options = append(options, trace.WithTimestamp(ts)) - } - properties := []attribute.KeyValue{} for k, v := range props { properties = append(properties, attribute.String(k, v)) } - options = append(options, trace.WithAttributes(properties...)) - s.span.AddEvent(props["@message"], options...) + span.SetAttributes(properties...) + span.SetName(props["@message"]) return len(p), nil } diff --git a/terraform/main.tf b/terraform/main.tf index 4607af7..9c98c65 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -18,7 +18,7 @@ variable "vault_version" { variable "vault_agent_version" { description = "The version of the Vault agent to use." - default = "1.3.1" + default = "1.3.2" } variable "opentelemetry" {