aws / aws-xray-sdk-go

AWS X-Ray SDK for the Go programming language.
Apache License 2.0
276 stars 117 forks source link

Consider using `errors.As` instead of type assertions in `segment.Close` to support wrapped errors #352

Open okonos opened 2 years ago

okonos commented 2 years ago

Segment.Close enriches the segment with details specific to the error passed, but since it uses type assertions, the error must be of an exact type:

https://github.com/aws/aws-xray-sdk-go/blob/053264401e5a9608d10a4c44a613cacd607cfe94/strategy/exception/default_exception_formatting_strategy.go#L118-L123 https://github.com/aws/aws-xray-sdk-go/blob/053264401e5a9608d10a4c44a613cacd607cfe94/strategy/exception/default_exception_formatting_strategy.go#L136-L138 https://github.com/aws/aws-xray-sdk-go/blob/053264401e5a9608d10a4c44a613cacd607cfe94/strategy/exception/default_exception_formatting_strategy.go#L143-L145

Using errors.As there instead of type assertions would make it work with wrapped errors as well.