Skip to content

Commit

Permalink
feat: support an ignore option #351
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilias Tsangaris committed Jan 5, 2022
1 parent c469ebc commit 0f07158
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ruby/lib/readme/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def process_response(response:, env:, start_time:, end_time:)
Readme::Metrics.logger.warn "Request or response body MIME type isn't supported for filtering. Omitting request from ReadMe API logging"
else
payload = Payload.new(har, user_info, development: @development)
@@request_queue.push(payload.to_json)
@@request_queue.push(payload.to_json) if !payload.ignore
end
end

Expand Down
5 changes: 5 additions & 0 deletions packages/ruby/lib/readme/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

module Readme
class Payload
attr_reader :ignore

def initialize(har, info, development:)
@har = har
# swap api_key for id
info[:id] = info.delete :api_key unless info[:api_key].nil?
# pull log_id and ignore fields out of info to construct a user_info hash that can be assigned to the group key
@log_id = info[:log_id]
@ignore = info[:ignore]
info.delete :log_id
info.delete :ignore
@user_info = info
@development = development
@uuid = UUID.new
Expand Down
19 changes: 18 additions & 1 deletion packages/ruby/spec/readme/metrics_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require "readme/metrics"
require "rack/test"
require "webmock/rspec"
require "uuid"

RSpec.describe Readme::Metrics do
include Rack::Test::Methods

before do
@uuid = UUID.new
end

before :each do
WebMock.reset_executed_requests!
end
Expand Down Expand Up @@ -429,6 +434,16 @@ def app
.with { |request| validate_json("readmeMetrics", request.body) }
}.to raise_error
end

it "can ignore sending logs" do
def app
json_app_with_middleware({}, {ignore: true})
end

post "/api/foo"

expect(WebMock).not_to have_requested(:post, Readme::Metrics::ENDPOINT)
end
end

def json_app_with_middleware(option_overrides = {}, group_overrides = {})
Expand All @@ -449,7 +464,9 @@ def app_with_middleware(app, option_overrides = {}, group_overrides = {})
group = {
id: env["CURRENT_USER"].id,
label: env["CURRENT_USER"].name,
email: env["CURRENT_USER"].email
email: env["CURRENT_USER"].email,
log_id: @uuid.generate,
ignore: false
}.merge(group_overrides)
group.delete :id unless group[:api_key].nil?
group
Expand Down

0 comments on commit 0f07158

Please sign in to comment.