Skip to content

Workflow middlewares don't raise error on workflow execution failure #309

Description

@etiennelalumiere

I'd like to emit the metric workflow_failed when the workflow execution fails (replicating metrics emitted by other SDKs). 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions