Skip to content

Commit 101ec13

Browse files
authored
Merge pull request coinbase#133 from christopherb-stripe/christopherb/add-workflow-tag-metric
Add workflow tag to metrics emitted from the activity task processor
2 parents 30342ae + 0d7e637 commit 101ec13

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/temporal/activity/task_processor.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def process
2626
start_time = Time.now
2727

2828
Temporal.logger.debug("Processing Activity task", metadata.to_h)
29-
Temporal.metrics.timing('activity_task.queue_time', queue_time_ms, activity: activity_name, namespace: namespace)
29+
Temporal.metrics.timing('activity_task.queue_time', queue_time_ms, activity: activity_name, namespace: namespace, workflow: metadata.workflow_name)
3030

3131
context = Activity::Context.new(connection, metadata)
3232

@@ -46,7 +46,7 @@ def process
4646
respond_failed(error)
4747
ensure
4848
time_diff_ms = ((Time.now - start_time) * 1000).round
49-
Temporal.metrics.timing('activity_task.latency', time_diff_ms, activity: activity_name, namespace: namespace)
49+
Temporal.metrics.timing('activity_task.latency', time_diff_ms, activity: activity_name, namespace: namespace, workflow: metadata.workflow_name)
5050
Temporal.logger.debug("Activity task processed", metadata.to_h.merge(execution_time: time_diff_ms))
5151
end
5252

lib/temporal/workflow/poller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def poll_loop
6363

6464
time_diff_ms = ((Time.now - last_poll_time) * 1000).round
6565
Temporal.metrics.timing('workflow_poller.time_since_last_poll', time_diff_ms, metrics_tags)
66-
Temporal.logger.debug("Polling Worklow task queue", { namespace: namespace, task_queue: task_queue })
66+
Temporal.logger.debug("Polling workflow task queue", { namespace: namespace, task_queue: task_queue })
6767

6868
task = poll_for_task
6969
last_poll_time = Time.now

spec/unit/lib/temporal/activity/task_processor_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
end
1717
let(:metadata) { Temporal::Metadata.generate_activity_metadata(task, namespace) }
18+
let(:workflow_name) { task.workflow_type.name }
1819
let(:activity_name) { 'TestActivity' }
1920
let(:connection) { instance_double('Temporal::Connection::GRPC') }
2021
let(:middleware_chain) { Temporal::Middleware::Chain.new }
@@ -125,15 +126,15 @@
125126

126127
expect(Temporal.metrics)
127128
.to have_received(:timing)
128-
.with('activity_task.queue_time', an_instance_of(Integer), activity: activity_name, namespace: namespace)
129+
.with('activity_task.queue_time', an_instance_of(Integer), activity: activity_name, namespace: namespace, workflow: workflow_name)
129130
end
130131

131132
it 'sends latency metric' do
132133
subject.process
133134

134135
expect(Temporal.metrics)
135136
.to have_received(:timing)
136-
.with('activity_task.latency', an_instance_of(Integer), activity: activity_name, namespace: namespace)
137+
.with('activity_task.latency', an_instance_of(Integer), activity: activity_name, namespace: namespace, workflow: workflow_name)
137138
end
138139

139140
context 'with async activity' do
@@ -203,15 +204,15 @@
203204

204205
expect(Temporal.metrics)
205206
.to have_received(:timing)
206-
.with('activity_task.queue_time', an_instance_of(Integer), activity: activity_name, namespace: namespace)
207+
.with('activity_task.queue_time', an_instance_of(Integer), activity: activity_name, namespace: namespace, workflow: workflow_name)
207208
end
208209

209210
it 'sends latency metric' do
210211
subject.process
211212

212213
expect(Temporal.metrics)
213214
.to have_received(:timing)
214-
.with('activity_task.latency', an_instance_of(Integer), activity: activity_name, namespace: namespace)
215+
.with('activity_task.latency', an_instance_of(Integer), activity: activity_name, namespace: namespace, workflow: workflow_name)
215216
end
216217

217218
context 'with ScriptError exception' do

0 commit comments

Comments
 (0)