Skip to content

Commit dca8020

Browse files
authored
Merge pull request #855 from newrelic/skip_span_event_when_transaction_ignored
Do not record span events when transaction is ignored
2 parents d589560 + 16e42ef commit dca8020

File tree

15 files changed

+148
-4
lines changed

15 files changed

+148
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
Template rendering using [Tilt](https://github.com/rtomayko/tilt) is now instrumented. See [PR #847](https://github.com/newrelic/newrelic-ruby-agent/pull/847) for details.
88

9+
* **Bugfix: Span Events recorded when using newrelic_ignore**
10+
11+
Previously, the agent was incorrectly recording span events only on transactions that should be ignored. This fix will prevent any span events from being created for transactions using newrelic_ignore, or ignored through the `rules.ignore_url_regexes` configuration option.
12+
913
* **Bugfix: Scrub non-unicode characters from DecoratingLogger**
1014

1115
To prevent `JSON::GeneratorErrors`, the DecoratingLogger replaces non-unicode characters with the replacement character: �. Thank you Jonathan del Strother (@jdelStrother) for bringing this to our attention!

infinite_tracing/lib/infinite_tracing/agent_integrations/datastore_segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Agent
88
class Transaction
99
class DatastoreSegment
1010
def record_span_event
11+
# don't record a span event if the transaction is ignored
12+
return if transaction.ignore?
13+
1114
tracer = ::NewRelic::Agent.agent.infinite_tracer
1215
tracer << Proc.new { SpanEventPrimitive.for_datastore_segment self }
1316
end

infinite_tracing/lib/infinite_tracing/agent_integrations/external_request_segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Agent
88
class Transaction
99
class ExternalRequestSegment
1010
def record_span_event
11+
# don't record a span event if the transaction is ignored
12+
return if transaction.ignore?
13+
1114
tracer = ::NewRelic::Agent.agent.infinite_tracer
1215
tracer << Proc.new { SpanEventPrimitive.for_external_request_segment self }
1316
end

infinite_tracing/lib/infinite_tracing/agent_integrations/segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def segment_complete
1313
end
1414

1515
def record_span_event
16+
# don't record a span event if the transaction is ignored
17+
return if transaction.ignore?
18+
1619
tracer = ::NewRelic::Agent.agent.infinite_tracer
1720
tracer << Proc.new { SpanEventPrimitive.for_segment self }
1821
end

infinite_tracing/test/infinite_tracing/agent_integrations/datastore_segment_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ def test_non_sampled_segment_does_record_span_event
9696
assert_equal 2, span_events.size
9797
end
9898

99+
def test_ignored_transaction_does_not_record_span_event
100+
span_events = generate_and_stream_segments do
101+
in_web_transaction('wat') do |txn|
102+
txn.stubs(:ignore?).returns(true)
103+
104+
segment = Tracer.start_datastore_segment(
105+
product: "SQLite",
106+
operation: "select",
107+
port_path_or_id: 1337807
108+
)
109+
110+
segment.start
111+
advance_process_time(1.0)
112+
segment.finish
113+
end
114+
end
115+
116+
assert_equal 0, span_events.size
117+
end
99118
end
100119
end
101120
end

infinite_tracing/test/infinite_tracing/agent_integrations/external_request_segment_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ def test_non_sampled_segment_does_record_span_event
8686
assert_equal 2, span_events.size
8787
end
8888

89+
def test_ignored_transaction_does_not_record_span_event
90+
span_events = generate_and_stream_segments do
91+
in_transaction('wat') do |txn|
92+
txn.stubs(:ignore?).returns(true)
93+
94+
segment = Transaction::ExternalRequestSegment.new \
95+
"Typhoeus",
96+
"http://remotehost.com/blogs/index",
97+
"GET"
98+
99+
txn.add_segment segment
100+
segment.start
101+
advance_process_time(1.0)
102+
segment.finish
103+
end
104+
end
105+
106+
assert_equal 0, span_events.size
107+
end
89108
end
90109
end
91110
end

infinite_tracing/test/infinite_tracing/agent_integrations/segment_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ def test_non_sampled_segment_does_record_span_event
7272
assert_equal 2, span_events.size
7373
end
7474

75+
def test_ignored_transaction_does_not_record_span_event
76+
span_events = generate_and_stream_segments do
77+
in_transaction('wat') do |txn|
78+
txn.stubs(:ignore?).returns(true)
79+
80+
segment = Transaction::Segment.new 'Ummm'
81+
txn.add_segment segment
82+
segment.start
83+
advance_process_time(1.0)
84+
segment.finish
85+
end
86+
end
87+
88+
assert_equal 0, span_events.size
89+
end
90+
7591
def test_streams_multiple_segments
7692
total_spans = 5
7793
segments = []

lib/new_relic/agent/configuration/default_source.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,10 +1814,7 @@ def self.enforce_fallback(allowed_values: nil, fallback: nil)
18141814
:type => Array,
18151815
:allowed_from_server => true,
18161816
:transform => DefaultSource.method(:convert_to_regexp_list),
1817-
:description => 'Define transactions you want the agent to ignore, by specifying a list of patterns matching the URI you want to ignore.' \
1818-
'*Note:* This will only ignore transaction events, not spans or traces from the same transation. See documentation on ' \
1819-
'(Ignoring Specific Transactions)[https://docs.newrelic.com/docs/agents/ruby-agent/api-guides/ignoring-specific-transactions/#config-ignoring] ' \
1820-
'for more details.'
1817+
:description => 'Define transactions you want the agent to ignore, by specifying a list of patterns matching the URI you want to ignore.'
18211818
},
18221819
:'synthetics.traces_limit' => {
18231820
:default => 20,

lib/new_relic/agent/transaction/datastore_segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def record_sql?
138138
end
139139

140140
def record_span_event
141+
# don't record a span event if the transaction is ignored
142+
return if transaction.ignore?
143+
141144
aggregator = ::NewRelic::Agent.agent.span_event_aggregator
142145
priority = transaction.priority
143146

lib/new_relic/agent/transaction/external_request_segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ def obfuscator
250250
end
251251

252252
def record_span_event
253+
# don't record a span event if the transaction is ignored
254+
return if transaction.ignore?
255+
253256
aggregator = ::NewRelic::Agent.agent.span_event_aggregator
254257
priority = transaction.priority
255258
aggregator.record(priority: priority) do

lib/new_relic/agent/transaction/segment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def segment_complete
7979
end
8080

8181
def record_span_event
82+
# don't record a span event if the transaction is ignored
83+
return if transaction.ignore?
84+
8285
aggregator = ::NewRelic::Agent.agent.span_event_aggregator
8386
priority = transaction.priority
8487

test/multiverse/suites/rails/ignore_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def action_to_ignore
1717
def action_to_ignore_apdex
1818
render body: "This too"
1919
end
20+
21+
def action_not_ignored
22+
render body: "Not this!"
23+
end
2024
end
2125

2226
class ParentController < ApplicationController
@@ -77,4 +81,20 @@ def test_apdex_ignored_if_ignored_in_parent_class
7781

7882
assert_metrics_not_recorded("Apdex")
7983
end
84+
85+
def test_ignored_transaction_does_not_record_span_events
86+
get '/ignored/action_to_ignore'
87+
88+
last_span_events = NewRelic::Agent.agent.span_event_aggregator.harvest![1]
89+
assert_empty last_span_events
90+
end
91+
92+
def test_ignored_by_ignore_url_regexes_does_not_record_span_events
93+
with_config(:rules => { :ignore_url_regexes => ['/ignored/action_not_ignored'] }) do
94+
get '/ignored/action_not_ignored'
95+
96+
last_span_events = NewRelic::Agent.agent.span_event_aggregator.harvest![1]
97+
assert_empty last_span_events
98+
end
99+
end
80100
end

test/new_relic/agent/transaction/datastore_segment_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,25 @@ def test_non_sampled_segment_does_not_record_span_event
210210
assert_empty last_span_events
211211
end
212212

213+
def test_ignored_transaction_does_not_record_span_event
214+
in_web_transaction('wat') do |txn|
215+
txn.stubs(:ignore?).returns(true)
216+
217+
segment = Tracer.start_datastore_segment(
218+
product: "SQLite",
219+
operation: "select",
220+
port_path_or_id: 1337807
221+
)
222+
223+
segment.start
224+
advance_process_time 1.0
225+
segment.finish
226+
end
227+
228+
last_span_events = NewRelic::Agent.agent.span_event_aggregator.harvest![1]
229+
assert_empty last_span_events
230+
end
231+
213232
def test_sampled_segment_records_span_event
214233
trace_id = nil
215234
txn_guid = nil

test/new_relic/agent/transaction/external_request_segment_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,23 @@ def test_non_sampled_segment_does_not_record_span_event
877877
assert_empty last_span_events
878878
end
879879

880+
def test_non_sampled_segment_does_not_record_span_event
881+
in_transaction('wat') do |txn|
882+
txn.stubs(:ignore?).returns(true)
883+
884+
segment = ExternalRequestSegment.new "Typhoeus",
885+
"http://remotehost.com/blogs/index",
886+
"GET"
887+
txn.add_segment segment
888+
segment.start
889+
advance_process_time 1.0
890+
segment.finish
891+
end
892+
893+
last_span_events = NewRelic::Agent.agent.span_event_aggregator.harvest![1]
894+
assert_empty last_span_events
895+
end
896+
880897
def test_span_event_truncates_long_value
881898
with_config(distributed_tracing_config) do
882899
in_transaction('wat') do |txn|

test/new_relic/agent/transaction/segment_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ def test_non_sampled_segment_does_not_record_span_event
213213
assert_empty last_span_events
214214
end
215215

216+
def test_ignored_transaction_does_not_record_span_events
217+
in_transaction('wat') do |txn|
218+
txn.stubs(:ignore?).returns(true)
219+
220+
segment = Segment.new 'Ummm'
221+
txn.add_segment segment
222+
segment.start
223+
advance_process_time 1.0
224+
segment.finish
225+
end
226+
227+
last_span_events = NewRelic::Agent.agent.span_event_aggregator.harvest![1]
228+
assert_empty last_span_events
229+
end
230+
216231
def test_sampled_segment_records_span_event
217232
trace_id = nil
218233
txn_guid = nil

0 commit comments

Comments
 (0)