Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that tracing data is correctly finalised #427

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func Execute() {
}()

// shutdown and submit any remaining otel data before exiting
if cmdSpan != nil {
cmdSpan.End()
}
tracing.ShutdownTracer()

if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions cmd/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -61,10 +59,6 @@ func CmdWrapper(action string, requiredScopes []string, commandModel func(args [
defer cancel()

cmdName := fmt.Sprintf("CLI %v", cmd.CommandPath())
ctx, span := tracing.Tracer().Start(ctx, cmdName, trace.WithAttributes(
attribute.String("ovm.config", fmt.Sprintf("%v", tracedSettings())),
))
defer span.End()
defer tracing.LogRecoverToExit(ctx, cmdName)

// ensure that only error messages are printed to the console,
Expand Down Expand Up @@ -132,7 +126,9 @@ func CmdWrapper(action string, requiredScopes []string, commandModel func(args [
if err != nil {
log.WithContext(ctx).WithError(err).Error("Error running command")
// don't forget that os.Exit() does not wait for telemetry to be flushed
span.End()
if cmdSpan != nil {
cmdSpan.End()
}
tracing.ShutdownTracer()
os.Exit(1)
}
Expand Down
Loading