-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
Current metrics api only supports setting dimensions on metric creation. I think to fully leverage dimensions and express in code that certain set of metrics report into a same metric label, we need to allow setting dimensions on record as well as in constructor. E.g. imagine we're trying to instrument an http server. With custom dimensions we could do something like this:
let requestDurationTimer = Timer(label: "request_duration", dimensions: [("instance": "myInstance")])
func handle(request: Request) {
var statusCodeClass: String = "2XX"
let startTime = DispatchTime.now()
defer {
requestDurationTimer.recordNanoseconds(since: startTime,
dimensions: [("statusCode": statusCodeClass,
"uri": request.uri)])
}
do {
try handleRequest(request)
} catch let error as ServerError {
// recovery routine
statusCodeClass = "5XX"
} catch let error as UserError {
statusCodeClass = "4XX"
}
}We won't have to create a separate requestDurationTimer for each "uri" as well as a separate timer for each uri/error class combination. This also applies to more complex state machines instrumentation when we may want to express certain event belongs to a certain state/command.
Metadata
Metadata
Assignees
Labels
No labels