Skip to content

Commit

Permalink
Merge pull request #85 from solarwinds/NH-65373
Browse files Browse the repository at this point in the history
NH-65373: include the ENV var for SW_APM_TRANSACTION_NAME
  • Loading branch information
xuan-cao-swi authored Nov 3, 2023
2 parents 3dcf741 + 55b8b0b commit 0b4e038
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
17 changes: 17 additions & 0 deletions test/opentelemetry/solarwinds_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0b4e038

Please sign in to comment.