MCPcopy
hub / github.com/grafana/tempo / ParseIdentifier

Function ParseIdentifier

pkg/traceql/parse.go:88–118  ·  view source on GitHub ↗

warning: ParseIdentifier is used to parse filter policies in pkg/spanfilter/config/config.go if changed, it can break existing config. Behavioral note vs. the previous implementation: this now rejects identifiers containing unquoted spaces (e.g. ".foo bar") that were previously accepted via HasPref

(s string)

Source from the content-addressed store, hash-verified

86// unquoted spaces (e.g. ".foo bar") that were previously accepted via HasPrefix matching.
87// Quoted identifiers with spaces (e.g. span."foo bar") are still accepted.
88func ParseIdentifier(s string) (Attribute, error) {
89 // Wrap the identifier in curly braces to create a valid spanset filter expression
90 attr := "{" + s + "}"
91 expr, err := ParseNoOptimizations(attr)
92 if err != nil {
93 return Attribute{}, fmt.Errorf("failed to parse identifier %s: %w", s, err)
94 }
95
96 // Validate the parsed expression structure
97 if expr == nil {
98 return Attribute{}, fmt.Errorf("failed to parse identifier %s: parsed expression is nil", s)
99 }
100
101 if len(expr.Pipeline.Elements) == 0 {
102 return Attribute{}, fmt.Errorf("failed to parse identifier %s: no pipeline elements found", s)
103 }
104
105 // Extract and validate the spanset filter
106 filter, ok := expr.Pipeline.Elements[0].(*SpansetFilter)
107 if !ok {
108 return Attribute{}, fmt.Errorf("failed to parse identifier %s: expected SpansetFilter but got %T", s, expr.Pipeline.Elements[0])
109 }
110
111 // Extract and validate the attribute
112 attribute, ok := filter.Expression.(Attribute)
113 if !ok {
114 return Attribute{}, fmt.Errorf("failed to parse identifier %s: expected Attribute but got %T", s, filter.Expression)
115 }
116
117 return attribute, nil
118}
119
120func MustParseIdentifier(s string) Attribute {
121 a, err := ParseIdentifier(s)

Callers 15

SearchTagValuesV2Method · 0.92
TestFetchTagValuesFunction · 0.92
BenchmarkFetchTagValuesFunction · 0.92
TestFetchTagValuesFunction · 0.92
BenchmarkFetchTagValuesFunction · 0.92
TestFetchTagValuesFunction · 0.92
BenchmarkFetchTagValuesFunction · 0.92
SearchTagValuesV2Method · 0.92

Calls 1

ParseNoOptimizationsFunction · 0.85

Tested by 13

TestFetchTagValuesFunction · 0.74
BenchmarkFetchTagValuesFunction · 0.74
TestFetchTagValuesFunction · 0.74
BenchmarkFetchTagValuesFunction · 0.74
TestFetchTagValuesFunction · 0.74
BenchmarkFetchTagValuesFunction · 0.74
TestParseIdentifierFunction · 0.68