Skip to content

Commit

Permalink
Merge pull request #427 from overmindtech/tracing
Browse files Browse the repository at this point in the history
Ensure that tracing data is correctly finalised
  • Loading branch information
DavidS-ovm authored Jun 21, 2024
2 parents 92c566a + ec0baac commit 8745ea9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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

0 comments on commit 8745ea9

Please sign in to comment.