Skip to content

Commit

Permalink
Add transaction_ignore_urls config (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikkel Malmberg authored Aug 10, 2020
1 parent b79d2d6 commit e20f48f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ endif::[]
[[release-notes-3.x]]
=== Ruby Agent version 3.x
[float]
[[unreleased]]
==== Unreleased
[float]
===== Added
- Config option `transaction_ignore_urls` to replace `ignore_url_patterns` {pull}844[#844]
[[release-notes-3.9.0]]
==== 3.9.0 (2020-08-04)
Expand Down
8 changes: 8 additions & 0 deletions lib/elastic_apm/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Config
option :source_lines_span_library_frames, type: :int, default: 0
option :span_frames_min_duration, type: :float, default: '5ms', converter: Duration.new(default_unit: 'ms')
option :stack_trace_limit, type: :int, default: 999_999
option :transaction_ignore_urls, type: :list, default: [], converter: WildcardPatternList.new
option :transaction_max_spans, type: :int, default: 500
option :transaction_sample_rate, type: :float, default: 1.0
option :use_elastic_traceparent_header, type: :bool, default: true
Expand Down Expand Up @@ -234,6 +235,13 @@ def default_tags=(value)
self.default_labels = value
end

def ignore_url_patterns=(value)
warn '[DEPRECATED] The option ignore_url_patterns is being removed. ' \
'Consider using transaction_ignore_urls instead.'

set(:ignore_url_patterns, value)
end

def custom_key_filters=(value)
unless value == self.class.schema[:custom_key_filters][:default]
warn '[DEPRECATED] The option custom_key_filters is being removed. ' \
Expand Down
10 changes: 8 additions & 2 deletions lib/elastic_apm/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ def http_result(status)
end

def path_ignored?(env)
config.ignore_url_patterns.any? do |r|
env['PATH_INFO'].match r
return true if config.ignore_url_patterns.any? do |r|
r.match(env['PATH_INFO'])
end

return true if config.transaction_ignore_urls.any? do |r|
r.match(env['PATH_INFO'])
end

false
end

def start_transaction(env)
Expand Down
11 changes: 11 additions & 0 deletions spec/elastic_apm/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ module ElasticAPM
end
end

describe 'ignore_url_patterns' do
subject { Config.new }

it 'logs a warning and sets' do
expect(subject).to receive(:warn).with(/DEPRECATED/)
subject.ignore_url_patterns = ['/ping']

expect(subject.ignore_url_patterns).to match([%r{/ping}])
end
end

describe 'use_legacy_sql_parser' do
subject { Config.new }

Expand Down
17 changes: 15 additions & 2 deletions spec/elastic_apm/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ module ElasticAPM
end

it 'ignores url patterns' do
with_agent ignore_url_patterns: %w[/ping] do
with_agent transaction_ignore_urls: %w[/status/*/ping] do
expect(ElasticAPM).to_not receive(:start_transaction)

app = Middleware.new(->(_) { [200, {}, ['ok']] })
status, = app.call(Rack::MockRequest.env_for('/ping'))
status, = app.call(Rack::MockRequest.env_for('/status/something/ping'))

expect(status).to be 200
end
Expand Down Expand Up @@ -198,5 +198,18 @@ class MiddlewareTestError < StandardError; end
end
end
end

describe 'deprecated' do
it 'ignores url patterns' do
with_agent ignore_url_patterns: %w[/ping] do
expect(ElasticAPM).to_not receive(:start_transaction)

app = Middleware.new(->(_) { [200, {}, ['ok']] })
status, = app.call(Rack::MockRequest.env_for('/ping'))

expect(status).to be 200
end
end
end
end
end

0 comments on commit e20f48f

Please sign in to comment.