← ClaudeAtlas

telemetry-facade-patternlisted

Design the app-side event pipeline that fans one `telemetry.observe(event)` call out to logging, tracking, MetricKit and Game Center sinks. Use when deciding whether Logger and analytics tracking share one interface; when adding a `TelemetrySink` / `MetricKitSink` / `GameCenterSink`; when a wired-looking sink never fires (score not submitted, achievement not unlocked, `GKLeaderboard.submitScore` unreached); when sink order or UI-blocking sink I/O matters. Does NOT choose the Logger API (oslog-logger-defaults) or which analytics sources to use (apple-three-piece-analytics).
wei18/apple-dev-skills · ★ 19 · AI & Automation · score 78
Install: claude install-skill wei18/apple-dev-skills
# Telemetry Facade Pattern ## When to invoke - Starting a new project and designing the logger / tracker / metrics interface. - About to introduce OSLog and any tracking / analytics at the same time. - Wanting to preserve flexibility for "swap the tracking provider later". - User asks "should Logger and Tracking be separate", "how should the event interface look". ## Default decisions ### A single `Telemetry` target - Create one `Telemetry` target inside the SwiftPM Package. - It contains: - `TelemetryEvent` value type (enum / struct, `Sendable`) - `TelemetrySink` protocol: ```swift public protocol TelemetrySink: Sendable { func receive(_ event: TelemetryEvent) async } ``` - The main facade — default to a `Telemetry` **actor**. Sink stateful subscriptions (e.g. `MetricKitSink` holding `MXMetricManagerSubscriber` reference identity) require an actor for clean lifecycle management. A `Sendable` struct facade is acceptable only when every sink is fully synchronous and stateless. The facade fans out to multiple sinks. - Default sinks (see below) ### Call sites describe only "what happened" ```swift telemetry.observe(.puzzleCompleted(id: puzzleId, durationMs: 12_345)) ``` - The call site **doesn't know** who will consume the event. - Swapping providers / adding sinks only requires replacing a sink; call sites change nothing. ### Default sink set | Sink | Receives | Purpose | |---|---|---| | `OSLogSink` | All events | Human-readable debug m