File tree 3 files changed +32
-18
lines changed
elasticsearch-rails/lib/elasticsearch/rails
3 files changed +32
-18
lines changed Original file line number Diff line number Diff line change @@ -9,22 +9,28 @@ module Publishers
9
9
# @see http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html
10
10
#
11
11
module SearchRequest
12
- extend ActiveSupport ::Concern
13
12
14
- included do
15
- alias_method_chain :execute! , :instrumentation
16
- end
13
+ def self . included ( base )
14
+ base . class_eval do
15
+ alias_method :execute_without_instrumentation! , :execute!
16
+
17
+ def execute!
18
+ execute_with_instrumentation!
19
+ end
17
20
18
- # Wrap `Search#execute!` and perform instrumentation
19
- #
20
- def execute_with_instrumentation!
21
- ActiveSupport ::Notifications . instrument "search.elasticsearch" ,
22
- name : 'Search' ,
23
- klass : ( self . klass . is_a? ( Elasticsearch ::Model ::Proxy ::ClassMethodsProxy ) ? self . klass . target . to_s : self . klass . to_s ) ,
24
- search : self . definition do
25
- execute_without_instrumentation!
21
+ # Wrap `Search#execute!` and perform instrumentation
22
+ #
23
+ def execute_with_instrumentation!
24
+ ActiveSupport ::Notifications . instrument "search.elasticsearch" ,
25
+ name : 'Search' ,
26
+ klass : ( self . klass . is_a? ( Elasticsearch ::Model ::Proxy ::ClassMethodsProxy ) ? self . klass . target . to_s : self . klass . to_s ) ,
27
+ search : self . definition do
28
+ execute_without_instrumentation!
29
+ end
30
+ end
26
31
end
27
32
end
33
+
28
34
end
29
35
end
30
36
end
Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ class Railtie < ::Rails::Railtie
14
14
15
15
Elasticsearch ::Model ::Searching ::SearchRequest . class_eval do
16
16
include Elasticsearch ::Rails ::Instrumentation ::Publishers ::SearchRequest
17
- end
17
+ end if defined? ( Elasticsearch ::Model ::Searching ::SearchRequest )
18
+
19
+ Elasticsearch ::Persistence ::Model ::Find ::SearchRequest . class_eval do
20
+ include Elasticsearch ::Rails ::Instrumentation ::Publishers ::SearchRequest
21
+ end if defined? ( Elasticsearch ::Persistence ::Model ::Find ::SearchRequest )
18
22
19
23
ActiveSupport . on_load ( :action_controller ) do
20
24
include Elasticsearch ::Rails ::Instrumentation ::ControllerRuntime
Original file line number Diff line number Diff line change @@ -21,17 +21,21 @@ class Railtie < ::Rails::Railtie
21
21
require 'elasticsearch/rails/instrumentation/log_subscriber'
22
22
require 'elasticsearch/rails/instrumentation/controller_runtime'
23
23
24
- config . lograge . custom_options = lambda do |event |
25
- { es : event . payload [ :elasticsearch_runtime ] . to_f . round ( 2 ) }
26
- end
27
-
28
24
Elasticsearch ::Model ::Searching ::SearchRequest . class_eval do
29
25
include Elasticsearch ::Rails ::Instrumentation ::Publishers ::SearchRequest
30
- end
26
+ end if defined? ( Elasticsearch ::Model ::Searching ::SearchRequest )
27
+
28
+ Elasticsearch ::Persistence ::Model ::Find ::SearchRequest . class_eval do
29
+ include Elasticsearch ::Rails ::Instrumentation ::Publishers ::SearchRequest
30
+ end if defined? ( Elasticsearch ::Persistence ::Model ::Find ::SearchRequest )
31
31
32
32
ActiveSupport . on_load ( :action_controller ) do
33
33
include Elasticsearch ::Rails ::Instrumentation ::ControllerRuntime
34
34
end
35
+
36
+ config . lograge . custom_options = lambda do |event |
37
+ { es : event . payload [ :elasticsearch_runtime ] . to_f . round ( 2 ) }
38
+ end
35
39
end
36
40
end
37
41
You can’t perform that action at this time.
0 commit comments