diff --git a/cmd/porter/main.go b/cmd/porter/main.go index 11aa70852..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 @@ -187,7 +188,17 @@ 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) - return nil + ctx, err := p.Connect(cmd.Context()) + + // 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 { if printVersion { diff --git a/tests/integration/telemetry_test.go b/tests/integration/telemetry_test.go index 98d900551..f9a97b8b8 100644 --- a/tests/integration/telemetry_test.go +++ b/tests/integration/telemetry_test.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "testing" + "time" "get.porter.sh/porter/pkg/porter" "get.porter.sh/porter/tests" @@ -29,7 +30,7 @@ func TestTelemetrySetup(t *testing.T) { defer test.RunPorter("uninstall", "otel-jaeger", "--allow-docker-host-access") // Wait until the collection should be up - // time.Sleep(10 * time.Second) + time.Sleep(10 * time.Second) // Try to run porter with telemetry enabled p := porter.New()