Telemetry: tag relay fetches with X-Client (app/widget) — app via RelayFuelProvider, widget focused/fuel-only fetches + diag beacon; Siri untouched (cached-only). Purely observational for relay admin /stats.
This commit is contained in:
@@ -71,6 +71,19 @@ struct RelayFuelProvider: FuelPriceProviding {
|
||||
/// dataset update time). Written by fetchStations, read by the view.
|
||||
static var latestMeta: RelayMeta?
|
||||
|
||||
/// Admin telemetry: the relay tags inbound connections by client kind
|
||||
/// (app vs widget) so the developer can monitor the poll model. Siri
|
||||
/// never fetches (cached-data-first). Purely observational — the relay
|
||||
/// ignores the header for responses.
|
||||
static let clientTagHeader = "X-Client"
|
||||
|
||||
static func relayRequest(_ url: URL, client: String, timeout: TimeInterval = 30) -> URLRequest {
|
||||
var request = URLRequest(url: url)
|
||||
request.timeoutInterval = timeout
|
||||
request.setValue(client, forHTTPHeaderField: clientTagHeader)
|
||||
return request
|
||||
}
|
||||
|
||||
func fetchStations(near lat: Double?, lng: Double?, fuel: FuelType, radiusKM: Double?) async throws -> [FuelStation] {
|
||||
var components = URLComponents(url: baseURL.appendingPathComponent("api/v1/stations"), resolvingAgainstBaseURL: false)!
|
||||
var query: [URLQueryItem] = [URLQueryItem(name: "fuel", value: fuel.rawValue)]
|
||||
@@ -89,7 +102,8 @@ struct RelayFuelProvider: FuelPriceProviding {
|
||||
}
|
||||
components.queryItems = query
|
||||
|
||||
let (data, response) = try await URLSession.shared.data(from: components.url!)
|
||||
let request = RelayFuelProvider.relayRequest(components.url!, client: "app")
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
guard let http = response as? HTTPURLResponse, http.statusCode == 200 else {
|
||||
throw FuelProviderError.relayUnavailable
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user