withIntervalSignpost(_:id:_:around:)
Measures the execution of a closure and attaches the specified message.
Declaration
func withIntervalSignpost<T>(_ name: StaticString, id: OSSignpostID = .exclusive, _ message: SignpostMetadata, around task: () throws -> T) rethrows -> TParameters
- name:
The signpost’s name.
- id:
The signpost’s ID. The default value is Exclusive.
- message:
The interpolated string that the signposter attaches to the signpost. Each of the message’s interpolations can specify individual formatting and privacy options. For more information, see Message Argument Formatters.
- task:
The closure around which to create the signposted interval.
Discussion
The signposter uses a signpost ID to pair the beginning and the end of a signposted interval, which is necessary because multiple intervals with the same configuration and scope can be in-flight simultaneously. If only one interval with a specific configuration can execute at any particular time, pass exclusive as the id parameter. Otherwise, use the makeSignpostID() and makeSignpostID(from:) methods to generate a signpost identifier, as the following example shows:
let accountNumber = "12345678"
// Create a signposter using the default subsystem.
let signposter = OSSignposter()
// Generate a signpost ID to associate with the signpost.
let signpostID = signposter.makeSignpostID()
// Signpost the interval of a closure that encapsulates
// one or more related tasks, and attach a message that
// securely interpolates sensitive data.
signposter.withIntervalSignpost("Account Reconciliation", id: signpostID,
"Account: \(accountNumber, privacy: .sensitive(mask: .hash))") {
// Perform the related tasks.
processTransactions()
updateBalance()
}