Skip to content

fix(jaegermcp): use PutBool instead of PutStr for error attribute in …#8217

Open
YoungHypo wants to merge 2 commits intojaegertracing:mainfrom
YoungHypo:haibo-fix-error-type
Open

fix(jaegermcp): use PutBool instead of PutStr for error attribute in …#8217
YoungHypo wants to merge 2 commits intojaegertracing:mainfrom
YoungHypo:haibo-fix-error-type

Conversation

@YoungHypo
Copy link
Contributor

Which problem is this PR solving?

Fix search_traces.with_errors to encode the internal error query attribute as a boolean instead of a string.

The previous implementation used attributes.PutStr("error", "true"). This caused inconsistent behavior across backends. In particular, the v2 memory backend interprets the error query attribute as a boolean flag when filtering by span status, so with_errors=true could return incorrect results.

Description of the changes

  • change search_traces to use attributes.PutBool("error", true)
  • Add a new existing handler test TestSearchTracesHandler_Handle_WithErrorsFilter_UsingMemoryStore to assert boolean semantics.

Here is a Mermaid diagram to help explain why the current code had a bug in TestSearchTracesHandler_Handle_WithErrorsFilter_UsingMemoryStore.

sequenceDiagram
    participant T as Test
    participant H as handle()
    participant BQ as buildQuery()
    participant FT as FindTraces()
    participant M as memory.FindTraces()
    participant VS as validSpan()
    
    T->>H: handle(ctx, req, input)
    H->>BQ: buildQuery(input)
    Note over BQ: PutStr("error", "true")
    BQ-->>H: Attributes: {error: "true" (string)}
    H->>FT: FindTraces(ctx, query)
    FT->>M: FindTraces(ctx, query)
    M->>VS: validSpan(span, query)
    
    Note over VS: errAttribute.Bool()
    Note over VS: String.Bool() = false
    
    VS->>VS: !false && Error != Ok = true
    VS-->>M: return false
    M-->>FT: (no trace)
    FT-->>H: empty iterator
    H-->>T: output.Traces = []
Loading

How was this change tested?

go test -v ./cmd/jaeger/internal/extension/jaegermcp/internal/handlers/... -run "TestSearchTracesHandler_Handle_WithErrorsFilter_UsingMemoryStore"

Checklist

AI Usage in this PR (choose one)

See AI Usage Policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

…search_traces

Signed-off-by: haibo <haibo942us@gmail.com>
@YoungHypo YoungHypo requested a review from a team as a code owner March 21, 2026 07:50
Copilot AI review requested due to automatic review settings March 21, 2026 07:50
@dosubot dosubot bot added the bug label Mar 21, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Jaeger MCP’s search_traces.with_errors query construction to encode the internal error attribute as a boolean (instead of a string), aligning behavior across storage backends (notably the v2 memory store).

Changes:

  • Update search_traces query building to use attributes.PutBool("error", true).
  • Add a handler test that exercises WithErrors filtering against the v2 memory store implementation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces.go Switches the error attribute filter from string to boolean in buildQuery.
cmd/jaeger/internal/extension/jaegermcp/internal/handlers/search_traces_test.go Adds a memory-store-backed test for WithErrors filtering and imports the v2 memory store.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: haibo <haibo942us@gmail.com>
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.61%. Comparing base (4afa357) to head (61a51b0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8217   +/-   ##
=======================================
  Coverage   95.61%   95.61%           
=======================================
  Files         319      319           
  Lines       16793    16793           
=======================================
  Hits        16056    16056           
  Misses        582      582           
  Partials      155      155           
Flag Coverage Δ
badger_direct 9.05% <ø> (ø)
badger_e2e 1.04% <ø> (ø)
cassandra-4.x-direct-manual 13.25% <ø> (ø)
cassandra-4.x-e2e-auto 1.03% <ø> (ø)
cassandra-4.x-e2e-manual 1.03% <ø> (ø)
cassandra-5.x-direct-manual 13.25% <ø> (ø)
cassandra-5.x-e2e-auto 1.03% <ø> (ø)
cassandra-5.x-e2e-manual 1.03% <ø> (ø)
clickhouse 1.16% <ø> (ø)
elasticsearch-6.x-direct 16.83% <ø> (ø)
elasticsearch-7.x-direct 16.86% <ø> (ø)
elasticsearch-8.x-direct 17.01% <ø> (ø)
elasticsearch-8.x-e2e 1.04% <ø> (ø)
elasticsearch-9.x-e2e 1.04% <ø> (ø)
grpc_direct 7.79% <ø> (ø)
grpc_e2e 1.04% <ø> (ø)
kafka-3.x-v2 1.04% <ø> (ø)
memory_v2 1.04% <ø> (ø)
opensearch-1.x-direct 16.91% <ø> (ø)
opensearch-2.x-direct 16.91% <ø> (ø)
opensearch-2.x-e2e 1.04% <ø> (ø)
opensearch-3.x-e2e 1.04% <ø> (ø)
query 1.04% <ø> (ø)
tailsampling-processor 0.52% <ø> (ø)
unittests 94.30% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

The UI sends all tag filters as strings today, and they are converted to Attributes object using PutStr:

func convertTagsToAttributes(tags map[string]string) pcommon.Map {
attrs := pcommon.NewMap()
for k, v := range tags {
attrs.PutStr(k, v)
}
return attrs
}

Why is this MCP tool need to do differently?

@YoungHypo
Copy link
Contributor Author

As you pointed out, existing query paths normalize tag filters to strings, for example in convertTagsToAttributes, so MCP should follow the same internal convention even though types.SearchTracesInput.WithErrors is a boolean at the API layer.

// WithErrors filters to only return traces containing error spans (optional).
WithErrors bool `json:"with_errors,omitempty" jsonschema:"If true only return traces containing error spans"`

That means WithErrors being a bool in MCP input is fine. buildQuery will encode it into query attributes in String type.

if input.WithErrors {
attributes.PutStr("error", "true")
}

The inconsistency seems to be in the memory backend. In validSpan, the error filter is interpreted as bool-only via errAttribute.Bool(), instead of also accepting "true" / "false" string values. That makes memory narrower than the existing query convention.

if errAttribute, ok := query.Attributes.Get(errorAttribute); ok {
if errAttribute.Bool() && span.Status().Code() != ptrace.StatusCodeError {
return false
}
if !errAttribute.Bool() && span.Status().Code() != ptrace.StatusCodeOk {
return false
}
}

Would you prefer the fix to be in the memory backend, by making it accept both string and boolean forms of the error query attribute? @yurishkuro

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.

3 participants