Skip to content

Commit

Permalink
fix OTEL Exception Message Propagation (#341)
Browse files Browse the repository at this point in the history
Only propagate exception if event message is empty
  • Loading branch information
rubvs authored Aug 29, 2024
1 parent 341bb20 commit fcd5ede
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
4 changes: 3 additions & 1 deletion model/modelprocessor/errormessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (s SetErrorMessage) ProcessBatch(ctx context.Context, b *modelpb.Batch) err
for i := range *b {
event := (*b)[i]
if event.Error != nil {
event.Message = s.setErrorMessage(event)
if event.GetMessage() == "" {
event.Message = s.setErrorMessage(event)
}
}
}
return nil
Expand Down
59 changes: 39 additions & 20 deletions model/modelprocessor/errormessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,56 @@ import (

func TestSetErrorMessage(t *testing.T) {
tests := []struct {
input *modelpb.Error
message string
desc string
input *modelpb.APMEvent
expectedMessage string
}{{
input: &modelpb.Error{},
message: "",
}, {
input: &modelpb.Error{Log: &modelpb.ErrorLog{Message: "log_message"}},
message: "log_message",
desc: "keep event message when no error",
input: &modelpb.APMEvent{
Error: &modelpb.Error{
Log: &modelpb.ErrorLog{},
Exception: &modelpb.Exception{},
},
Message: "message",
},
expectedMessage: "message",
}, {
input: &modelpb.Error{Exception: &modelpb.Exception{Message: "exception_message"}},
message: "exception_message",
desc: "keep event message when error",
input: &modelpb.APMEvent{
Error: &modelpb.Error{
Log: &modelpb.ErrorLog{Message: "log_message"},
Exception: &modelpb.Exception{Message: "exception_message"},
},
Message: "message",
},
expectedMessage: "message",
}, {
input: &modelpb.Error{
Log: &modelpb.ErrorLog{},
Exception: &modelpb.Exception{Message: "exception_message"},
desc: "propagate log error if event message empty",
input: &modelpb.APMEvent{
Error: &modelpb.Error{
Log: &modelpb.ErrorLog{Message: "log_message"},
Exception: &modelpb.Exception{},
},
Message: "",
},
message: "exception_message",
expectedMessage: "log_message",
}, {
input: &modelpb.Error{
Log: &modelpb.ErrorLog{Message: "log_message"},
Exception: &modelpb.Exception{Message: "exception_message"},
desc: "propagate exception error if event message is empty",
input: &modelpb.APMEvent{
Error: &modelpb.Error{
Log: &modelpb.ErrorLog{},
Exception: &modelpb.Exception{Message: "exception_message"},
},
Message: "",
},
message: "log_message",
expectedMessage: "exception_message",
}}

for _, test := range tests {
batch := modelpb.Batch{{Error: test.input}}
batch := modelpb.Batch{test.input}
processor := modelprocessor.SetErrorMessage{}
err := processor.ProcessBatch(context.Background(), &batch)
assert.NoError(t, err)
assert.Equal(t, test.message, batch[0].Message)
assert.Equal(t, test.expectedMessage, batch[0].Message)
}

}

0 comments on commit fcd5ede

Please sign in to comment.