Skip to content

fix(observability): avoid error status for expected pkgsite results - #25

Merged
garrettladley merged 1 commit into
mainfrom
gml/fix-pkgsite-span-status
May 29, 2026
Merged

garrettladley merged 1 commit into
mainfrom
gml/fix-pkgsite-span-status

Conversation

@garrettladley

Copy link
Copy Markdown
Owner
  • keep expected pkgsite tool results from setting span codes.Error
  • preserve observability.ResultAttrs status-code attributes for handled pkgsite errors
  • add coverage for unexpectedPkgsiteStatus across expected 4xx and unexpected 5xx results

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a noisy observability footprint where expected pkgsite 4xx responses (404, 400, 429) were incorrectly marking OTel spans as codes.Error. The new unexpectedPkgsiteStatus helper gates that status transition on statusCode >= 500, preserving the ErrorStatusCode attribute on ResultAttrs for all error cases regardless.

  • register.go: Wraps span.SetStatus(codes.Error, …) in unexpectedPkgsiteStatus, so 4xx pkgsite responses keep the span's default OK status while still recording the status-code attribute.
  • register_test.go: Adds a parallel table-driven unit test for unexpectedPkgsiteStatus covering representative 4xx (false) and 5xx (true) inputs.

Confidence Score: 5/5

Safe to merge; the change is narrowly scoped to the OTel span-status path and does not alter any data returned to callers.

The diff is small and correct: 4xx responses from pkgsite are expected client-side outcomes and should not flip span status to Error. The unexpectedPkgsiteStatus helper is straightforwardly expressed and well-tested. The only gap is the absence of a statusCode=0 test case, which is a documentation concern rather than a runtime defect.

No files require special attention.

Important Files Changed

Filename Overview
internal/mcpserver/tools/register.go Guards span.SetStatus(codes.Error) behind a new unexpectedPkgsiteStatus check (statusCode >= 500), so expected 4xx responses from pkgsite no longer pollute trace error counts.
internal/mcpserver/tools/register_test.go New parallel table-driven tests for unexpectedPkgsiteStatus covering 400, 404, 429 (false) and 500, 503 (true); missing a case for statusCode=0.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[s.result called] --> B{Go-level error?}
    B -- yes --> C[return nil, nil, err]
    B -- no --> D{result.Error != nil?}
    D -- no --> E[set ResultAttrs attributes on span]
    D -- yes --> F[set ErrorStatusCode on ResultAttrs]
    F --> G{unexpectedPkgsiteStatus\nstatusCode >= 500?}
    G -- yes --> H[span.SetStatus codes.Error]
    G -- no --> I[4xx: span stays OK]
    H --> E
    I --> E
    E --> J{result.Items > 0\nor Pagination != nil?}
    J -- yes --> K[return paginatedEnvelope]
    J -- no --> L[return singleEnvelope]
Loading

Reviews (1): Last reviewed commit: "fix(observability): avoid error status f..." | Re-trigger Greptile

Comment on lines +11 to +20
tests := []struct {
status int
want bool
}{
{status: 400, want: false},
{status: 404, want: false},
{status: 429, want: false},
{status: 500, want: true},
{status: 503, want: true},
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The test suite doesn't include statusCode = 0. An APIError with a zero-valued StatusCode (e.g. constructed without setting the field) would return false from unexpectedPkgsiteStatus, silently skipping the error span. Adding a 0 case makes the boundary explicit and documents the intended treatment of that sentinel value.

Suggested change
tests := []struct {
status int
want bool
}{
{status: 400, want: false},
{status: 404, want: false},
{status: 429, want: false},
{status: 500, want: true},
{status: 503, want: true},
}
tests := []struct {
status int
want bool
}{
{status: 0, want: false},
{status: 400, want: false},
{status: 404, want: false},
{status: 429, want: false},
{status: 500, want: true},
{status: 503, want: true},
}

@garrettladley
garrettladley merged commit bed5eb9 into main May 29, 2026
3 checks passed
@garrettladley
garrettladley deleted the gml/fix-pkgsite-span-status branch May 29, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant