@@ -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,9 +134,19 @@ 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
+
137
146
timeInQueue := time .Since (scheduledAt )
138
- ww .backend .Metrics ().Distribution (metrickeys .WorkflowTaskDelay , metrics.Tags {}, float64 (timeInQueue / time .Millisecond ))
147
+ ww .backend .Metrics ().Distribution (metrickeys .WorkflowTaskDelay , metrics.Tags {
148
+ metrickeys .EventName : fmt .Sprint (t .NewEvents [0 ].Type ),
149
+ }, float64 (timeInQueue / time .Millisecond ))
139
150
140
151
timer := metrics .Timer (ww .backend .Metrics (), metrickeys .WorkflowTaskProcessed , metrics.Tags {})
141
152
0 commit comments