Skip to content

fix: report exception types instead of error codes - #124

Closed
NikitaKurpas wants to merge 5 commits into
open-telemetry:mainfrom
NikitaKurpas:codex/fix-exception-type
Closed

NikitaKurpas wants to merge 5 commits into
open-telemetry:mainfrom
NikitaKurpas:codex/fix-exception-type

Conversation

@NikitaKurpas

@NikitaKurpas NikitaKurpas commented Oct 5, 2026 •

Copy link
Copy Markdown

exception.type currently contains a numeric error code. Codes do not identify the error type and can mean different things in different domains. When no custom localized description is supplied, Foundation already includes the code in the default localizedDescription.

Report the fully qualified Swift error type using String(reflecting:), falling back to the domain for plain NSError. Casting back to Error before reading its dynamic type preserves bridged Swift error types. Qualified names distinguish errors with the same short name in different modules or enclosing types.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: NikitaKurpas / name: Nikita Kurpas (84af1e2)

public var type: String {
String(code)
let error = self as Error
return Swift.type(of: error) == NSError.self ? domain : String(describing: Swift.type(of: error))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception.type is supposed to be the fully qualified type name, like MyApp.ServiceA.Failure. String(describing:) only keeps the last piece, so ServiceA.Failure and ServiceB.Failure both show up as "Failure".

PostHog can get away with the short name because it also sends the module separately. We only have exception.type, so the qualified name has to go there.

Could we use String(reflecting:) and, when the dynamic type is NSError, keep using domain? That covers URLError and plain NSError, whose useful name is the domain (NSURLErrorDomain).

One cleanup: for private and function-local errors, String(reflecting:) includes an address, (unknown context at $…), that changes every app launch. Strip that part so the same error does not look new on every run.

@nachoBonafonte @bryce-b any inputs here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with String(reflecting:) but decided to go with String(describing:) 😅
Reverted that, now it uses String(reflecting:).

@NikitaKurpas NikitaKurpas Oct 6, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One cleanup: for private and function-local errors, String(reflecting:) includes an address, (unknown context at $…), that changes every app launch.

TIL. Removed the (unknown context at $…) part.

@nachoBonafonte

Copy link
Copy Markdown
Member

Hi, this repository is on hold, so no more PRs here, there is already a PR on the main library open telemetry-swift to move all the core code there: 1220. This PR should be created there once the 1220 PR is merged.

@NikitaKurpas

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants