coinbase / coinbase/temporal-ruby

Workflow middlewares don't raise error on workflow execution failure

Open
#309 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
287
Forks
113
Avg merge
6d 11h
Merged PRs (30d)
1

Description

I'd like to emit the metric `workflow_failed` when the workflow execution fails (replicating metrics emitted by other [SDKs](https://docs.temporal.io/references/sdk-metrics#workflow_failed)). To achieve that, I registered a workflow middleware in my worker. In my middleware, I rescue errors and emit this metric.

The problem is that the workflow middleware doesn't raise an error when the workflow execution fails. AFAIK, there is no way of knowing if the workflow execution failed in the context of a workflow middleware. Conversely, in the activity middleware, errors are raised so it's possible to emit the metric `activity_exectuion_failed`. How can I emit the `workflow_failed` metrics when the workflow execution fails?

Setup:

`worker.rb`:
```
class Worker < Temporal::Worker
def self.start
worker = Temporal::Worker.new
# configure...
worker.add_workflow_middleware(MetricsWorkflowMiddleware)
worker.start
end
end
```

`metrics_workflow_middleware.rb`:
```
class MetricsWorkflowMiddleware
def call(metadata)
yield
Statsd.increment('workflow_completed')
rescue StandardError
Statsd.increment('workflow_failed')
raise
end
end
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.