Skip to content

Commit

Permalink
add on_exception callback for periodic_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
senid231 committed Nov 28, 2023
1 parent f75432f commit ed137d0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/prometheus_exporter/ext/instrumentation/periodic_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def start(frequency: 30, client: PrometheusExporter::Client.default, **)
rescue StandardError => e
client.logger.error("#{klass} Prometheus Exporter Failed To Collect Stats")
client.logger.error("#{e.class} #{e.backtrace&.join("\n")}")
@on_exception&.call(e) if defined?(@on_exception)
ensure
sleep frequency
end
Expand All @@ -43,6 +44,12 @@ def stop
end
@thread = nil
end

# Adds handler that will be called when exception is raised in the thread.
# @yieldparam exception [Exception]
def on_exception(&block)
@on_exception = block
end
end
end
end

0 comments on commit ed137d0

Please sign in to comment.