Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Dec 17, 2024
1 parent e5914c2 commit 38d8148
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/new_relic/agent/configuration/default_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ def self.notify
:type => String,
:dynamic_name => true,
:allowed_from_server => false,
:description => 'Controls auto-instrumentation of the aws_sdk_kinesis library at start-up. May be one of `auto`, `prepend`, `chain`, `disabled`.'
:description => 'Controls auto-instrumentation of the aws-sdk-kinesis library at start-up. May be one of `auto`, `prepend`, `chain`, `disabled`.'
},
:'instrumentation.ruby_kafka' => {
:default => 'auto',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def instrument_method_with_new_relic(method_name, *args)

NewRelic::Agent.record_instrumentation_invocation(KINESIS)
params = args[0]
arn = get_arn(params) if params

if BROKER_METHODS.include?(method_name)
stream_name = get_stream_name(params)
stream_name = get_stream_name(params, arn)
segment = NewRelic::Agent::Tracer.start_message_broker_segment(
action: method_name == 'get_records' ? :consume : :produce,
library: KINESIS,
Expand All @@ -48,7 +49,6 @@ def instrument_method_with_new_relic(method_name, *args)
segment = NewRelic::Agent::Tracer.start_segment(name: get_segment_name(method_name, params))
end

arn = get_arn(params) if params
segment&.add_agent_attribute('cloud.resource_id', arn) if arn

begin
Expand All @@ -67,16 +67,10 @@ def get_segment_name(method_name, params)
NewRelic::Agent.logger.warn("Failed to create segment name: #{e}")
end

def get_stream_name(params)
return params[:stream_name] if params&.dig(:stream_name)

arn = get_arn(params)

return arn.split('/').last if arn
def get_stream_name(params, arn)
params[:stream_name] || arn.split('/').last || 'unknown'
rescue => e
NewRelic::Agent.logger.warn("Failed to get stream name: #{e}")

'unknown'
end

def nr_account_id
Expand Down

0 comments on commit 38d8148

Please sign in to comment.