-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #700 from DataDog/refactor/grape_replace_pin_with_…
…config Deprecate Grape pin in favor of configuration API
- Loading branch information
Showing
7 changed files
with
263 additions
and
169 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
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,73 @@ | ||
module Datadog | ||
module Contrib | ||
module Grape | ||
# Instrumentation for Grape::Endpoint | ||
module Instrumentation | ||
def self.included(base) | ||
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') | ||
base.class_eval do | ||
# Class methods | ||
singleton_class.send(:include, ClassMethodsCompatibility) | ||
singleton_class.send(:include, ClassMethods) | ||
|
||
# Instance methods | ||
include InstanceMethodsCompatibility | ||
include InstanceMethods | ||
end | ||
else | ||
base.singleton_class.send(:prepend, ClassMethods) | ||
base.send(:prepend, InstanceMethods) | ||
end | ||
end | ||
|
||
# Compatibility shim for Rubies not supporting `.prepend` | ||
module ClassMethodsCompatibility | ||
def self.included(base) | ||
base.class_eval do | ||
alias_method :generate_api_method_without_datadog, :generate_api_method | ||
remove_method :generate_api_method | ||
end | ||
end | ||
|
||
def generate_api_method(*args, &block) | ||
generate_api_method_without_datadog(*args, &block) | ||
end | ||
end | ||
|
||
# Compatibility shim for Rubies not supporting `.prepend` | ||
module InstanceMethodsCompatibility | ||
def self.included(base) | ||
base.class_eval do | ||
alias_method :run_without_datadog, :run | ||
remove_method :run | ||
end | ||
end | ||
|
||
def run(*args, &block) | ||
run_without_datadog(*args, &block) | ||
end | ||
end | ||
|
||
# ClassMethods - implementing instrumentation | ||
module ClassMethods | ||
def generate_api_method(*params, &block) | ||
method_api = super | ||
|
||
proc do |*args| | ||
::ActiveSupport::Notifications.instrument('endpoint_render.grape.start_render') | ||
method_api.call(*args) | ||
end | ||
end | ||
end | ||
|
||
# InstanceMethods - implementing instrumentation | ||
module InstanceMethods | ||
def run(*args) | ||
::ActiveSupport::Notifications.instrument('endpoint_run.grape.start_process') | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.