Skip to content

Commit 012ab89

Browse files
committed
revision: update config_token
1 parent e098635 commit 012ab89

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/solarwinds_apm/support/otlp_endpoint.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def config_token(data_type)
7676
# for case 10 and 11
7777
agent_enable = !ENV['SW_APM_API_TOKEN'].nil?
7878
else
79-
token_type = if ENV["OTEL_EXPORTER_OTLP_#{data_type_upper}_HEADERS"]
79+
token_source = if ENV["OTEL_EXPORTER_OTLP_#{data_type_upper}_HEADERS"]
8080
"#{data_type}_token"
8181
elsif ENV['OTEL_EXPORTER_OTLP_HEADERS']
8282
'general_token'
@@ -86,22 +86,20 @@ def config_token(data_type)
8686
'invalid'
8787
end
8888

89-
case token_type
90-
when "#{data_type}_token" || 'general_token'
91-
# exporter header is ok, but still need extract it for sampler http get setting
92-
headers = token_type == 'general_token' ? ENV.fetch('OTEL_EXPORTER_OTLP_HEADERS', nil) : ENV.fetch("OTEL_EXPORTER_OTLP_#{data_type_upper}_HEADERS", nil)
93-
@token = headers.gsub('authorization=Bearer ', '')
94-
when 'service_key'
89+
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] token source: #{token_source}" }
90+
91+
if token_source == 'service_key'
9592
if valid?(ENV['SW_APM_SERVICE_KEY'])
9693
@token, @service_name = ENV['SW_APM_SERVICE_KEY'].to_s.split(':')
9794
else
95+
token_source = 'invalid'
9896
SolarWindsAPM.logger.warn { "SW_APM_SERVICE_KEY is invalid: #{mask_token(ENV['SW_APM_SERVICE_KEY'])}" }
9997
end
10098

10199
ENV['OTEL_EXPORTER_OTLP_HEADERS'] = "authorization=Bearer #{@token}"
102100
end
103101

104-
agent_enable = token_type != 'invalid'
102+
agent_enable = token_source != 'invalid'
105103
end
106104

107105
@agent_enable = agent_enable

0 commit comments

Comments
 (0)