From 55b8b0b341d132109e9180534be6c4b5b06b8c4c Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Wed, 25 Oct 2023 11:36:16 -0400 Subject: [PATCH] NH-65373: include the ENV var for SW_APM_TRANSACTION_NAME --- .../opentelemetry/solarwinds_processor.rb | 3 +++ test/opentelemetry/solarwinds_processor_test.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb b/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb index 1e9d6011..9273b6ea 100644 --- a/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +++ b/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb @@ -148,12 +148,15 @@ def get_http_status_code(span) end # Get trans_name and url_tran of this span instance. + # Predecessor order: custom SDK > env var SW_APM_TRANSACTION_NAME > automatic naming def calculate_transaction_names(span) trace_span_id = "#{span.context.hex_trace_id}-#{span.context.hex_span_id}" trans_name = @txn_manager.get(trace_span_id) if trans_name SolarWindsAPM.logger.debug {"[#{self.class}/#{__method__}] found trans name from txn_manager: #{trans_name} by #{trace_span_id}"} @txn_manager.del(trace_span_id) + elsif ENV.has_key?('SW_APM_TRANSACTION_NAME') && ENV['SW_APM_TRANSACTION_NAME'] != '' + trans_name = ENV['SW_APM_TRANSACTION_NAME'] else trans_name = span.attributes[HTTP_ROUTE] || nil trans_name = span.name if span.name && (trans_name.nil? || trans_name.empty?) diff --git a/test/opentelemetry/solarwinds_processor_test.rb b/test/opentelemetry/solarwinds_processor_test.rb index 2910fbe5..408d9988 100644 --- a/test/opentelemetry/solarwinds_processor_test.rb +++ b/test/opentelemetry/solarwinds_processor_test.rb @@ -34,6 +34,23 @@ _(result).must_equal "name" end + it 'test_calculate_transaction_names_with_SW_APM_TRANSACTION_NAME' do + ENV['SW_APM_TRANSACTION_NAME'] = 'another_name' + + span = create_span + result = @processor.send(:calculate_transaction_names, span) + _(result).must_equal "another_name" + ENV.delete('SW_APM_TRANSACTION_NAME') + end + + it 'test_calculate_transaction_names_with_SW_APM_TRANSACTION_NAME_nil' do + ENV['SW_APM_TRANSACTION_NAME'] = nil + + span = create_span + result = @processor.send(:calculate_transaction_names, span) + _(result).must_equal "name" + end + it 'test_get_http_status_code' do span_data = create_span_data result = @processor.send(:get_http_status_code, span_data)