Skip to content

Commit

Permalink
update "attribute not found" message to include span details
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Feb 20, 2024
1 parent 5f46d4a commit c2652aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions server/expression/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ func (ds AttributeDataStore) Source() string {

func (ds AttributeDataStore) getFromAlias(name string) (string, error) {
alias, found := attributeAlias[name]
notMatchingErr := fmt.Errorf(`attribute "%s" not found in span "%s" (ID: %s)`, name, ds.Span.Name, ds.Span.ID.String())

if !found {
return "", fmt.Errorf(`attribute "%s" not found`, name)
return "", notMatchingErr
}

value := ds.Span.Attributes.Get(alias)
if value == "" {
return "", fmt.Errorf(`attribute "%s" not found`, name)
return "", notMatchingErr
}

return value, nil
Expand All @@ -45,7 +46,7 @@ func (ds AttributeDataStore) Get(name string) (string, error) {
// It's probably a nil span and we never got a matching selector,
// so instead of returning a resolution error, let's return a non-matching
// span error instead
return "", fmt.Errorf(`there are no matching spans to retrieve the attribute "%s" from`, name)
return "", fmt.Errorf(`there are no matching spans to retrieve the attribute "%s" from. To fix this error, create a selector matching at least one span.`, name)
}

value := ds.Span.Attributes.Get(name)
Expand Down
8 changes: 5 additions & 3 deletions server/expression/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestBasicOperationExecution(t *testing.T) {
}

func TestAttributeExecution(t *testing.T) {
notMatchingAttributeSpanID := id.NewRandGenerator().SpanID()
testCases := []executorTestCase{
{
Name: "should_get_values_from_attributes",
Expand Down Expand Up @@ -129,19 +130,20 @@ func TestAttributeExecution(t *testing.T) {
Name: "should_return_error_when_attribute_doesnt_exist",
Query: "attr:dapr-app-id = 43",
ShouldPass: false,
ExpectedErrorMessage: `resolution error: attribute "dapr-app-id" not found`,
ExpectedErrorMessage: fmt.Sprintf(`resolution error: attribute "dapr-app-id" not found in span "Span name" (ID: %s)`, notMatchingAttributeSpanID.String()),

AttributeDataStore: expression.AttributeDataStore{
Span: traces.Span{
ID: id.NewRandGenerator().SpanID(),
Name: "Span name",
ID: notMatchingAttributeSpanID,
},
},
},
{
Name: "should_return_error_when_no_matching_spans",
Query: "attr:dapr-app-id = 42",
ShouldPass: false,
ExpectedErrorMessage: `resolution error: there are no matching spans to retrieve the attribute "dapr-app-id" from`,
ExpectedErrorMessage: `resolution error: there are no matching spans to retrieve the attribute "dapr-app-id" from. To fix this error, create a selector matching at least one span.`,

AttributeDataStore: expression.AttributeDataStore{
Span: traces.Span{
Expand Down

0 comments on commit c2652aa

Please sign in to comment.