Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
etiennelalumiere opened this issue Jul 26, 2024 · 0 comments

Comments

@etiennelalumiere
Copy link

etiennelalumiere commented Jul 26, 2024

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
@etiennelalumiere etiennelalumiere changed the title Workflow Middleware doesn't raise error on workflow execution failure Workflow middlewares don't raise error on workflow execution failure Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant