Sentry's engineering team details their design process for building a type-safe Metrics API in Swift. The article demonstrates using protocol extensions for default parameter values, enums with associated values for flexible unit types, and ExpressibleByStringLiteral for cleaner syntax. The implementation allows developers to capture counters, gauges, and distributions with compile-time safety while supporting both predefined and custom metric units. Part I covers the foundational API design patterns, with Part II promising deeper dives into type-safe attributes and forward-compatible enum design.

9m read timeFrom sentry.engineering
Post cover image
Table of contents
Three Important MethodsMetrics Units, Enums And Generic ValuesWhat's Next

Sort: