-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We used to insert Faraday::Request::Instrumentation into our Faraday middleware stack to be able to instrument Stripe calls with StatsD. With Faraday being removed in version 5, this required some rework. This commit implements a simple callback system that can be used with any kind of instrumentation system.
- Loading branch information
Showing
4 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class Instrumentation | ||
def self.subscribe(name = rand, &block) | ||
subscribers[name] = block | ||
name | ||
end | ||
|
||
def self.unsubscribe(name) | ||
subscribers.delete(name) | ||
end | ||
|
||
def self.notify(*args) | ||
subscribers.each_value { |subscriber| subscriber.call(*args) } | ||
end | ||
|
||
def self.subscribers | ||
@subscribers ||= {} | ||
end | ||
private_class_method :subscribers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters