-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathmetrics.go
38 lines (32 loc) · 1.05 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package metrics
import (
"time"
"go.temporal.io/sdk/client"
)
const (
activityLatency = "activity_latency"
scheduleToStartLatency = "schedule_to_start_latency"
activityStartedCount = "activity_started"
activityFailedCount = "activity_failed"
activitySuccessCount = "activity_succeeded"
)
func recordActivityStart(
handler client.MetricsHandler,
activityType string,
scheduledTimeNanos int64,
) client.MetricsHandler {
handler = handler.WithTags(map[string]string{"operation": activityType})
scheduleToStartDuration := time.Duration(time.Now().UnixNano() - scheduledTimeNanos)
handler.Timer(scheduleToStartLatency).Record(scheduleToStartDuration)
handler.Counter(activityStartedCount).Inc(1)
return handler
}
// recordActivityEnd emits metrics at the end of an activity function
func recordActivityEnd(handler client.MetricsHandler, startTime time.Time, err error) {
handler.Timer(activityLatency).Record(time.Since(startTime))
if err != nil {
handler.Counter(activityFailedCount).Inc(1)
return
}
handler.Counter(activitySuccessCount).Inc(1)
}