From 38d8148602c096cf8f19c612bcaa1e8c9c33ed46 Mon Sep 17 00:00:00 2001 From: Hannah Ramadan Date: Tue, 17 Dec 2024 12:36:29 -0800 Subject: [PATCH] Refactor --- .../agent/configuration/default_source.rb | 2 +- .../aws_sdk_kinesis/instrumentation.rb | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/new_relic/agent/configuration/default_source.rb b/lib/new_relic/agent/configuration/default_source.rb index 399de4020c..d5163432f4 100644 --- a/lib/new_relic/agent/configuration/default_source.rb +++ b/lib/new_relic/agent/configuration/default_source.rb @@ -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', diff --git a/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb b/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb index 52412ded2f..0cc26e9737 100644 --- a/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb @@ -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, @@ -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 @@ -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