solarwinds_apm 6.0.0.preV4 → 6.0.0.prev6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/ext/oboe_metal/extconf.rb +4 -3
  3. data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +1 -1
  4. data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +1 -1
  5. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +1 -1
  6. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
  7. data/ext/oboe_metal/src/VERSION +1 -1
  8. data/ext/oboe_metal/src/oboe.h +56 -13
  9. data/ext/oboe_metal/src/oboe_api.cpp +105 -6
  10. data/ext/oboe_metal/src/oboe_api.h +121 -2
  11. data/ext/oboe_metal/src/oboe_debug.h +4 -315
  12. data/ext/oboe_metal/src/oboe_swig_wrap.cc +2987 -549
  13. data/lib/oboe_metal.rb +5 -2
  14. data/lib/rails/generators/solarwinds_apm/install_generator.rb +5 -2
  15. data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +8 -4
  16. data/lib/solarwinds_apm/api/current_trace_info.rb +8 -7
  17. data/lib/solarwinds_apm/api/custom_metrics.rb +93 -0
  18. data/lib/solarwinds_apm/api/opentelemetry.rb +6 -0
  19. data/lib/solarwinds_apm/api/tracing.rb +32 -5
  20. data/lib/solarwinds_apm/api/transaction_name.rb +30 -14
  21. data/lib/solarwinds_apm/api.rb +7 -2
  22. data/lib/solarwinds_apm/base.rb +5 -14
  23. data/lib/solarwinds_apm/config.rb +58 -17
  24. data/lib/solarwinds_apm/constants.rb +6 -0
  25. data/lib/solarwinds_apm/logger.rb +5 -2
  26. data/lib/solarwinds_apm/noop/context.rb +5 -2
  27. data/lib/solarwinds_apm/noop/metadata.rb +5 -2
  28. data/lib/solarwinds_apm/oboe_init_options.rb +37 -19
  29. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +7 -2
  30. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +10 -1
  31. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +6 -0
  32. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +6 -0
  33. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +8 -1
  34. data/lib/solarwinds_apm/opentelemetry.rb +6 -0
  35. data/lib/solarwinds_apm/otel_config.rb +18 -29
  36. data/lib/solarwinds_apm/support/logger_formatter.rb +6 -3
  37. data/lib/solarwinds_apm/support/logging_log_event.rb +5 -2
  38. data/lib/solarwinds_apm/support/lumberjack_formatter.rb +5 -2
  39. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +10 -4
  40. data/lib/solarwinds_apm/support/swomarginalia/README.md +1 -1
  41. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +3 -3
  42. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +6 -0
  43. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +1 -1
  44. data/lib/solarwinds_apm/support/transaction_cache.rb +6 -0
  45. data/lib/solarwinds_apm/support/transaction_settings.rb +6 -7
  46. data/lib/solarwinds_apm/support/txn_name_manager.rb +6 -0
  47. data/lib/solarwinds_apm/support/utils.rb +6 -0
  48. data/lib/solarwinds_apm/support/x_trace_options.rb +5 -2
  49. data/lib/solarwinds_apm/support.rb +5 -3
  50. data/lib/solarwinds_apm/support_report.rb +6 -3
  51. data/lib/solarwinds_apm/thread_local.rb +5 -2
  52. data/lib/solarwinds_apm/version.rb +6 -3
  53. data/lib/solarwinds_apm.rb +9 -11
  54. metadata +6 -4
data/lib/oboe_metal.rb CHANGED
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  # Disable docs and Camelcase warns since we're implementing
5
8
  # an interface here. See OboeBase for details.
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  module SolarWindsAPM
5
8
  # InstallGenerator
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2019 SolarWinds, LLC.
4
- # All rights reserved.
3
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
8
 
6
9
  # SolarWindsAPM Configuration for the Ruby Agent aka solarwinds_apm gem
7
10
  # https://cloud.solarwinds.com/
@@ -33,7 +36,8 @@ if defined?(SolarWindsAPM::Config)
33
36
  # SolarWindsAPM::Config[:hostname_alias] = 'alias_name'
34
37
 
35
38
  #
36
- # Set Proxy for SolarWinds # This setting will be overridden if SW_APM_PROXY is set as an environment variable.
39
+ # Set Proxy for SolarWinds
40
+ # This setting will be overridden if SW_APM_PROXY is set as an environment variable.
37
41
  #
38
42
  # Please configure http_proxy if a proxy needs to be used to communicate with
39
43
  # the SolarWinds APM collector.
@@ -143,7 +147,7 @@ if defined?(SolarWindsAPM::Config)
143
147
  # Trace options is a custom HTTP header X-Trace-Options that can be set on a request to carry additional information
144
148
  # to the agents, one such option being trigger-trace which we’ll call a trigger trace request.
145
149
  #
146
- SolarWindsAPM::Config[:trigger_tracing_mode] = 'enabled'
150
+ SolarWindsAPM::Config[:trigger_tracing_mode] = :enabled
147
151
 
148
152
  #
149
153
  # Argument logging
@@ -1,7 +1,9 @@
1
- #--
2
- # Copyright (c) SolarWinds, LLC.
3
- # All rights reserved.
4
- #++
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
5
7
  module SolarWindsAPM
6
8
  module API
7
9
  module CurrentTraceInfo
@@ -49,7 +51,7 @@ module SolarWindsAPM
49
51
  class TraceInfo
50
52
  attr_reader :tracestring, :trace_id, :span_id, :trace_flags, :do_log
51
53
 
52
- REGEXP = /^(?<tracestring>(?<version>[a-f0-9]{2})-(?<trace_id>[a-f0-9]{32})-(?<span_id>[a-f0-9]{16})-(?<flags>[a-f0-9]{2}))$/
54
+ REGEXP = /^(?<tracestring>(?<version>[a-f0-9]{2})-(?<trace_id>[a-f0-9]{32})-(?<span_id>[a-f0-9]{16})-(?<flags>[a-f0-9]{2}))$/.freeze # rubocop:disable Style/RedundantFreeze
53
55
  private_constant :REGEXP
54
56
 
55
57
  def initialize
@@ -96,8 +98,7 @@ module SolarWindsAPM
96
98
  # * Hash
97
99
  #
98
100
  def hash_for_log
99
- @hash_for_log = {}
100
- @hash_for_log = {trace_id: @trace_id, span_id: @span_id, trace_flags: @trace_flags, service_name: @service_name} if @do_log
101
+ @hash_for_log = @do_log ? {'trace_id' => @trace_id, 'span_id' => @span_id, 'trace_flags' => @trace_flags, 'resource.service.name' => @service_name} : {}
101
102
  end
102
103
 
103
104
  private
@@ -0,0 +1,93 @@
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
7
+ module SolarWindsAPM
8
+ module API
9
+ module CustomMetrics
10
+ # Send counts
11
+ #
12
+ # Use this method to report the number of times an action occurs. The metric counts reported are summed and flushed every 60 seconds.
13
+ #
14
+ # === Arguments:
15
+ #
16
+ # * +name+ (String) Name to be used for the metric. Must be 255 or fewer characters and consist only of A-Za-z0-9.:-*
17
+ # * +count+ (Integer, optional, default = 1): Count of actions being reported
18
+ # * +with_hostname+ (Boolean, optional, default = false): Indicates if the host name should be included as a tag for the metric
19
+ # * +tags_kvs+ (Hash, optional): List of key/value pairs to describe the metric. The key must be <= 64 characters, the value must be <= 255 characters, allowed characters: A-Za-z0-9.:-_
20
+ #
21
+ # === Example:
22
+ #
23
+ # class WorkTracker
24
+ # def counting(name, tags = {})
25
+ # yield # yield to where work is done
26
+ # SolarWindsAPM::API.increment_metric(name, 1, false, tags)
27
+ # end
28
+ # end
29
+ #
30
+ # === Returns:
31
+ # * Boolean
32
+ #
33
+ def increment_metric(name, count=1, with_hostname=false, tags_kvs={}) # rubocop:disable Style/OptionalBooleanParameter
34
+ return true unless SolarWindsAPM.loaded
35
+
36
+ with_hostname = with_hostname ? 1 : 0
37
+ tags, tags_count = make_tags(tags_kvs)
38
+ SolarWindsAPM::CustomMetrics.increment(name.to_s, count, with_hostname, nil, tags, tags_count) == 0
39
+ end
40
+
41
+ # Send values with counts
42
+ #
43
+ # Use this method to report a value for each or multiple counts. The metric values reported are aggregated and flushed every 60 seconds. The dashboard displays the average value per count.
44
+ #
45
+ # === Arguments:
46
+ #
47
+ # * +name+ (String) Name to be used for the metric. Must be 255 or fewer characters and consist only of A-Za-z0-9.:-*
48
+ # * +value+ (Numeric) Value to be added to the current sum
49
+ # * +count+ (Integer, optional, default = 1): Count of actions being reported
50
+ # * +with_hostname+ (Boolean, optional, default = false): Indicates if the host name should be included as a tag for the metric
51
+ # * +tags_kvs+ (Hash, optional): List of key/value pairs to describe the metric. The key must be <= 64 characters, the value must be <= 255 characters, allowed characters: A-Za-z0-9.:-_
52
+ #
53
+ # === Example:
54
+ #
55
+ # class WorkTracker
56
+ # def timing(name, tags = {})
57
+ # start = Time.now
58
+ # yield # yield to where work is done
59
+ # duration = Time.now - start
60
+ # SolarWindsAPM::API.summary_metric(name, duration, 1, false, tags)
61
+ # end
62
+ # end
63
+ #
64
+ # === Returns:
65
+ # * Boolean
66
+ #
67
+ def summary_metric(name, value, count=1, with_hostname=false, tags_kvs={}) # rubocop:disable Style/OptionalBooleanParameter
68
+ return true unless SolarWindsAPM.loaded
69
+
70
+ with_hostname = with_hostname ? 1 : 0
71
+ tags, tags_count = make_tags(tags_kvs)
72
+ SolarWindsAPM::CustomMetrics.summary(name.to_s, value, count, with_hostname, nil, tags, tags_count) == 0
73
+ end
74
+
75
+ private
76
+
77
+ def make_tags(tags_kvs)
78
+ unless tags_kvs.is_a?(Hash)
79
+ SolarWindsAPM.logger.warn("[solarwinds_apm/metrics] CustomMetrics received tags_kvs that are not a Hash (found #{tags_kvs.class}), setting tags_kvs = {}")
80
+ tags_kvs = {}
81
+ end
82
+ count = tags_kvs.size
83
+ tags = SolarWindsAPM::MetricTags.new(count)
84
+
85
+ tags_kvs.each_with_index do |(k, v), i|
86
+ tags.add(i, k.to_s, v.to_s)
87
+ end
88
+
89
+ [tags, count]
90
+ end
91
+ end
92
+ end
93
+ end
@@ -1,3 +1,9 @@
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
1
7
  module SolarWindsAPM
2
8
  module API
3
9
  module OpenTelemetry
@@ -1,15 +1,31 @@
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
1
7
  module SolarWindsAPM
2
8
  module API
3
9
  module Tracing
4
10
  # Wait for SolarWinds to be ready to send traces.
5
11
  #
6
12
  # This may be useful in short lived background processes when it is important to capture
7
- # information during the whole time the process is running. Usually SolarWinds doesn't block an
8
- # application while it is starting up.
13
+ # information during the whole time the process is running. It returns boolean if <tt>integer_response</tt> is false,
14
+ # and it will return integer if setting <tt>integer_response</tt> as true.
15
+ # Usually SolarWinds doesn't block an application while it is starting up.
16
+ #
17
+ # For status code reference:
18
+ # 0: unknown error
19
+ # 1: is ready
20
+ # 2: not ready yet, try later
21
+ # 3: limit exceeded
22
+ # 4: invalid API key
23
+ # 5: connection error
9
24
  #
10
25
  # === Argument:
11
26
  #
12
27
  # * +wait_milliseconds+ - (int, default 3000) the maximum time to wait in milliseconds
28
+ # * +integer_response+ - (boolean, default false) determine whether return status code of reporter or not
13
29
  #
14
30
  # === Example:
15
31
  #
@@ -17,13 +33,24 @@ module SolarWindsAPM
17
33
  # Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent"
18
34
  # end
19
35
  #
36
+ # # with status code print out
37
+ # status = SolarWindsAPM::API.solarwinds_ready?(10_000, integer_response: true)
38
+ # unless status == 1
39
+ # Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent. Error code "#{status}"
40
+ # end
41
+ #
20
42
  # === Returns:
21
- # * Boolean
43
+ # * Boolean (if integer_response: false)
44
+ # * Integer (if integer_response: true)
22
45
  #
23
- def solarwinds_ready?(wait_milliseconds=3000)
46
+ def solarwinds_ready?(wait_milliseconds=3000, integer_response: false)
24
47
  return false unless SolarWindsAPM.loaded
25
48
 
26
- SolarWindsAPM::Context.isReady(wait_milliseconds) == 1
49
+ is_ready = SolarWindsAPM::Context.isReady(wait_milliseconds)
50
+
51
+ return is_ready if integer_response
52
+
53
+ is_ready == 1
27
54
  end
28
55
  end
29
56
  end
@@ -1,3 +1,9 @@
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
1
7
  module SolarWindsAPM
2
8
  module API
3
9
  module TransactionName
@@ -30,26 +36,36 @@ module SolarWindsAPM
30
36
  # * Boolean
31
37
  #
32
38
  def set_transaction_name(custom_name=nil)
33
-
34
39
  status = true
35
- if custom_name.nil? || custom_name.empty?
40
+ if ENV.fetch('SW_APM_ENABLED', 'true') == 'false' ||
41
+ SolarWindsAPM::Context.toString == '99-00000000000000000000000000000000-0000000000000000-00'
42
+ # library disabled or noop, just log and skip work.
43
+ # TODO: can we have a single indicator that the API is in noop mode?
44
+ SolarWindsAPM.logger.debug {"[#{name}/#{__method__}] SolarWindsAPM is in disabled or noop mode."}
45
+ elsif custom_name.nil? || custom_name.empty?
46
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Set transaction name failed: custom_name is either nil or empty string."}
36
47
  status = false
37
- elsif SolarWindsAPM::Context.toString == '99-00000000000000000000000000000000-0000000000000000-00' # noop
38
- status = true
39
48
  elsif SolarWindsAPM::OTelConfig.class_variable_get(:@@config)[:span_processor].nil?
40
- SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Solarwinds processor is missing. Set transaction name failed."}
49
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Set transaction name failed: Solarwinds processor is missing."}
41
50
  status = false
42
51
  else
43
- solarwinds_processor = SolarWindsAPM::OTelConfig.class_variable_get(:@@config)[:span_processor]
44
- current_span = ::OpenTelemetry::Trace.current_span
45
- entry_trace_id = current_span.context.hex_trace_id
46
- entry_span_id, trace_flags = solarwinds_processor.txn_manager.get_root_context_h(entry_trace_id)&.split('-')
47
-
48
- status = false if entry_trace_id.nil? || entry_span_id.nil? || trace_flags.nil?
49
- status = false if entry_trace_id == '0'*32 || entry_span_id == '0'*16 || trace_flags == '00' # not sampled
52
+ solarwinds_processor = SolarWindsAPM::OTelConfig.class_variable_get(:@@config)[:span_processor]
53
+ current_span = ::OpenTelemetry::Trace.current_span
50
54
 
51
- solarwinds_processor.txn_manager.set("#{entry_trace_id}-#{entry_span_id}",custom_name)
52
- SolarWindsAPM.logger.debug {"[#{name}/#{__method__}] Cached custom transaction name for #{entry_trace_id}-#{entry_span_id} as #{custom_name}"}
55
+ if current_span.context.valid?
56
+ current_trace_id = current_span.context.hex_trace_id
57
+ entry_span_id, trace_flags = solarwinds_processor.txn_manager.get_root_context_h(current_trace_id)&.split('-')
58
+ if entry_span_id.to_s.empty? || trace_flags.to_s.empty?
59
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Set transaction name failed: record not found in the transaction manager."}
60
+ status = false
61
+ else
62
+ solarwinds_processor.txn_manager.set("#{current_trace_id}-#{entry_span_id}",custom_name)
63
+ SolarWindsAPM.logger.debug {"[#{name}/#{__method__}] Cached custom transaction name for #{current_trace_id}-#{entry_span_id} as #{custom_name}"}
64
+ end
65
+ else
66
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Set transaction name failed: invalid span context."}
67
+ status = false
68
+ end
53
69
  end
54
70
  status
55
71
  end
@@ -1,10 +1,14 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  require_relative './api/transaction_name'
5
8
  require_relative './api/current_trace_info'
6
9
  require_relative './api/tracing'
7
10
  require_relative './api/opentelemetry'
11
+ require_relative './api/custom_metrics'
8
12
 
9
13
  module SolarWindsAPM
10
14
  module API
@@ -12,5 +16,6 @@ module SolarWindsAPM
12
16
  extend SolarWindsAPM::API::CurrentTraceInfo
13
17
  extend SolarWindsAPM::API::Tracing
14
18
  extend SolarWindsAPM::API::OpenTelemetry
19
+ extend SolarWindsAPM::API::CustomMetrics
15
20
  end
16
21
  end
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  ##
5
8
  # This module is the base module for SolarWindsAPM reporting.
@@ -8,18 +11,6 @@ module SolarWindsAPMBase
8
11
  extend SolarWindsAPM::ThreadLocal
9
12
 
10
13
  attr_accessor :reporter, :loaded
11
-
12
- ##
13
- # Determines if we are running under a forking webserver
14
- #
15
- def forking_webserver?
16
- if (defined?(::Unicorn) && ($PROGRAM_NAME =~ /unicorn/i)) ||
17
- (defined?(::Puma) && ($PROGRAM_NAME =~ /puma/i))
18
- true
19
- else
20
- false
21
- end
22
- end
23
14
  end
24
15
 
25
16
  module SolarWindsAPM
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  module SolarWindsAPM
5
8
  ##
@@ -9,6 +12,15 @@ module SolarWindsAPM
9
12
  # Use SolarWindsAPM::Config.show to view the entire nested hash.
10
13
  #
11
14
  module Config
15
+ LOGGER_LEVEL_MAPPING = {-1 => ::Logger::FATAL,
16
+ 0 => ::Logger::FATAL,
17
+ 1 => ::Logger::ERROR,
18
+ 2 => ::Logger::WARN,
19
+ 3 => ::Logger::INFO,
20
+ 4 => ::Logger::DEBUG,
21
+ 5 => ::Logger::DEBUG,
22
+ 6 => ::Logger::DEBUG}.freeze
23
+
12
24
  @@config = {}
13
25
  @@instrumentation = [:action_controller, :action_controller_api, :action_view,
14
26
  :active_record, :bunnyclient, :bunnyconsumer, :curb,
@@ -41,19 +53,20 @@ module SolarWindsAPM
41
53
  config_files << config_file if File.exist?(config_file)
42
54
 
43
55
  # Check for file set by env variable
44
- config_files << config_from_env if ENV.has_key?('SW_APM_CONFIG_RUBY')
56
+ config_files << config_file_from_env if ENV.has_key?('SW_APM_CONFIG_RUBY')
45
57
 
46
58
  # Check for default config file
47
59
  config_file = File.join(Dir.pwd, 'solarwinds_apm_config.rb')
48
60
  config_files << config_file if File.exist?(config_file)
49
61
 
62
+ SolarWindsAPM.logger.debug {"[#{name}/#{__method__}] Available config_files: #{config_files.join(', ')}" }
50
63
  SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Multiple configuration files configured, using the first one listed: #{config_files.join(', ')}"} if config_files.size > 1
51
64
  load(config_files[0]) if config_files.size > 0
52
65
 
53
66
  set_log_level # sets SolarWindsAPM::Config[:debug_level], SolarWindsAPM.logger.level
54
67
  end
55
68
 
56
- def self.config_from_env
69
+ def self.config_file_from_env
57
70
  if File.exist?(ENV['SW_APM_CONFIG_RUBY']) && !File.directory?(ENV['SW_APM_CONFIG_RUBY'])
58
71
  config_file = ENV['SW_APM_CONFIG_RUBY']
59
72
  elsif File.exist?(File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb'))
@@ -65,11 +78,40 @@ module SolarWindsAPM
65
78
  end
66
79
 
67
80
  def self.set_log_level
68
- SolarWindsAPM::Config[:debug_level] = 3 unless (-1..6).include?(SolarWindsAPM::Config[:debug_level])
81
+ log_level = (ENV['SW_APM_DEBUG_LEVEL'] || SolarWindsAPM::Config[:debug_level] || 3).to_i
82
+
83
+ SolarWindsAPM.logger = ::Logger.new(nil) if log_level == -1
84
+
85
+ SolarWindsAPM.logger.level = LOGGER_LEVEL_MAPPING[log_level] || ::Logger::INFO # default log level info
86
+ end
87
+
88
+ def self.enable_disable_config(env_var, key, value, default, bool: false)
89
+ env_value = ENV[env_var.to_s]&.downcase
90
+ valid_env_values = bool ? %w[true false] : %w[enabled disabled]
91
+
92
+ if env_var && valid_env_values.include?(env_value)
93
+ value = bool ? true?(env_value) : env_value.to_sym
94
+ elsif env_var && !env_value.to_s.empty?
95
+ SolarWindsAPM.logger.warn("[#{name}/#{__method__}] #{env_var} must be #{valid_env_values.join('/')} (current setting is #{ENV[env_var]}). Using default value: #{default}.")
96
+ return @@config[key.to_sym] = default
97
+ end
98
+
99
+ return @@config[key.to_sym] = value unless (bool && !boolean?(value)) || (!bool && !symbol?(value))
69
100
 
70
- # let's find and use the equivalent debug level for ruby
71
- debug_level = (ENV['SW_APM_DEBUG_LEVEL'] || SolarWindsAPM::Config[:debug_level] || 3).to_i
72
- SolarWindsAPM.logger.level = debug_level < 0 ? 6 : [4 - debug_level, 0].max
101
+ SolarWindsAPM.logger.warn("[#{name}/#{__method__}] :#{key} must be a #{valid_env_values.join('/')}. Using default value: #{default}.")
102
+ @@config[key.to_sym] = default
103
+ end
104
+
105
+ def self.true?(obj)
106
+ obj.to_s.casecmp("true").zero?
107
+ end
108
+
109
+ def self.boolean?(obj)
110
+ [true, false].include?(obj)
111
+ end
112
+
113
+ def self.symbol?(obj)
114
+ [:enabled, :disabled].include?(obj)
73
115
  end
74
116
 
75
117
  ##
@@ -90,8 +132,9 @@ module SolarWindsAPM
90
132
  #
91
133
  # Initializer method to set everything up with a default configuration.
92
134
  # The defaults are read from the template configuration file.
135
+ # This will be called when require 'solarwinds_apm/config' happen
93
136
  #
94
- def self.initialize(_data={})
137
+ def self.initialize
95
138
  # for config file backward compatibility
96
139
  @@instrumentation.each {|inst| @@config[inst] = {}}
97
140
  @@config[:transaction_name] = {}
@@ -120,6 +163,7 @@ module SolarWindsAPM
120
163
  #
121
164
  # Config variable assignment method. Here we validate and store the
122
165
  # assigned value(s) and trigger any secondary action needed.
166
+ # ENV always have higher precedence
123
167
  #
124
168
  def self.[]=(key, value)
125
169
  key = key.to_sym
@@ -148,17 +192,14 @@ module SolarWindsAPM
148
192
  when :transaction_settings
149
193
  compile_settings(value)
150
194
 
195
+ when :trigger_tracing_mode
196
+ enable_disable_config('SW_APM_TRIGGER_TRACING_MODE', key, value, :enabled)
197
+
151
198
  when :tracing_mode
152
- # ALL TRACING COMMUNICATION TO OBOE IS NOW HANDLED BY TransactionSettings
153
- # Make sure that the mode is stored as a symbol
154
- @@config[key.to_sym] = value.to_sym
199
+ enable_disable_config(nil, key, value, :enabled)
155
200
 
156
201
  when :tag_sql
157
- if ENV.has_key?('SW_APM_TAG_SQL')
158
- @@config[key.to_sym] = (ENV['SW_APM_TAG_SQL'] == 'true')
159
- else
160
- @@config[key.to_sym] = value
161
- end
202
+ enable_disable_config('SW_APM_TAG_SQL', key, value, false, bool: true)
162
203
 
163
204
  else
164
205
  @@config[key.to_sym] = value
@@ -1,3 +1,9 @@
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6
+
1
7
  module SolarWindsAPM
2
8
  # Constants
3
9
  module Constants
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  require 'logger'
5
8
 
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2019 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  ####
5
8
  # noop version of SolarWindsAPM::Context
@@ -1,5 +1,8 @@
1
- # Copyright (c) 2019 SolarWinds, LLC.
2
- # All rights reserved.
1
+ # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
3
6
 
4
7
  ####
5
8
  # noop version of SolarWindsAPM::Metadata