diff --git a/server/expression/executor.go b/server/expression/executor.go index 3f3d0b40c7..c4e21b9e40 100644 --- a/server/expression/executor.go +++ b/server/expression/executor.go @@ -341,7 +341,7 @@ func (e Executor) executeFilter(input value.Value, filter *Filter) (value.Value, return value.Nil, err } - args = append(args, resolvedArg.Value().Value) + args = append(args, resolvedArg.UnescappedString()) } newValue, err := executeFilter(input, filter.Name, args) diff --git a/server/expression/executor_test.go b/server/expression/executor_test.go index c6cf3448e4..6480f46072 100644 --- a/server/expression/executor_test.go +++ b/server/expression/executor_test.go @@ -182,6 +182,13 @@ func TestStringInterpolationExecution(t *testing.T) { } func TestFilterExecution(t *testing.T) { + jsonResponseSpan := traces.Span{ + ID: id.NewRandGenerator().SpanID(), + Attributes: traces.NewAttributes(), + } + + jsonResponseSpan.Attributes.Set("tracetest.response.body", `{"results":[{"count(*)":{"result":3}}]}`) + testCases := []executorTestCase{ { Name: "should_extract_id_from_json", @@ -216,6 +223,14 @@ func TestFilterExecution(t *testing.T) { Query: `'{ "array": [1, 2, 5] }' | json_path '$.array[*]' | get_index 'last' = 5`, ShouldPass: true, }, + { + Name: "should_unescape_filter_arg", + Query: `attr:tracetest.response.body | json_path '$.results[0][\'count(*)\'].result' = 3`, + ShouldPass: true, + AttributeDataStore: expression.AttributeDataStore{ + Span: jsonResponseSpan, + }, + }, } executeTestCases(t, testCases) diff --git a/server/expression/value/value.go b/server/expression/value/value.go index c67a602a01..2b1aa731fd 100644 --- a/server/expression/value/value.go +++ b/server/expression/value/value.go @@ -83,3 +83,11 @@ func (v Value) String() string { return v.Value().Value } + +func (v Value) UnescappedString() string { + output := v.String() + output = strings.ReplaceAll(output, `\'`, `'`) + output = strings.ReplaceAll(output, `\"`, `"`) + + return output +}