@@ -10,6 +10,7 @@ import (
10
10
"github.com/benbjohnson/clock"
11
11
"github.com/cschleiden/go-workflows/backend"
12
12
"github.com/cschleiden/go-workflows/internal/core"
13
+ "github.com/cschleiden/go-workflows/internal/history"
13
14
"github.com/cschleiden/go-workflows/internal/metrickeys"
14
15
"github.com/cschleiden/go-workflows/internal/task"
15
16
"github.com/cschleiden/go-workflows/internal/workflow"
@@ -133,11 +134,25 @@ func (ww *WorkflowWorker) runDispatcher() {
133
134
134
135
func (ww * WorkflowWorker ) handle (ctx context.Context , t * task.Workflow ) {
135
136
// Record how long this task was in the queue
136
- scheduledAt := t .NewEvents [0 ].Timestamp // Use the timestamp of the first event as the schedule time
137
+ firstEvent := t .NewEvents [0 ]
138
+ var scheduledAt time.Time
139
+ if firstEvent .Type == history .EventType_TimerFired {
140
+ timerFiredAttributes := firstEvent .Attributes .(* history.TimerFiredAttributes )
141
+ scheduledAt = timerFiredAttributes .At // Use the timestamp of the timer fired event as the schedule time
142
+ } else {
143
+ scheduledAt = firstEvent .Timestamp // Use the timestamp of the first event as the schedule time
144
+ }
145
+
146
+ eventName := fmt .Sprint (firstEvent .Type )
147
+
137
148
timeInQueue := time .Since (scheduledAt )
138
- ww .backend .Metrics ().Distribution (metrickeys .WorkflowTaskDelay , metrics.Tags {}, float64 (timeInQueue / time .Millisecond ))
149
+ ww .backend .Metrics ().Distribution (metrickeys .WorkflowTaskDelay , metrics.Tags {
150
+ metrickeys .EventName : eventName ,
151
+ }, float64 (timeInQueue / time .Millisecond ))
139
152
140
- timer := metrics .Timer (ww .backend .Metrics (), metrickeys .WorkflowTaskProcessed , metrics.Tags {})
153
+ timer := metrics .Timer (ww .backend .Metrics (), metrickeys .WorkflowTaskProcessed , metrics.Tags {
154
+ metrickeys .EventName : eventName ,
155
+ })
141
156
142
157
result , err := ww .handleTask (ctx , t )
143
158
if err != nil {
0 commit comments