diff --git a/cmd/porter/main.go b/cmd/porter/main.go index 388a42e75..795778b3d 100644 --- a/cmd/porter/main.go +++ b/cmd/porter/main.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var includeDocsCommand = false @@ -188,7 +189,15 @@ Try our QuickStart https://getporter.org/quickstart to learn how to use Porter. // Reload configuration with the now parsed cli flags p.DataLoader = cli.LoadHierarchicalConfig(cmd) ctx, err := p.Connect(cmd.Context()) - cmd.SetContext(ctx) + + // Extract the parent span from the main command + parentSpan := trace.SpanFromContext(cmd.Context()) + + // Create a context with the main command's span + ctxWithRootCmdSpan := trace.ContextWithSpan(ctx, parentSpan) + + // Set the new context to the command + cmd.SetContext(ctxWithRootCmdSpan) return err }, RunE: func(cmd *cobra.Command, args []string) error {