-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Aleksei Sapitskii <[email protected]>
- Loading branch information
1 parent
cd70206
commit f6bb3af
Showing
8 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
|
||
extension TelemetryCounter { | ||
fileprivate static let sdkPrefix = "maps-mobile" | ||
fileprivate static let swiftUI = TelemetryCounter.create(name: "map", category: "swift-ui") | ||
fileprivate static let viewportCameraState = TelemetryCounter.viewport(name: "state/camera") | ||
fileprivate static let viewportFollowState = TelemetryCounter.viewport(name: "state/follow-puck") | ||
fileprivate static let viewportOverviewState = TelemetryCounter.viewport(name: "state/overview") | ||
fileprivate static let viewportTransition = TelemetryCounter.viewport(name: "transition") | ||
fileprivate static let styleDSL = TelemetryCounter.create(name: "dsl", category: "style") | ||
fileprivate static let carPlay = TelemetryCounter.create(forName: sdkPrefix + "/carplay") | ||
|
||
private static func viewport(name: String) -> TelemetryCounter { | ||
.create(name: name, category: "viewport") | ||
} | ||
|
||
private static func create(name: String, category: String) -> TelemetryCounter { | ||
.create(forName: [sdkPrefix, category, name].joined(separator: "/")) | ||
} | ||
} | ||
|
||
/// Default scope for telemetry events | ||
/// This scope and all posible future scopes should be singleton to get rid of spawning several equal counters | ||
/// Also singleton allows the usage of KeyPath in sendTelemetry (static members on metatype not allowed in KeyPath) | ||
struct TelemetryEvents { | ||
let swiftUI = TelemetryEvent(counter: .swiftUI) | ||
let viewportCameraState = TelemetryEvent(counter: .viewportCameraState) | ||
let viewportFollowState = TelemetryEvent(counter: .viewportFollowState) | ||
let viewportOverviewState = TelemetryEvent(counter: .viewportOverviewState) | ||
let viewportTransition = TelemetryEvent(counter: .viewportTransition) | ||
let styleDSL = TelemetryEvent(counter: .styleDSL) | ||
let carPlay = TelemetryEvent(counter: .carPlay) | ||
|
||
static let shared = TelemetryEvents() | ||
|
||
fileprivate init() {} | ||
} | ||
|
||
/// Abstraction over the actiual telemetry implementation, which hides all the implementtion details | ||
/// All it's properties should be fileprivate to keep implementation inside the file | ||
struct TelemetryEvent { | ||
fileprivate let counter: TelemetryCounter | ||
} | ||
|
||
/// Interface for sending telemetry using the default events scope | ||
/// Allows to send events in type-safe manner while keeping implementstion details hidden from client code | ||
func sendTelemetry(_ eventName: KeyPath<TelemetryEvents, TelemetryEvent>) { | ||
sendTelemetry(eventName: eventName, category: TelemetryEvents.shared) | ||
} | ||
|
||
/// Interface for sending telemetry using the custom scope | ||
/// Allows to send events in type-safe manner while keeping implementstion details hidden from client code and specify custom scope to group event when their number will grow | ||
func sendTelemetry<T>(eventName: KeyPath<T, TelemetryEvent>, category: T) { | ||
let event = category[keyPath: eventName] | ||
event.counter.increment() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters