Skip to content

feat(go): add attributes to CLI - #638

Merged
AndreyMarkinPPC merged 1 commit into
mainfrom
go-otel
Oct 16, 2026
Merged

AndreyMarkinPPC merged 1 commit into
mainfrom
go-otel

Conversation

@AndreyMarkinPPC

Copy link
Copy Markdown
Member

No description provided.

@AndreyMarkinPPC AndreyMarkinPPC self-assigned this Oct 16, 2026
@AndreyMarkinPPC
AndreyMarkinPPC merged commit 82255f8 into main Oct 16, 2026
6 checks passed
@AndreyMarkinPPC
AndreyMarkinPPC deleted the go-otel branch October 16, 2026 21:02

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds OpenTelemetry tracing attributes to the execute and run CLI commands, and appends LIMIT clauses to the example SQL queries. However, the changes in root.go introduce a couple of issues: they discard the command context by using context.Background() and create a potential span leak if garf.New returns an error.

Comment thread sdk/go/garf/cmd/root.go
Comment on lines +45 to 49
ctx, _ := tracer.Start(context.Background(), "cli")
cmd.SetContext(ctx)
defer span.End()
garfEndpoint := viper.GetString("endpoint")
g, err := garf.New(ctx, garfEndpoint)
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are two issues here:\n1. Context Propagation: Using context.Background() discards any context (including cancellation, deadlines, or parent metadata) that Cobra or the caller set up on the command. We should use cmd.Context() instead.\n2. Span Leak on Error: If garf.New returns an error, PersistentPreRunE exits early. Since PersistentPostRunE is not executed when PersistentPreRunE fails, the span created here will be leaked (never ended). We should capture the span and explicitly call span.End() in the error path.

Suggested change
ctx, _ := tracer.Start(context.Background(), "cli")
cmd.SetContext(ctx)
defer span.End()
garfEndpoint := viper.GetString("endpoint")
g, err := garf.New(ctx, garfEndpoint)
if err != nil {
ctx, span := tracer.Start(cmd.Context(), "cli")
cmd.SetContext(ctx)
garfEndpoint := viper.GetString("endpoint")
g, err := garf.New(ctx, garfEndpoint)
if err != nil {
span.End()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant