Skip to content

Commit

Permalink
fixed ntp clock logging to only occur once (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b authored Jul 30, 2024
1 parent 644050a commit 297934e
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions Sources/apm-agent-ios/Utils/NTPClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@ import OpenTelemetrySdk
import Kronos
import os.log

class NTPClock: OpenTelemetrySdk.Clock {
var now: Date {
if let date = Kronos.Clock.now {
os_log("Using Kronos Clock.now as fallback.")
return date
}

os_log("Kronos Clock.now unavailable. using system clock as fallback.")
return Date()
class SuccessLogOnce {
static let run: Void = {
let logger = OSLog(subsystem: "co.elastic.ElasticApm", category: "NTPClock")
os_log("NTPClock is now being used for signal timestamps.", log: logger, type: .info)
return ()
}()
}

class FailureLogOnce {
static let run: Void = {
let logger = OSLog(subsystem: "co.elastic.ElasticApm", category: "NTPClock")
os_log("NTPClock is unavailable. Using system clock as fallback for signal timestamps.", log: logger, type: .info)
return()
}()
}

class NTPClock: OpenTelemetrySdk.Clock {
var now: Date {
if let date = Kronos.Clock.now {
SuccessLogOnce.run
return date
}
FailureLogOnce.run
return Date()
}
}

0 comments on commit 297934e

Please sign in to comment.