From 8fbff53edc19e2ab8c0e0ffcc60a321bdd1c6e04 Mon Sep 17 00:00:00 2001 From: Nitish Chauhan <72253189+nitishchauhan0022@users.noreply.github.com> Date: Thu, 31 Aug 2023 09:30:56 +0530 Subject: [PATCH] fixing the nesting of tracing (#2781) * fixing the nesting of tracing Signed-off-by: ntishchauhan0022 --------- Signed-off-by: ntishchauhan0022 --- cmd/porter/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 {