Skip to content

feat: add enrichment of StartRequest with OS, device ID, version #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Coder-Desktop/VPN/Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import VPNLib
actor Manager {
let ptp: PacketTunnelProvider
let cfg: ManagerConfig
let telemetryEnricher: TelemetryEnricher

let tunnelHandle: TunnelHandle
let speaker: Speaker<Vpn_ManagerMessage, Vpn_TunnelMessage>
Expand All @@ -19,6 +20,7 @@ actor Manager {
init(with: PacketTunnelProvider, cfg: ManagerConfig) async throws(ManagerError) {
ptp = with
self.cfg = cfg
telemetryEnricher = TelemetryEnricher()
#if arch(arm64)
let dylibPath = cfg.serverUrl.appending(path: "bin/coder-vpn-darwin-arm64.dylib")
#elseif arch(x86_64)
Expand Down Expand Up @@ -176,6 +178,7 @@ actor Manager {
req.value = header.value
}
}
req = telemetryEnricher.enrich(req)
}
})
} catch {
Expand Down
31 changes: 31 additions & 0 deletions Coder-Desktop/VPNLib/TelemetryEnricher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Foundation

public struct TelemetryEnricher {
private let deviceID: String
private let version: String?

public init() {
version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

let userDefaults = UserDefaults.standard
let key = "deviceID"

if let existingID = userDefaults.string(forKey: key) {
deviceID = existingID
} else {
let newID = UUID().uuidString
userDefaults.set(newID, forKey: key)
deviceID = newID
}
}

public func enrich(_ original: Vpn_StartRequest) -> Vpn_StartRequest {
var req = original
req.deviceOs = "macOS"
req.deviceID = deviceID
if version != nil {
req.coderDesktopVersion = version!
}
return req
}
}
Loading
Loading