solarwinds_apm 5.1.9 → 6.0.0.preV2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +28 -55
  3. data/ext/oboe_metal/extconf.rb +37 -41
  4. data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +1 -1
  5. data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +1 -1
  6. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +1 -1
  7. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
  8. data/ext/oboe_metal/src/VERSION +1 -1
  9. data/ext/oboe_metal/src/init_solarwinds_apm.cc +0 -6
  10. data/ext/oboe_metal/src/oboe_debug.h +1 -0
  11. data/lib/oboe_metal.rb +116 -80
  12. data/lib/rails/generators/solarwinds_apm/install_generator.rb +1 -5
  13. data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +42 -267
  14. data/lib/solarwinds_apm/api/current_trace_info.rb +148 -0
  15. data/lib/solarwinds_apm/api/tracing.rb +30 -0
  16. data/lib/solarwinds_apm/api/transaction_name.rb +58 -0
  17. data/lib/solarwinds_apm/api.rb +8 -15
  18. data/lib/solarwinds_apm/base.rb +4 -131
  19. data/lib/solarwinds_apm/config.rb +101 -174
  20. data/lib/solarwinds_apm/constants.rb +32 -0
  21. data/lib/solarwinds_apm/logger.rb +1 -1
  22. data/lib/solarwinds_apm/noop/context.rb +2 -5
  23. data/lib/solarwinds_apm/noop/metadata.rb +1 -2
  24. data/lib/solarwinds_apm/oboe_init_options.rb +74 -38
  25. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +204 -0
  26. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +166 -0
  27. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +92 -0
  28. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +72 -0
  29. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +335 -0
  30. data/lib/solarwinds_apm/opentelemetry.rb +8 -0
  31. data/lib/solarwinds_apm/otel_config.rb +161 -0
  32. data/lib/solarwinds_apm/{inst → support}/logger_formatter.rb +5 -6
  33. data/lib/solarwinds_apm/{inst → support}/logging_log_event.rb +3 -6
  34. data/lib/solarwinds_apm/{inst → support}/lumberjack_formatter.rb +1 -4
  35. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +27 -0
  36. data/lib/solarwinds_apm/support/swomarginalia/LICENSE +20 -0
  37. data/lib/solarwinds_apm/support/swomarginalia/README.md +41 -0
  38. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +205 -0
  39. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +48 -0
  40. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +22 -0
  41. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +86 -0
  42. data/lib/solarwinds_apm/support/transaction_cache.rb +24 -0
  43. data/lib/solarwinds_apm/support/transaction_settings.rb +26 -209
  44. data/lib/solarwinds_apm/support/transformer.rb +56 -0
  45. data/lib/solarwinds_apm/support/txn_name_manager.rb +25 -0
  46. data/lib/solarwinds_apm/support/x_trace_options.rb +42 -26
  47. data/lib/solarwinds_apm/support.rb +37 -10
  48. data/lib/solarwinds_apm/support_report.rb +10 -32
  49. data/lib/solarwinds_apm/thread_local.rb +1 -1
  50. data/lib/solarwinds_apm/version.rb +4 -4
  51. data/lib/solarwinds_apm.rb +29 -25
  52. metadata +63 -123
  53. data/.dockerignore +0 -5
  54. data/.gitignore +0 -58
  55. data/.rubocop.yml +0 -29
  56. data/.whitesource +0 -22
  57. data/.yardopts +0 -7
  58. data/CHANGELOG-appoptics.md +0 -766
  59. data/CHANGELOG.md +0 -82
  60. data/CONFIG.md +0 -31
  61. data/Gemfile +0 -15
  62. data/README.md +0 -385
  63. data/bin/solarwinds_apm_config +0 -15
  64. data/examples/prepend.rb +0 -13
  65. data/examples/sdk_examples.rb +0 -158
  66. data/ext/oboe_metal/README.md +0 -69
  67. data/ext/oboe_metal/extconf_local.rb +0 -75
  68. data/ext/oboe_metal/lib/.keep +0 -0
  69. data/ext/oboe_metal/noop/noop.c +0 -8
  70. data/ext/oboe_metal/src/README.md +0 -6
  71. data/ext/oboe_metal/src/frames.cc +0 -247
  72. data/ext/oboe_metal/src/frames.h +0 -40
  73. data/ext/oboe_metal/src/logging.cc +0 -97
  74. data/ext/oboe_metal/src/logging.h +0 -34
  75. data/ext/oboe_metal/src/profiling.cc +0 -435
  76. data/ext/oboe_metal/src/profiling.h +0 -78
  77. data/ext/oboe_metal/test/CMakeLists.txt +0 -53
  78. data/ext/oboe_metal/test/FindGMock.cmake +0 -43
  79. data/ext/oboe_metal/test/README.md +0 -56
  80. data/ext/oboe_metal/test/frames_test.cc +0 -164
  81. data/ext/oboe_metal/test/profiling_test.cc +0 -93
  82. data/ext/oboe_metal/test/ruby_inc_dir.rb +0 -8
  83. data/ext/oboe_metal/test/ruby_prefix.rb +0 -8
  84. data/ext/oboe_metal/test/ruby_test_helper.rb +0 -67
  85. data/ext/oboe_metal/test/test.h +0 -11
  86. data/ext/oboe_metal/test/test_main.cc +0 -32
  87. data/init.rb +0 -4
  88. data/lib/solarwinds_apm/api/layerinit.rb +0 -41
  89. data/lib/solarwinds_apm/api/logging.rb +0 -356
  90. data/lib/solarwinds_apm/api/memcache.rb +0 -37
  91. data/lib/solarwinds_apm/api/metrics.rb +0 -63
  92. data/lib/solarwinds_apm/api/util.rb +0 -98
  93. data/lib/solarwinds_apm/frameworks/grape.rb +0 -96
  94. data/lib/solarwinds_apm/frameworks/padrino.rb +0 -78
  95. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller.rb +0 -100
  96. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller5.rb +0 -50
  97. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller_api.rb +0 -50
  98. data/lib/solarwinds_apm/frameworks/rails/inst/action_view.rb +0 -88
  99. data/lib/solarwinds_apm/frameworks/rails/inst/active_record.rb +0 -26
  100. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +0 -29
  101. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +0 -22
  102. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +0 -103
  103. data/lib/solarwinds_apm/frameworks/rails/inst/logger_formatters.rb +0 -14
  104. data/lib/solarwinds_apm/frameworks/rails.rb +0 -100
  105. data/lib/solarwinds_apm/frameworks/sinatra.rb +0 -96
  106. data/lib/solarwinds_apm/inst/bunny-client.rb +0 -157
  107. data/lib/solarwinds_apm/inst/bunny-consumer.rb +0 -102
  108. data/lib/solarwinds_apm/inst/curb.rb +0 -289
  109. data/lib/solarwinds_apm/inst/dalli.rb +0 -89
  110. data/lib/solarwinds_apm/inst/delayed_job.rb +0 -100
  111. data/lib/solarwinds_apm/inst/excon.rb +0 -113
  112. data/lib/solarwinds_apm/inst/faraday.rb +0 -96
  113. data/lib/solarwinds_apm/inst/graphql.rb +0 -206
  114. data/lib/solarwinds_apm/inst/grpc_client.rb +0 -147
  115. data/lib/solarwinds_apm/inst/grpc_server.rb +0 -119
  116. data/lib/solarwinds_apm/inst/httpclient.rb +0 -182
  117. data/lib/solarwinds_apm/inst/memcached.rb +0 -86
  118. data/lib/solarwinds_apm/inst/mongo.rb +0 -246
  119. data/lib/solarwinds_apm/inst/mongo2.rb +0 -225
  120. data/lib/solarwinds_apm/inst/moped.rb +0 -466
  121. data/lib/solarwinds_apm/inst/net_http.rb +0 -60
  122. data/lib/solarwinds_apm/inst/rack.rb +0 -223
  123. data/lib/solarwinds_apm/inst/rack_cache.rb +0 -35
  124. data/lib/solarwinds_apm/inst/redis.rb +0 -280
  125. data/lib/solarwinds_apm/inst/redis_v4.rb +0 -273
  126. data/lib/solarwinds_apm/inst/resque.rb +0 -129
  127. data/lib/solarwinds_apm/inst/rest-client.rb +0 -43
  128. data/lib/solarwinds_apm/inst/sequel.rb +0 -241
  129. data/lib/solarwinds_apm/inst/sidekiq-client.rb +0 -63
  130. data/lib/solarwinds_apm/inst/sidekiq-worker.rb +0 -64
  131. data/lib/solarwinds_apm/inst/typhoeus.rb +0 -90
  132. data/lib/solarwinds_apm/instrumentation.rb +0 -22
  133. data/lib/solarwinds_apm/loading.rb +0 -65
  134. data/lib/solarwinds_apm/noop/profiling.rb +0 -21
  135. data/lib/solarwinds_apm/ruby.rb +0 -35
  136. data/lib/solarwinds_apm/sdk/current_trace_info.rb +0 -123
  137. data/lib/solarwinds_apm/sdk/custom_metrics.rb +0 -94
  138. data/lib/solarwinds_apm/sdk/logging.rb +0 -37
  139. data/lib/solarwinds_apm/sdk/trace_context_headers.rb +0 -69
  140. data/lib/solarwinds_apm/sdk/tracing.rb +0 -432
  141. data/lib/solarwinds_apm/support/profiling.rb +0 -25
  142. data/lib/solarwinds_apm/support/trace_context.rb +0 -53
  143. data/lib/solarwinds_apm/support/trace_state.rb +0 -69
  144. data/lib/solarwinds_apm/support/trace_string.rb +0 -89
  145. data/lib/solarwinds_apm/support/transaction_metrics.rb +0 -67
  146. data/lib/solarwinds_apm/test.rb +0 -165
  147. data/lib/solarwinds_apm/util.rb +0 -426
  148. data/log/.keep +0 -0
  149. data/log/postgresql/.keep +0 -0
  150. data/solarwinds_apm.gemspec +0 -55
  151. data/yardoc_frontpage.md +0 -24
@@ -1,21 +1,14 @@
1
1
  # Copyright (c) 2016 SolarWinds, LLC.
2
2
  # All rights reserved.
3
3
 
4
- module SolarWindsAPM
4
+ require_relative './api/transaction_name'
5
+ require_relative './api/current_trace_info'
6
+ require_relative './api/tracing'
5
7
 
8
+ module SolarWindsAPM
6
9
  module API
7
- extend SolarWindsAPM::API::Logging
8
- extend SolarWindsAPM::API::Metrics
9
- extend SolarWindsAPM::API::LayerInit
10
- extend SolarWindsAPM::API::Util
11
-
12
- require_relative './sdk/trace_context_headers'
13
- require_relative './sdk/tracing'
14
- require_relative './sdk/custom_metrics'
15
- require_relative './sdk/current_trace_info'
16
- require_relative './sdk/logging' # to make sure it is loaded <- not very elegant
17
-
18
- extend SolarWindsAPM::SDK::Tracing
19
- extend SolarWindsAPM::SDK::CustomMetrics
10
+ extend SolarWindsAPM::API::TransactionName
11
+ extend SolarWindsAPM::API::CurrentTraceInfo
12
+ extend SolarWindsAPM::API::Tracing
20
13
  end
21
- end
14
+ end
@@ -1,112 +1,13 @@
1
1
  # Copyright (c) 2016 SolarWinds, LLC.
2
2
  # All rights reserved.
3
3
 
4
- # Constants from liboboe
5
- SW_APM_TRACE_DISABLED = 0
6
- SW_APM_TRACE_ENABLED = 1
7
-
8
- SAMPLE_RATE_MASK = 0b0000111111111111111111111111
9
- SAMPLE_SOURCE_MASK = 0b1111000000000000000000000000
10
-
11
- # w3c trace context related global constants
12
- # see: https://www.w3.org/TR/trace-context/#tracestate-limits
13
- SW_APM_TRACESTATE_ID = 'sw'.freeze
14
- SW_APM_MAX_TRACESTATE_BYTES = 512
15
- SW_APM_MAX_TRACESTATE_MEMBER_BYTES = 128
16
-
17
- SW_APM_STR_LAYER = 'Layer'.freeze
18
- SW_APM_STR_LABEL = 'Label'.freeze
19
-
20
4
  ##
21
5
  # This module is the base module for SolarWindsAPM reporting.
22
6
  #
23
7
  module SolarWindsAPMBase
24
8
  extend SolarWindsAPM::ThreadLocal
25
9
 
26
- attr_accessor :reporter
27
- attr_accessor :loaded
28
-
29
- thread_local :sample_source
30
- thread_local :sample_rate
31
- thread_local :layer
32
- thread_local :layer_op
33
-
34
- # trace context is used to store incoming w3c trace information
35
- thread_local :trace_context
36
-
37
- # transaction_name is used for custom transaction naming
38
- # It needs to be globally accessible, but is only set by the request processors of the different frameworks
39
- # and read by rack
40
- thread_local :transaction_name
41
-
42
- # Semaphore used during the test suite to test
43
- # global config options.
44
- thread_local :config_lock
45
-
46
- ##
47
- # tracing_layer?
48
- #
49
- # Queries the thread local variable about the current
50
- # layer being traced. This is used in cases of recursive
51
- # operation tracing or one instrumented operation calling another.
52
- #
53
- def tracing_layer?(layer)
54
- SolarWindsAPM.layer == layer.to_sym
55
- end
56
-
57
- ##
58
- # tracing_layer_op?
59
- #
60
- # Queries the thread local variable about the current
61
- # operation being traced. This is used in cases of recursive
62
- # operation tracing or one instrumented operation calling another.
63
- #
64
- # In such cases, we only want to trace the outermost operation.
65
- #
66
- def tracing_layer_op?(operation)
67
- unless SolarWindsAPM.layer_op.nil? || SolarWindsAPM.layer_op.is_a?(Array)
68
- SolarWindsAPM.logger.error('[SolarWindsAPM/logging] INTERNAL: layer_op should be nil or an array, please report to technicalsupport@solarwinds.com')
69
- return false
70
- end
71
-
72
- return false if SolarWindsAPM.layer_op.nil? || SolarWindsAPM.layer_op.empty? || !operation.respond_to?(:to_sym)
73
- SolarWindsAPM.layer_op.last == operation.to_sym
74
- end
75
-
76
- # TODO review use of these boolean statements
77
- # ____ they should now be handled by TransactionSettings,
78
- # ____ because there can be exceptions to :enabled and :disabled
79
-
80
- ##
81
- # Returns true if the tracing_mode is set to :enabled.
82
- # False otherwise
83
- #
84
- def tracing_enabled?
85
- SolarWindsAPM::Config[:tracing_mode] &&
86
- [:enabled, :always].include?(SolarWindsAPM::Config[:tracing_mode].to_sym)
87
- end
88
-
89
- ##
90
- # Returns true if the tracing_mode is set to :disabled.
91
- # False otherwise
92
- #
93
- def tracing_disabled?
94
- SolarWindsAPM::Config[:tracing_mode] &&
95
- [:disabled, :never].include?(SolarWindsAPM::Config[:tracing_mode].to_sym)
96
- end
97
-
98
- ##
99
- # Returns true if we are currently tracing a request
100
- # False otherwise
101
- #
102
- def tracing?
103
- return false if !SolarWindsAPM.loaded # || SolarWindsAPM.tracing_disabled?
104
- SolarWindsAPM::Context.isSampled
105
- end
106
-
107
- def heroku?
108
- ENV.key?('SW_APM_URL')
109
- end
10
+ attr_accessor :reporter, :loaded
110
11
 
111
12
  ##
112
13
  # Determines if we are running under a forking webserver
@@ -119,42 +20,14 @@ module SolarWindsAPMBase
119
20
  false
120
21
  end
121
22
  end
122
-
123
- ##
124
- # Indicates whether a supported framework is in use
125
- # or not
126
- #
127
- def framework?
128
- defined?(::Rails) || defined?(::Sinatra) || defined?(::Padrino) || defined?(::Grape)
129
- end
130
-
131
- ##
132
- # These methods should be implemented by the descendants
133
- # currently only Oboe_metal
134
- #
135
- def sample?(_opts = {})
136
- fail 'sample? should be implemented by metal layer.'
137
- end
138
-
139
- def log(_layer, _label, _options = {})
140
- fail 'log should be implemented by metal layer.'
141
- end
142
-
143
- def set_tracing_mode(_mode)
144
- fail 'set_tracing_mode should be implemented by metal layer.'
145
- end
146
-
147
- def set_sample_rate(_rate)
148
- fail 'set_sample_rate should be implemented by metal layer.'
149
- end
150
23
  end
151
24
 
152
25
  module SolarWindsAPM
153
26
  extend SolarWindsAPMBase
154
27
  end
155
28
 
156
- # Setup an alias so we don't bug users
157
- # about single letter capitalization
158
- SolarwindsAPM = SolarWindsAPM
29
+ # Setup an alias
159
30
  SolarWindsApm = SolarWindsAPM
160
31
  SolarwindsApm = SolarWindsAPM
32
+ SolarwindsAPM = SolarWindsAPM
33
+ Solarwindsapm = SolarWindsAPM
@@ -1,8 +1,6 @@
1
1
  # Copyright (c) 2016 SolarWinds, LLC.
2
2
  # All rights reserved.
3
3
 
4
- require_relative 'support/transaction_settings'
5
-
6
4
  module SolarWindsAPM
7
5
  ##
8
6
  # This module exposes a nested configuration hash that can be used to
@@ -12,29 +10,22 @@ module SolarWindsAPM
12
10
  #
13
11
  module Config
14
12
  @@config = {}
15
-
16
13
  @@instrumentation = [:action_controller, :action_controller_api, :action_view,
17
14
  :active_record, :bunnyclient, :bunnyconsumer, :curb,
18
15
  :dalli, :delayed_jobclient, :delayed_jobworker,
19
16
  :excon, :faraday, :graphql, :grpc_client, :grpc_server, :grape,
20
17
  :httpclient, :nethttp, :memcached, :mongo, :moped, :padrino, :rack, :redis,
21
18
  :resqueclient, :resqueworker, :rest_client,
22
- :sequel, :sidekiqclient, :sidekiqworker, :sinatra, :typhoeus]
23
-
24
- # ignore configs for instrumentations we don't have anymore
25
- # can't remove because the config may still be present in configs created
26
- # with previous gem versions
27
- @@ignore = [:em_http_request]
28
-
29
- # Subgrouping of instrumentation
30
- @@http_clients = [:curb, :excon,
31
- :faraday, :httpclient, :nethttp, :rest_client, :typhoeus]
19
+ :sequel, :sidekiqclient, :sidekiqworker, :sinatra, :typhoeus,
20
+ :curb, :excon, :faraday, :httpclient, :nethttp, :rest_client, :typhoeus]
32
21
 
33
22
  ##
34
23
  # load_config_file
35
24
  #
36
25
  # There are 3 possible locations for the config file:
37
26
  # Rails default, ENV['SW_APM_CONFIG_RUBY'], or the gem's default
27
+ # Config will be used in OboeInitOptions but ENV variable has higher priority
28
+ # e.g. ENV['SW_APM_SERVICE_KEY'] || SolarWindsAPM::Config[:service_key]
38
29
  #
39
30
  # Hierarchie:
40
31
  # 1 - Rails default: config/initializers/solarwinds_apm.rb
@@ -50,54 +41,35 @@ module SolarWindsAPM
50
41
  config_files << config_file if File.exist?(config_file)
51
42
 
52
43
  # Check for file set by env variable
53
- if ENV.key?('SW_APM_CONFIG_RUBY')
54
- if File.exist?(ENV['SW_APM_CONFIG_RUBY']) && !File.directory?(ENV['SW_APM_CONFIG_RUBY'])
55
- config_files << ENV['SW_APM_CONFIG_RUBY']
56
- elsif File.exist?(File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb'))
57
- config_files << File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb')
58
- else
59
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] Could not find the configuration file set by the SW_APM_CONFIG_RUBY environment variable: #{ENV['SW_APM_CONFIG_RUBY']}"
60
- end
61
- end
44
+ config_files << config_from_env if ENV.has_key?('SW_APM_CONFIG_RUBY')
62
45
 
63
46
  # Check for default config file
64
47
  config_file = File.join(Dir.pwd, 'solarwinds_apm_config.rb')
65
48
  config_files << config_file if File.exist?(config_file)
66
49
 
67
- unless config_files.empty? # we use the defaults from the template if there are no config files
68
- if config_files.size > 1
69
- SolarWindsAPM.logger.warn [
70
- '[solarwinds_apm/config] Multiple configuration files configured, using the first one listed: ',
71
- config_files.join(', ')
72
- ].join(' ')
73
- end
74
- load(config_files[0])
75
- end
50
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Multiple configuration files configured, using the first one listed: #{config_files.join(', ')}"} if config_files.size > 1
51
+ load(config_files[0]) if config_files.size > 0
76
52
 
77
- # sets SolarWindsAPM::Config[:debug_level], SolarWindsAPM.logger.level
78
- set_log_level
53
+ set_log_level # sets SolarWindsAPM::Config[:debug_level], SolarWindsAPM.logger.level
54
+ end
79
55
 
80
- # the verbose setting is only relevant for ruby, ENV['SW_APM_GEM_VERBOSE'] overrides
81
- if ENV.key?('SW_APM_GEM_VERBOSE')
82
- SolarWindsAPM::Config[:verbose] = ENV['SW_APM_GEM_VERBOSE'].downcase == 'true'
56
+ def self.config_from_env
57
+ if File.exist?(ENV['SW_APM_CONFIG_RUBY']) && !File.directory?(ENV['SW_APM_CONFIG_RUBY'])
58
+ config_file = ENV['SW_APM_CONFIG_RUBY']
59
+ elsif File.exist?(File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb'))
60
+ config_file = File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb')
61
+ else
62
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Could not find the configuration file set by the SW_APM_CONFIG_RUBY environment variable: #{ENV['SW_APM_CONFIG_RUBY']}"}
83
63
  end
64
+ config_file
84
65
  end
85
66
 
86
67
  def self.set_log_level
87
- unless (-1..6).include?(SolarWindsAPM::Config[:debug_level])
88
- SolarWindsAPM::Config[:debug_level] = 3
89
- end
68
+ SolarWindsAPM::Config[:debug_level] = 3 unless (-1..6).include?(SolarWindsAPM::Config[:debug_level])
90
69
 
91
70
  # let's find and use the equivalent debug level for ruby
92
71
  debug_level = (ENV['SW_APM_DEBUG_LEVEL'] || SolarWindsAPM::Config[:debug_level] || 3).to_i
93
- if debug_level < 0
94
- # there should be no logging if SW_APM_DEBUG_LEVEL == -1
95
- # In Ruby level 5 is UNKNOWN and it can log, but level 6 is quiet
96
- SolarWindsAPM.logger.level = 6
97
- else
98
- SolarWindsAPM.logger.level = [4 - debug_level, 0].max
99
- end
100
- SolarWindsAPM::Config[:debug_level] = debug_level
72
+ SolarWindsAPM.logger.level = debug_level < 0 ? 6 : [4 - debug_level, 0].max
101
73
  end
102
74
 
103
75
  ##
@@ -107,32 +79,10 @@ module SolarWindsAPM
107
79
  # to create an output similar to the content of the config file
108
80
  #
109
81
  def self.print_config
110
- SolarWindsAPM.logger.warn "# General configurations"
111
- non_instrumentation = @@config.keys - @@instrumentation
112
- non_instrumentation.each do |config|
113
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:#{config}] = #{@@config[config]}"
82
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] General configurations list blow:"}
83
+ @@config.each do |k,v|
84
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Config Key/Value: #{k}, #{v.inspect}"}
114
85
  end
115
-
116
- SolarWindsAPM.logger.warn "\n# Instrumentation specific configurations"
117
- SolarWindsAPM.logger.warn "# Enabled/Disabled Instrumentation"
118
- @@instrumentation.each do |config|
119
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:#{config}][:enabled] = #{@@config[config][:enabled]}"
120
- end
121
-
122
- SolarWindsAPM.logger.warn "\n# Enabled/Disabled Backtrace Collection"
123
- @@instrumentation.each do |config|
124
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:#{config}][:collect_backtraces] = #{@@config[config][:collect_backtraces]}"
125
- end
126
-
127
- SolarWindsAPM.logger.warn "\n# Logging of outgoing HTTP query args"
128
- @@instrumentation.each do |config|
129
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:#{config}][:log_args] = #{@@config[config][:log_args] || false}"
130
- end
131
-
132
- SolarWindsAPM.logger.warn "\n# Bunny Controller and Action"
133
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:bunnyconsumer][:controller] = #{@@config[:bunnyconsumer][:controller].inspect}"
134
- SolarWindsAPM.logger.warn "SolarWindsAPM::Config[:bunnyconsumer][:action] = #{@@config[:bunnyconsumer][:action].inspect}"
135
- nil
136
86
  end
137
87
 
138
88
  ##
@@ -141,20 +91,15 @@ module SolarWindsAPM
141
91
  # Initializer method to set everything up with a default configuration.
142
92
  # The defaults are read from the template configuration file.
143
93
  #
144
- # rubocop:disable Metrics/AbcSize
145
- def self.initialize(_data = {})
146
- (@@instrumentation+@@ignore).each { |k| @@config[k] = {} }
94
+ def self.initialize(_data={})
95
+ # for config file backward compatibility
96
+ @@instrumentation.each {|inst| @@config[inst] = {}}
147
97
  @@config[:transaction_name] = {}
148
98
 
149
- @@config[:profiling] = :disabled
150
- @@config[:profiling_interval] = 5
151
-
152
99
  # Always load the template, it has all the keys and defaults defined,
153
100
  # no guarantee of completeness in the user's config file
154
- load(File.join(File.dirname(File.dirname(__FILE__)),
155
- 'rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb'))
101
+ load(File.join(File.dirname(File.dirname(__FILE__)), 'rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb'))
156
102
  end
157
- # rubocop:enable Metrics/AbcSize
158
103
 
159
104
  def self.update!(data)
160
105
  data.each do |key, value|
@@ -167,11 +112,6 @@ module SolarWindsAPM
167
112
  end
168
113
 
169
114
  def self.[](key)
170
- if key == :resque
171
- SolarWindsAPM.logger.warn '[solarwinds_apm/warn] :resque config is deprecated. It is now split into :resqueclient and :resqueworker.'
172
- SolarWindsAPM.logger.warn "[solarwinds_apm/warn] Called from #{Kernel.caller[0]}"
173
- end
174
-
175
115
  @@config[key.to_sym]
176
116
  end
177
117
 
@@ -181,129 +121,116 @@ module SolarWindsAPM
181
121
  # Config variable assignment method. Here we validate and store the
182
122
  # assigned value(s) and trigger any secondary action needed.
183
123
  #
184
- # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
185
124
  def self.[]=(key, value)
186
125
  key = key.to_sym
187
126
  @@config[key] = value
188
127
 
189
- if key == :sampling_rate
190
- SolarWindsAPM.logger.warn '[solarwinds_apm/config] sampling_rate is not a supported setting for SolarWindsAPM::Config. ' \
191
- 'Please use :sample_rate.'
128
+ case key
129
+ when :sampling_rate
130
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] sampling_rate is not a supported setting for SolarWindsAPM::Config. Please use :sample_rate."}
192
131
 
193
- elsif key == :sample_rate
132
+ when :sample_rate
194
133
  unless value.is_a?(Integer) || value.is_a?(Float)
195
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :sample_rate must be a number between 0 and 1000000 (1m) " \
196
- "(provided: #{value}), corrected to 0"
134
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] :sample_rate must be a number between 0 and 1000000 (1m) (provided: #{value}), corrected to 0"}
197
135
  value = 0
198
136
  end
199
137
 
200
138
  # Validate :sample_rate value
201
139
  unless value.between?(0, 1e6)
202
- value_1 = value
203
- value = value_1 < 0 ? 0 : 1_000_000
204
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :sample_rate must be between 0 and 1000000 (1m) " \
205
- "(provided: #{value_1}), corrected to #{value}"
140
+ new_value = value < 0 ? 0 : 1_000_000
141
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] :sample_rate must be between 0 and 1000000 (1m) (provided: #{value}), corrected to #{new_value}"}
206
142
  end
207
143
 
208
144
  # Assure value is an integer
209
- @@config[key.to_sym] = value.to_i
210
- SolarWindsAPM.set_sample_rate(value) if SolarWindsAPM.loaded
145
+ @@config[key.to_sym] = new_value.to_i
146
+ SolarWindsAPM.sample_rate(new_value) if SolarWindsAPM.loaded
211
147
 
212
- elsif key == :action_blacklist
213
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :action_blacklist has been deprecated and no longer functions."
148
+ when :transaction_settings
149
+ compile_settings(value)
214
150
 
215
- elsif key == :blacklist
216
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :blacklist has been deprecated and no longer functions."
151
+ 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
217
155
 
218
- elsif key == :dnt_regexp
219
- if value.nil? || value == ''
220
- @@config[:dnt_compiled] = nil
156
+ when :tag_sql
157
+ if ENV.has_key?('SW_APM_TAG_SQL')
158
+ @@config[key.to_sym] = (ENV['SW_APM_TAG_SQL'] == 'true')
221
159
  else
222
- @@config[:dnt_compiled] =
223
- Regexp.new(SolarWindsAPM::Config[:dnt_regexp], SolarWindsAPM::Config[:dnt_opts] || nil)
224
- end
225
-
226
- elsif key == :dnt_opts
227
- if SolarWindsAPM::Config[:dnt_regexp] && SolarWindsAPM::Config[:dnt_regexp] != ''
228
- @@config[:dnt_compiled] =
229
- Regexp.new(SolarWindsAPM::Config[:dnt_regexp], SolarWindsAPM::Config[:dnt_opts] || nil)
160
+ @@config[key.to_sym] = value
230
161
  end
231
162
 
232
- elsif key == :profiling
233
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] Profiling feature is currently not available."
234
- @@config[:profiling] = :disabled
163
+ else
164
+ @@config[key.to_sym] = value
235
165
 
236
- elsif key == :profiling_interval
237
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] Profiling feature is currently not available. :profiling_interval setting is not configured."
238
- if value.is_a?(Integer) && value > 0
239
- value = [100, value].min
240
- else
241
- value = 10
242
- end
243
- @@config[:profiling_interval] = value
244
- # CProfiler may not be loaded yet, the profiler will send the value
245
- # after it is loaded
246
- SolarWindsAPM::CProfiler.set_interval(value) if defined? SolarWindsAPM::CProfiler
247
-
248
- elsif key == :transaction_settings
249
- if value.is_a?(Hash)
250
- SolarWindsAPM::TransactionSettings.compile_url_settings(value[:url])
251
- else
252
- SolarWindsAPM::TransactionSettings.reset_url_regexps
253
- end
166
+ end
167
+ end
254
168
 
255
- elsif key == :resque
256
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :resque config is deprecated. It is now split into :resqueclient and :resqueworker."
257
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] Called from #{Kernel.caller[0]}"
169
+ ####### Below are private methods are not customer facing #######
258
170
 
259
- elsif key == :include_url_query_params # DEPRECATED
260
- # Obey the global flag and update all of the per instrumentation
261
- # <tt>:log_args</tt> values.
262
- @@config[:rack][:log_args] = value
171
+ def self.compile_settings(settings)
172
+ if !settings.is_a?(Array) || settings.empty?
173
+ reset_regexps
174
+ return
175
+ end
263
176
 
264
- elsif key == :include_remote_url_params # DEPRECATED
265
- # Obey the global flag and update all of the per instrumentation
266
- # <tt>:log_args</tt> values.
267
- @@http_clients.each do |i|
268
- @@config[i][:log_args] = value
269
- end
177
+ # `tracing: disabled` is the default
178
+ disabled = settings.select { |v| !v.has_key?(:tracing) || v[:tracing] == :disabled }
179
+ enabled = settings.select { |v| v[:tracing] == :enabled }
270
180
 
271
- elsif key == :tracing_mode
272
- # CAN'T DO `set_tracing_mode` ANYMORE, ALL TRACING COMMUNICATION TO OBOE
273
- # IS NOW HANDLED BY TransactionSettings
274
- # SolarWindsAPM.set_tracing_mode(value.to_sym) if SolarWindsAPM.loaded
181
+ SolarWindsAPM::Config[:enabled_regexps] = compile_regexp(enabled)
182
+ SolarWindsAPM::Config[:disabled_regexps] = compile_regexp(disabled)
183
+ end
184
+ private_class_method :compile_settings
275
185
 
276
- # Make sure that the mode is stored as a symbol
277
- @@config[key.to_sym] = value.to_sym
186
+ def self.compile_regexp(settings)
187
+ regexp_regexp = compile_settings_regexp(settings)
188
+ extensions_regexp = compile_settings_extensions(settings)
278
189
 
279
- elsif key == :trigger_tracing_mode
280
- # Make sure that the mode is stored as a symbol
281
- @@config[key.to_sym] = value.to_sym
190
+ regexps = [regexp_regexp, extensions_regexp].flatten.compact
282
191
 
283
- end
192
+ regexps.empty? ? nil : regexps
284
193
  end
285
- # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
194
+ private_class_method :compile_regexp
286
195
 
287
- def self.method_missing(sym, *args)
288
- class_var_name = "@@#{sym}"
289
-
290
- if sym.to_s =~ /(.+)=$/
291
- self[$1] = args.first
292
- else
293
- # Try part of the @@config hash first
294
- if @@config.key?(sym)
295
- self[sym]
296
-
297
- # Then try as a class variable
298
- elsif self.class_variable_defined?(class_var_name.to_sym)
299
- self.class_eval(class_var_name)
196
+ def self.compile_settings_regexp(value)
197
+ regexps = value.select do |v|
198
+ v.has_key?(:regexp) &&
199
+ !(v[:regexp].is_a?(String) && v[:regexp].empty?) &&
200
+ !(v[:regexp].is_a?(Regexp) && v[:regexp].inspect == '//')
201
+ end
300
202
 
301
- # Congrats - You've won a brand new nil...
302
- else
203
+ regexps.map! do |v|
204
+ begin
205
+ v[:regexp].is_a?(String) ? Regexp.new(v[:regexp], v[:opts]) : Regexp.new(v[:regexp])
206
+ rescue StandardError => e
207
+ SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] Problem compiling transaction_settings item #{v}, will ignore. Error: #{e.message}"}
303
208
  nil
304
209
  end
305
210
  end
211
+ regexps.keep_if { |v| !v.nil? }
212
+ regexps.empty? ? nil : regexps
213
+ end
214
+ private_class_method :compile_settings_regexp
215
+
216
+ def self.compile_settings_extensions(value)
217
+ extensions = value.select do |v|
218
+ v.has_key?(:extensions) &&
219
+ v[:extensions].is_a?(Array) &&
220
+ !v[:extensions].empty?
221
+ end
222
+ extensions = extensions.map { |v| v[:extensions] }.flatten
223
+ extensions.keep_if { |v| v.is_a?(String) }
224
+
225
+ extensions.empty? ? nil : Regexp.new("(#{Regexp.union(extensions).source})(\\?.+){0,1}$")
226
+ end
227
+ private_class_method :compile_settings_extensions
228
+
229
+ def self.reset_regexps
230
+ SolarWindsAPM::Config[:enabled_regexps] = nil
231
+ SolarWindsAPM::Config[:disabled_regexps] = nil
306
232
  end
233
+ private_class_method :reset_regexps
307
234
  end
308
235
  end
309
236
 
@@ -0,0 +1,32 @@
1
+ module SolarWindsAPM
2
+ # Constants
3
+ module Constants
4
+ HTTP_METHOD = "http.method".freeze
5
+ HTTP_ROUTE = "http.route".freeze
6
+ HTTP_STATUS_CODE = "http.status_code".freeze
7
+ HTTP_URL = "http.url".freeze
8
+
9
+ INTL_SWO_AO_COLLECTOR = "collector.appoptics.com".freeze
10
+ INTL_SWO_AO_STG_COLLECTOR = "collector-stg.appoptics.com".freeze
11
+ INTL_SWO_COMMA = ",".freeze
12
+ INTL_SWO_COMMA_W3C_SANITIZED = "....".freeze
13
+ INTL_SWO_EQUALS = "=".freeze
14
+ INTL_SWO_EQUALS_W3C_SANITIZED = "####".freeze
15
+ INTL_SWO_TRACESTATE_KEY = "sw".freeze
16
+ INTL_SWO_X_OPTIONS_KEY = "sw_xtraceoptions".freeze
17
+ INTL_SWO_SIGNATURE_KEY = "sw_signature".freeze
18
+ INTL_SWO_DEFAULT_TRACES_EXPORTER = "solarwinds_exporter".freeze
19
+ INTL_SWO_TRACECONTEXT_PROPAGATOR = "tracecontext".freeze
20
+ INTL_SWO_PROPAGATOR = "solarwinds_propagator".freeze
21
+ INTL_SWO_DEFAULT_PROPAGATORS = [INTL_SWO_TRACECONTEXT_PROPAGATOR, "baggage",INTL_SWO_PROPAGATOR].freeze
22
+ INTL_SWO_SUPPORT_EMAIL = "SWO-support@solarwinds.com".freeze
23
+ INTL_SWO_CURRENT_SPAN_ID = "sw-current-entry-span-id".freeze
24
+ INTL_SWO_CURRENT_TRACE_ID = "sw-current-trace-id".freeze
25
+ INTL_SWO_CURRENT_TRACE_FLAG = "sw-current-trace-flag".freeze
26
+
27
+ INTL_SWO_OTEL_SCOPE_NAME = "otel.scope.name".freeze
28
+ INTL_SWO_OTEL_SCOPE_VERSION = "otel.scope.version".freeze
29
+
30
+ INTERNAL_TRIGGERED_TRACE = "TriggeredTrace".freeze
31
+ end
32
+ end
@@ -9,6 +9,6 @@ module SolarWindsAPM
9
9
  end
10
10
  end
11
11
 
12
- SolarWindsAPM.logger = Logger.new(STDERR)
12
+ SolarWindsAPM.logger = Logger.new($stderr)
13
13
  # set log level to INFO to be consistent with the c-lib, DEBUG would be default
14
14
  SolarWindsAPM.logger.level = Logger::INFO
@@ -4,11 +4,9 @@
4
4
  ####
5
5
  # noop version of SolarWindsAPM::Context
6
6
  #
7
- #
8
-
9
7
  module SolarWindsAPM
8
+ # Context for noop
10
9
  module Context
11
-
12
10
  ##
13
11
  # noop version of :toString
14
12
  # toString would return the current trace context as string
@@ -20,7 +18,6 @@ module SolarWindsAPM
20
18
  ##
21
19
  # noop version of :clear
22
20
  #
23
- def self.clear
24
- end
21
+ def self.clear; end
25
22
  end
26
23
  end
@@ -5,10 +5,9 @@
5
5
  # noop version of SolarWindsAPM::Metadata
6
6
  #
7
7
  #
8
-
9
8
  module SolarWindsAPM
9
+ # Metadata
10
10
  class Metadata
11
-
12
11
  ##
13
12
  # noop version of :makeRandom
14
13
  #