open-telemetry / opentelemetry-swift

OpenTelemetry API for Swift
https://opentelemetry.io/docs/instrumentation/swift/
Apache License 2.0
221 stars 145 forks source link

Add `recordException` #599

Closed brunnoferreira closed 1 month ago

brunnoferreira commented 2 months ago

This pull request aims to resolve #117.

Since Swift does not offer a superclass like Throwable in Java to group all exception types, one challenge facing these changes is a polluted API, with a long list of methods to encompass NSException, NSError and Error.

To work around that problem I have chosen to include a new protocol named SpanException, describing the basic properties required to create a meaningful exception event. That, alongside extensions that automatically conform both NSError (and, automatically, Error) and NSException, should cater for most use cases. For everything else, users should simply need to conform their custom types to SpanException.

If there is any feedback on this, please let me know – happy to update as we go.

linux-foundation-easycla[bot] commented 2 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

brunnoferreira commented 1 month ago

Thanks for the review, @vvydier!

I just pushed a couple of minor changes based on the results of the workflow, if you could please run it again when convenient.

One of my tests was flaky, so I got it fixed. Also turns out NSException is not available on Linux despite being part of Foundation, so I made sure we don't try compiling it there.