Skip to content

Commit

Permalink
[instrumentation-fixes] make instrumentation occur (#27)
Browse files Browse the repository at this point in the history
only once per request and use naming convention suggested by Rails guides
  • Loading branch information
Valve authored Sep 24, 2018
1 parent ee33d67 commit f202f44
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Installation: `gem install solrb`
* [Dictionary boosting function](#dictionary-boosting-function)
* [Field list](#field-list)
* [Deleting documents](#deleting-documents)
* [Active Support instrumentation](#active-support-instrumentation)
* [Running specs](#running-specs)


Expand Down Expand Up @@ -287,6 +288,24 @@ Solr.delete_by_query('*:*')
Solr.delete_by_query('*:*', commit: true)
```

# Active Support instrumentation

This gem publishes events via [Active Support Instrumentation](https://edgeguides.rubyonrails.org/active_support_instrumentation.html)

To subscribe to solrb events, you can add this code to initializer:

```ruby
ActiveSupport::Notifications.subscribe('request.solrb') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
if Logger::INFO == Rails.logger.level
Rails.logger.info("Solrb #{event.duration.round(1)}ms")
elsif Logger::DEBUG == Rails.logger.level && Rails.env.development?
Pry::ColorPrinter.pp(event.payload)
end
end
```



# Running specs

Expand Down
2 changes: 1 addition & 1 deletion lib/solr/connection.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Solr
# low-level connection that can do network requests to Solr
class Connection
INSTRUMENT_KEY = 'solrb.request'.freeze
INSTRUMENT_KEY = 'request.solrb'.freeze

def initialize(url, faraday_options: Solr.configuration.faraday_options)
# Allow mock the connection for testing
Expand Down
5 changes: 1 addition & 4 deletions lib/solr/query/request/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def initialize(page:, page_size:, solr_params: {})

def run
raw_response = connection(PATH).post_as_json(request_params)
response = Solr::Response.from_raw_response(raw_response)
Solr.instrument(name: 'solrb.request_response_cycle',
data: { request: request_params, response: raw_response })
response
Solr::Response.from_raw_response(raw_response)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/solr/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Solr
VERSION = '0.1.4'.freeze
VERSION = '0.1.5'.freeze
end

0 comments on commit f202f44

Please sign in to comment.