solarwinds_apm 5.1.8 → 6.0.0.preV1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -1
  3. data/ext/oboe_metal/extconf.rb +19 -23
  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/oboe_api.cpp +9 -7
  10. data/ext/oboe_metal/src/oboe_api.h +7 -7
  11. data/ext/oboe_metal/src/oboe_debug.h +2 -0
  12. data/ext/oboe_metal/src/oboe_swig_wrap.cc +19 -18
  13. data/lib/oboe_metal.rb +116 -80
  14. data/lib/rails/generators/solarwinds_apm/install_generator.rb +1 -2
  15. data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +44 -260
  16. data/lib/solarwinds_apm/api/current_trace_info.rb +148 -0
  17. data/lib/solarwinds_apm/api/tracing.rb +30 -0
  18. data/lib/solarwinds_apm/api/transaction_name.rb +57 -0
  19. data/lib/solarwinds_apm/api.rb +8 -15
  20. data/lib/solarwinds_apm/base.rb +4 -131
  21. data/lib/solarwinds_apm/config.rb +128 -175
  22. data/lib/solarwinds_apm/constants.rb +32 -0
  23. data/lib/solarwinds_apm/logger.rb +1 -1
  24. data/lib/solarwinds_apm/noop/context.rb +2 -5
  25. data/lib/solarwinds_apm/noop/metadata.rb +1 -2
  26. data/lib/solarwinds_apm/noop/profiling.rb +3 -7
  27. data/lib/solarwinds_apm/oboe_init_options.rb +71 -33
  28. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +204 -0
  29. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +163 -0
  30. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +92 -0
  31. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +72 -0
  32. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +330 -0
  33. data/lib/solarwinds_apm/opentelemetry.rb +8 -0
  34. data/lib/solarwinds_apm/otel_config.rb +161 -0
  35. data/lib/solarwinds_apm/{inst → support}/logger_formatter.rb +5 -6
  36. data/lib/solarwinds_apm/{inst → support}/logging_log_event.rb +3 -6
  37. data/lib/solarwinds_apm/{inst → support}/lumberjack_formatter.rb +1 -4
  38. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +27 -0
  39. data/lib/solarwinds_apm/support/swomarginalia/LICENSE +20 -0
  40. data/lib/solarwinds_apm/support/swomarginalia/README.md +41 -0
  41. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +205 -0
  42. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +48 -0
  43. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +22 -0
  44. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +86 -0
  45. data/lib/solarwinds_apm/support/transaction_cache.rb +24 -0
  46. data/lib/solarwinds_apm/support/transaction_settings.rb +26 -209
  47. data/lib/solarwinds_apm/support/transformer.rb +56 -0
  48. data/lib/solarwinds_apm/support/txn_name_manager.rb +25 -0
  49. data/lib/solarwinds_apm/support/x_trace_options.rb +42 -26
  50. data/lib/solarwinds_apm/support.rb +33 -10
  51. data/lib/solarwinds_apm/support_report.rb +10 -32
  52. data/lib/solarwinds_apm/thread_local.rb +1 -1
  53. data/lib/solarwinds_apm/version.rb +4 -4
  54. data/lib/solarwinds_apm.rb +31 -26
  55. metadata +76 -121
  56. data/.dockerignore +0 -5
  57. data/.gitignore +0 -58
  58. data/.rubocop.yml +0 -29
  59. data/.whitesource +0 -22
  60. data/.yardopts +0 -7
  61. data/CHANGELOG-appoptics.md +0 -766
  62. data/CHANGELOG.md +0 -72
  63. data/CONFIG.md +0 -31
  64. data/Gemfile +0 -15
  65. data/README.md +0 -385
  66. data/bin/solarwinds_apm_config +0 -15
  67. data/examples/prepend.rb +0 -13
  68. data/examples/sdk_examples.rb +0 -158
  69. data/ext/oboe_metal/README.md +0 -69
  70. data/ext/oboe_metal/extconf_local.rb +0 -75
  71. data/ext/oboe_metal/lib/.keep +0 -0
  72. data/ext/oboe_metal/noop/noop.c +0 -8
  73. data/ext/oboe_metal/src/README.md +0 -6
  74. data/ext/oboe_metal/src/frames.cc +0 -247
  75. data/ext/oboe_metal/src/frames.h +0 -40
  76. data/ext/oboe_metal/src/logging.cc +0 -97
  77. data/ext/oboe_metal/src/logging.h +0 -34
  78. data/ext/oboe_metal/src/profiling.cc +0 -435
  79. data/ext/oboe_metal/src/profiling.h +0 -78
  80. data/ext/oboe_metal/test/CMakeLists.txt +0 -53
  81. data/ext/oboe_metal/test/FindGMock.cmake +0 -43
  82. data/ext/oboe_metal/test/README.md +0 -56
  83. data/ext/oboe_metal/test/frames_test.cc +0 -164
  84. data/ext/oboe_metal/test/profiling_test.cc +0 -93
  85. data/ext/oboe_metal/test/ruby_inc_dir.rb +0 -8
  86. data/ext/oboe_metal/test/ruby_prefix.rb +0 -8
  87. data/ext/oboe_metal/test/ruby_test_helper.rb +0 -67
  88. data/ext/oboe_metal/test/test.h +0 -11
  89. data/ext/oboe_metal/test/test_main.cc +0 -32
  90. data/init.rb +0 -4
  91. data/lib/solarwinds_apm/api/layerinit.rb +0 -41
  92. data/lib/solarwinds_apm/api/logging.rb +0 -356
  93. data/lib/solarwinds_apm/api/memcache.rb +0 -37
  94. data/lib/solarwinds_apm/api/metrics.rb +0 -63
  95. data/lib/solarwinds_apm/api/util.rb +0 -98
  96. data/lib/solarwinds_apm/frameworks/grape.rb +0 -96
  97. data/lib/solarwinds_apm/frameworks/padrino.rb +0 -78
  98. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller.rb +0 -100
  99. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller5.rb +0 -50
  100. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller_api.rb +0 -50
  101. data/lib/solarwinds_apm/frameworks/rails/inst/action_view.rb +0 -88
  102. data/lib/solarwinds_apm/frameworks/rails/inst/active_record.rb +0 -26
  103. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +0 -29
  104. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +0 -22
  105. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +0 -103
  106. data/lib/solarwinds_apm/frameworks/rails/inst/logger_formatters.rb +0 -14
  107. data/lib/solarwinds_apm/frameworks/rails.rb +0 -100
  108. data/lib/solarwinds_apm/frameworks/sinatra.rb +0 -96
  109. data/lib/solarwinds_apm/inst/bunny-client.rb +0 -157
  110. data/lib/solarwinds_apm/inst/bunny-consumer.rb +0 -102
  111. data/lib/solarwinds_apm/inst/curb.rb +0 -289
  112. data/lib/solarwinds_apm/inst/dalli.rb +0 -89
  113. data/lib/solarwinds_apm/inst/delayed_job.rb +0 -100
  114. data/lib/solarwinds_apm/inst/excon.rb +0 -113
  115. data/lib/solarwinds_apm/inst/faraday.rb +0 -96
  116. data/lib/solarwinds_apm/inst/graphql.rb +0 -206
  117. data/lib/solarwinds_apm/inst/grpc_client.rb +0 -147
  118. data/lib/solarwinds_apm/inst/grpc_server.rb +0 -119
  119. data/lib/solarwinds_apm/inst/httpclient.rb +0 -182
  120. data/lib/solarwinds_apm/inst/memcached.rb +0 -86
  121. data/lib/solarwinds_apm/inst/mongo.rb +0 -246
  122. data/lib/solarwinds_apm/inst/mongo2.rb +0 -225
  123. data/lib/solarwinds_apm/inst/moped.rb +0 -466
  124. data/lib/solarwinds_apm/inst/net_http.rb +0 -60
  125. data/lib/solarwinds_apm/inst/rack.rb +0 -223
  126. data/lib/solarwinds_apm/inst/rack_cache.rb +0 -35
  127. data/lib/solarwinds_apm/inst/redis.rb +0 -280
  128. data/lib/solarwinds_apm/inst/redis_v4.rb +0 -273
  129. data/lib/solarwinds_apm/inst/resque.rb +0 -129
  130. data/lib/solarwinds_apm/inst/rest-client.rb +0 -43
  131. data/lib/solarwinds_apm/inst/sequel.rb +0 -241
  132. data/lib/solarwinds_apm/inst/sidekiq-client.rb +0 -63
  133. data/lib/solarwinds_apm/inst/sidekiq-worker.rb +0 -64
  134. data/lib/solarwinds_apm/inst/typhoeus.rb +0 -90
  135. data/lib/solarwinds_apm/instrumentation.rb +0 -22
  136. data/lib/solarwinds_apm/loading.rb +0 -65
  137. data/lib/solarwinds_apm/ruby.rb +0 -35
  138. data/lib/solarwinds_apm/sdk/current_trace_info.rb +0 -123
  139. data/lib/solarwinds_apm/sdk/custom_metrics.rb +0 -94
  140. data/lib/solarwinds_apm/sdk/logging.rb +0 -37
  141. data/lib/solarwinds_apm/sdk/trace_context_headers.rb +0 -69
  142. data/lib/solarwinds_apm/sdk/tracing.rb +0 -432
  143. data/lib/solarwinds_apm/support/profiling.rb +0 -25
  144. data/lib/solarwinds_apm/support/trace_context.rb +0 -53
  145. data/lib/solarwinds_apm/support/trace_state.rb +0 -69
  146. data/lib/solarwinds_apm/support/trace_string.rb +0 -89
  147. data/lib/solarwinds_apm/support/transaction_metrics.rb +0 -67
  148. data/lib/solarwinds_apm/test.rb +0 -165
  149. data/lib/solarwinds_apm/util.rb +0 -426
  150. data/log/.keep +0 -0
  151. data/log/postgresql/.keep +0 -0
  152. data/solarwinds_apm.gemspec +0 -55
  153. data/yardoc_frontpage.md +0 -24
@@ -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
- :active_record, :bunnyclient, :bunnyconsumer, :curb,
18
- :dalli, :delayed_jobclient, :delayed_jobworker,
19
- :excon, :faraday, :graphql, :grpc_client, :grpc_server, :grape,
20
- :httpclient, :nethttp, :memcached, :mongo, :moped, :padrino, :rack, :redis,
21
- :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]
14
+ :active_record, :bunnyclient, :bunnyconsumer, :curb,
15
+ :dalli, :delayed_jobclient, :delayed_jobworker,
16
+ :excon, :faraday, :graphql, :grpc_client, :grpc_server, :grape,
17
+ :httpclient, :nethttp, :memcached, :mongo, :moped, :padrino, :rack, :redis,
18
+ :resqueclient, :resqueworker, :rest_client,
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,42 @@ 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 {"[#{self.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
+ set_verbose_level # the verbose setting is only relevant for ruby, ENV['SW_APM_GEM_VERBOSE'] overrides
55
+ end
79
56
 
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'
57
+ def self.config_from_env
58
+ config_files = []
59
+ if File.exist?(ENV['SW_APM_CONFIG_RUBY']) && !File.directory?(ENV['SW_APM_CONFIG_RUBY'])
60
+ config_files << ENV['SW_APM_CONFIG_RUBY']
61
+ elsif File.exist?(File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb'))
62
+ config_files << File.join(ENV['SW_APM_CONFIG_RUBY'], 'solarwinds_apm_config.rb')
63
+ else
64
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] Could not find the configuration file set by the SW_APM_CONFIG_RUBY environment variable: #{ENV['SW_APM_CONFIG_RUBY']}"}
83
65
  end
66
+ config_files
67
+ end
68
+
69
+ def self.set_verbose_level
70
+ verbose = ENV.has_key?('SW_APM_GEM_VERBOSE')? ENV['SW_APM_GEM_VERBOSE'].downcase == 'true' : nil
71
+ SolarWindsAPM::Config[:verbose] = verbose
84
72
  end
85
73
 
86
74
  def self.set_log_level
87
- unless (-1..6).include?(SolarWindsAPM::Config[:debug_level])
88
- SolarWindsAPM::Config[:debug_level] = 3
89
- end
75
+ SolarWindsAPM::Config[:debug_level] = 3 unless (-1..6).include?(SolarWindsAPM::Config[:debug_level])
90
76
 
91
77
  # let's find and use the equivalent debug level for ruby
92
78
  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
79
+ SolarWindsAPM.logger.level = debug_level < 0 ? 6 : [4 - debug_level, 0].max
101
80
  end
102
81
 
103
82
  ##
@@ -107,32 +86,10 @@ module SolarWindsAPM
107
86
  # to create an output similar to the content of the config file
108
87
  #
109
88
  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]}"
114
- 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}"
89
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] General configurations list blow:"}
90
+ @@config.each do |k,v|
91
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] Config Key/Value: #{k}, #{v.inspect}"}
130
92
  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
93
  end
137
94
 
138
95
  ##
@@ -141,20 +98,18 @@ module SolarWindsAPM
141
98
  # Initializer method to set everything up with a default configuration.
142
99
  # The defaults are read from the template configuration file.
143
100
  #
144
- # rubocop:disable Metrics/AbcSize
145
- def self.initialize(_data = {})
146
- (@@instrumentation+@@ignore).each { |k| @@config[k] = {} }
147
- @@config[:transaction_name] = {}
148
-
101
+ def self.initialize(_data={})
149
102
  @@config[:profiling] = :disabled
150
103
  @@config[:profiling_interval] = 5
151
104
 
105
+ # for config file backward compatibility
106
+ @@instrumentation.each {|inst| @@config[inst] = {}}
107
+ @@config[:transaction_name] = {}
108
+
152
109
  # Always load the template, it has all the keys and defaults defined,
153
110
  # 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'))
111
+ load(File.join(File.dirname(File.dirname(__FILE__)), 'rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb'))
156
112
  end
157
- # rubocop:enable Metrics/AbcSize
158
113
 
159
114
  def self.update!(data)
160
115
  data.each do |key, value|
@@ -167,11 +122,6 @@ module SolarWindsAPM
167
122
  end
168
123
 
169
124
  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
125
  @@config[key.to_sym]
176
126
  end
177
127
 
@@ -181,129 +131,132 @@ module SolarWindsAPM
181
131
  # Config variable assignment method. Here we validate and store the
182
132
  # assigned value(s) and trigger any secondary action needed.
183
133
  #
184
- # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
185
134
  def self.[]=(key, value)
186
135
  key = key.to_sym
187
136
  @@config[key] = value
188
137
 
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.'
138
+ case key
139
+ when :sampling_rate
140
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] sampling_rate is not a supported setting for SolarWindsAPM::Config. Please use :sample_rate."}
192
141
 
193
- elsif key == :sample_rate
142
+ when :sample_rate
194
143
  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"
144
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] :sample_rate must be a number between 0 and 1000000 (1m) (provided: #{value}), corrected to 0"}
197
145
  value = 0
198
146
  end
199
147
 
200
148
  # Validate :sample_rate value
201
149
  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}"
150
+ new_value = value < 0 ? 0 : 1_000_000
151
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] :sample_rate must be between 0 and 1000000 (1m) (provided: #{value}), corrected to #{new_value}"}
206
152
  end
207
153
 
208
154
  # Assure value is an integer
209
- @@config[key.to_sym] = value.to_i
210
- SolarWindsAPM.set_sample_rate(value) if SolarWindsAPM.loaded
155
+ @@config[key.to_sym] = new_value.to_i
156
+ SolarWindsAPM.sample_rate(new_value) if SolarWindsAPM.loaded
211
157
 
212
- elsif key == :action_blacklist
213
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :action_blacklist has been deprecated and no longer functions."
214
-
215
- elsif key == :blacklist
216
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] :blacklist has been deprecated and no longer functions."
217
-
218
- elsif key == :dnt_regexp
219
- if value.nil? || value == ''
220
- @@config[:dnt_compiled] = nil
221
- 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)
230
- end
231
-
232
- elsif key == :profiling
233
- SolarWindsAPM.logger.warn "[solarwinds_apm/config] Profiling feature is currently not available."
158
+ when :profiling
159
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] Profiling feature is currently not available." }
234
160
  @@config[:profiling] = :disabled
235
161
 
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
162
+ when :profiling_interval
163
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] Profiling feature is currently not available. :profiling_interval setting is not configured."}
164
+ value = if value.is_a?(Integer) && value > 0
165
+ [100, value].min
166
+ else
167
+ 10
168
+ end
243
169
  @@config[:profiling_interval] = value
244
170
  # CProfiler may not be loaded yet, the profiler will send the value
245
171
  # 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
172
+ SolarWindsAPM::CProfiler.interval_setup(value) if defined? SolarWindsAPM::CProfiler
254
173
 
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]}"
174
+ when :transaction_settings
175
+ compile_settings(value)
258
176
 
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
177
+ when :tracing_mode
178
+ # ALL TRACING COMMUNICATION TO OBOE IS NOW HANDLED BY TransactionSettings
179
+ # Make sure that the mode is stored as a symbol
180
+ @@config[key.to_sym] = value.to_sym
263
181
 
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
182
+ when :tag_sql
183
+ if ENV.has_key?('SW_APM_TAG_SQL')
184
+ @@config[key.to_sym] = (ENV['SW_APM_TAG_SQL'] == 'true')
185
+ else
186
+ @@config[key.to_sym] = value
269
187
  end
270
188
 
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
189
+ else
190
+ @@config[key.to_sym] = value
275
191
 
276
- # Make sure that the mode is stored as a symbol
277
- @@config[key.to_sym] = value.to_sym
192
+ end
193
+ end
278
194
 
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
195
+ ####### Below are private methods are not customer facing #######
282
196
 
197
+ def self.compile_settings(settings)
198
+ if !settings.is_a?(Array) || settings.empty?
199
+ reset_regexps
200
+ return
283
201
  end
202
+
203
+ # `tracing: disabled` is the default
204
+ disabled = settings.select { |v| !v.has_key?(:tracing) || v[:tracing] == :disabled }
205
+ enabled = settings.select { |v| v[:tracing] == :enabled }
206
+
207
+ SolarWindsAPM::Config[:enabled_regexps] = compile_regexp(enabled)
208
+ SolarWindsAPM::Config[:disabled_regexps] = compile_regexp(disabled)
284
209
  end
285
- # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
210
+ private_class_method :compile_settings
286
211
 
287
- def self.method_missing(sym, *args)
288
- class_var_name = "@@#{sym}"
212
+ def self.compile_regexp(settings)
213
+ regexp_regexp = compile_settings_regexp(settings)
214
+ extensions_regexp = compile_settings_extensions(settings)
289
215
 
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]
216
+ regexps = [regexp_regexp, extensions_regexp].flatten.compact
296
217
 
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)
218
+ regexps.empty? ? nil : regexps
219
+ end
220
+ private_class_method :compile_regexp
300
221
 
301
- # Congrats - You've won a brand new nil...
302
- else
222
+ def self.compile_settings_regexp(value)
223
+ regexps = value.select do |v|
224
+ v.has_key?(:regexp) &&
225
+ !(v[:regexp].is_a?(String) && v[:regexp].empty?) &&
226
+ !(v[:regexp].is_a?(Regexp) && v[:regexp].inspect == '//')
227
+ end
228
+
229
+ regexps.map! do |v|
230
+ begin
231
+ v[:regexp].is_a?(String) ? Regexp.new(v[:regexp], v[:opts]) : Regexp.new(v[:regexp])
232
+ rescue StandardError => e
233
+ SolarWindsAPM.logger.warn {"[#{self.name}/#{__method__}] Problem compiling transaction_settings item #{v}, will ignore. Error: #{e.message}"}
303
234
  nil
304
235
  end
305
236
  end
237
+ regexps.keep_if { |v| !v.nil? }
238
+ regexps.empty? ? nil : regexps
239
+ end
240
+ private_class_method :compile_settings_regexp
241
+
242
+ def self.compile_settings_extensions(value)
243
+ extensions = value.select do |v|
244
+ v.has_key?(:extensions) &&
245
+ v[:extensions].is_a?(Array) &&
246
+ !v[:extensions].empty?
247
+ end
248
+ extensions = extensions.map { |v| v[:extensions] }.flatten
249
+ extensions.keep_if { |v| v.is_a?(String) }
250
+
251
+ extensions.empty? ? nil : Regexp.new("(#{Regexp.union(extensions).source})(\\?.+){0,1}$")
252
+ end
253
+ private_class_method :compile_settings_extensions
254
+
255
+ def self.reset_regexps
256
+ SolarWindsAPM::Config[:enabled_regexps] = nil
257
+ SolarWindsAPM::Config[:disabled_regexps] = nil
306
258
  end
259
+ private_class_method :reset_regexps
307
260
  end
308
261
  end
309
262
 
@@ -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
  #
@@ -1,8 +1,6 @@
1
1
  module SolarWindsAPM
2
-
3
2
  # override the Ruby method, so that no code related to profiling gets executed
4
3
  class Profiling
5
-
6
4
  def self.run
7
5
  yield
8
6
  end
@@ -10,12 +8,10 @@ module SolarWindsAPM
10
8
 
11
9
  # these put the c-functions into "noop"
12
10
  module CProfiler
13
- def self.set_interval(_)
14
- # do nothing
15
- end
11
+ def self.interval_setup(_); end
16
12
 
17
- def self.get_tid
18
- return 0
13
+ def self.tid
14
+ 0
19
15
  end
20
16
  end
21
17
  end