solarwinds_apm 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/oboe_metal/extconf.rb +42 -41
  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-lambda-aarch64.so.sha256 +1 -0
  7. data/ext/oboe_metal/lib/liboboe-1.0-lambda-x86_64.so.sha256 +1 -0
  8. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
  9. data/ext/oboe_metal/src/VERSION +1 -1
  10. data/ext/oboe_metal/src/oboe.h +3 -0
  11. data/ext/oboe_metal/src/oboe_api.cpp +1 -1
  12. data/lib/oboe_metal.rb +30 -27
  13. data/lib/rails/generators/solarwinds_apm/install_generator.rb +21 -19
  14. data/lib/solarwinds_apm/api/current_trace_info.rb +16 -9
  15. data/lib/solarwinds_apm/api/custom_metrics.rb +6 -4
  16. data/lib/solarwinds_apm/api/opentelemetry.rb +8 -4
  17. data/lib/solarwinds_apm/api/tracing.rb +6 -4
  18. data/lib/solarwinds_apm/api/transaction_name.rb +21 -11
  19. data/lib/solarwinds_apm/api.rb +7 -5
  20. data/lib/solarwinds_apm/config.rb +70 -46
  21. data/lib/solarwinds_apm/constants.rb +25 -23
  22. data/lib/solarwinds_apm/logger.rb +2 -0
  23. data/lib/solarwinds_apm/noop/api.rb +3 -1
  24. data/lib/solarwinds_apm/noop/context.rb +2 -0
  25. data/lib/solarwinds_apm/noop/metadata.rb +2 -0
  26. data/lib/solarwinds_apm/noop/span.rb +2 -0
  27. data/lib/solarwinds_apm/noop.rb +8 -6
  28. data/lib/solarwinds_apm/oboe_init_options.rb +47 -39
  29. data/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +135 -0
  30. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +66 -41
  31. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +49 -51
  32. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +30 -22
  33. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +29 -16
  34. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +135 -98
  35. data/lib/solarwinds_apm/opentelemetry.rb +8 -5
  36. data/lib/solarwinds_apm/otel_config.rb +32 -25
  37. data/lib/solarwinds_apm/otel_lambda_config.rb +53 -0
  38. data/lib/solarwinds_apm/patch.rb +2 -0
  39. data/lib/solarwinds_apm/support/logger_formatter.rb +4 -2
  40. data/lib/solarwinds_apm/support/logging_log_event.rb +2 -0
  41. data/lib/solarwinds_apm/support/lumberjack_formatter.rb +2 -0
  42. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +2 -0
  43. data/lib/solarwinds_apm/support/service_key_checker.rb +18 -6
  44. data/lib/solarwinds_apm/support/support_report.rb +5 -3
  45. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +18 -17
  46. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +13 -12
  47. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +4 -2
  48. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +3 -1
  49. data/lib/solarwinds_apm/support/transaction_cache.rb +6 -4
  50. data/lib/solarwinds_apm/support/transaction_settings.rb +7 -3
  51. data/lib/solarwinds_apm/support/txn_name_manager.rb +8 -3
  52. data/lib/solarwinds_apm/support/utils.rb +12 -9
  53. data/lib/solarwinds_apm/support/x_trace_options.rb +23 -17
  54. data/lib/solarwinds_apm/support.rb +28 -24
  55. data/lib/solarwinds_apm/version.rb +3 -1
  56. data/lib/solarwinds_apm.rb +44 -34
  57. metadata +14 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dfd38bd4d4e3d70c56b86ffd34d9fe830e0944eb3fd02a82bff26da07900056
4
- data.tar.gz: 1ec9662543689c97af6509f2db2bde6e62bd9274fd2b792925d4ebf9fd46c4fb
3
+ metadata.gz: 0ad230df4c45bce0d25321678bc23a0a5fcfa62e98970e3d1ceda24430716314
4
+ data.tar.gz: bf4556eb3a109b25c8589bd7d4347e34f1475f1be6e86200af88ee604df3ffb0
5
5
  SHA512:
6
- metadata.gz: c90b9be36843bf092833fafc3fc16e6f97cf293787fd9551375b39a67c8f057b737c11145764eb47590b060bc22a60c367911bf8e31b3b5718452ad8b0e50234
7
- data.tar.gz: 29e352eb73da5c09fc0caf35e73e65facb842d7becab500e0183071ec4aaa563daf0ae2bd483972f0ef2e5b51a780821b0075b432d2a86892e82eedc8c4f71ad
6
+ metadata.gz: 8a7b0a9a5cfa5d0276c1fe5f3a52430380e3c4f2b9ecd8dc1426e29eda4aa7a98b245425dba6b574e9180c088e2dbff02239f66e802efd84938aa39502a418dc
7
+ data.tar.gz: b20dd4f228fe7ffbc8415c5f33cede6161232f928d99871023b1340a92ded360c5c776efff355a5e8323486227eb008616963d27492c5aeff315bd8aa4ad6dc3
@@ -7,14 +7,14 @@ require 'mkmf'
7
7
  require 'rbconfig'
8
8
  require 'open-uri'
9
9
 
10
- CONFIG['warnflags'] = CONFIG['warnflags'].gsub(/-Wdeclaration-after-statement/, '')
11
- .gsub(/-Wimplicit-function-declaration/, '')
12
- .gsub(/-Wimplicit-int/, '')
13
- .gsub(/-Wno-tautological-compare/, '')
14
- .gsub(/-Wno-self-assign/, '')
15
- .gsub(/-Wno-parentheses-equality/, '')
16
- .gsub(/-Wno-constant-logical-operand/, '')
17
- .gsub(/-Wno-cast-function-type/, '')
10
+ CONFIG['warnflags'] = CONFIG['warnflags'].gsub('-Wdeclaration-after-statement', '')
11
+ .gsub('-Wimplicit-function-declaration', '')
12
+ .gsub('-Wimplicit-int', '')
13
+ .gsub('-Wno-tautological-compare', '')
14
+ .gsub('-Wno-self-assign', '')
15
+ .gsub('-Wno-parentheses-equality', '')
16
+ .gsub('-Wno-constant-logical-operand', '')
17
+ .gsub('-Wno-cast-function-type', '')
18
18
  init_mkmf(CONFIG)
19
19
 
20
20
  ext_dir = __dir__
@@ -27,7 +27,7 @@ swo_include = File.join(ext_dir, 'src')
27
27
  # Download the appropriate liboboe from Staging or Production
28
28
  version = File.read(File.join(swo_include, 'VERSION')).strip
29
29
  if ENV['OBOE_DEV'].to_s.casecmp('true').zero?
30
- swo_path = "https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly"
30
+ swo_path = 'https://solarwinds-apm-staging.s3.us-west-2.amazonaws.com/apm/c-lib/nightly'
31
31
  puts 'Fetching c-lib from DEVELOPMENT Build'
32
32
  elsif ENV['OBOE_STAGING'].to_s.casecmp('true').zero?
33
33
  swo_path = File.join('https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/', version)
@@ -59,13 +59,14 @@ if File.exist?('/etc/alpine-release')
59
59
  end
60
60
 
61
61
  swo_clib = "liboboe-1.0-#{swo_arch}.so"
62
+ swo_clib = "liboboe-1.0-lambda-#{swo_arch}.so" if ENV['LAMBDA_TASK_ROOT'] || ENV['AWS_LAMBDA_FUNCTION_NAME']
62
63
  swo_item = File.join(swo_path, swo_clib)
63
64
  swo_checksum_file = File.join(swo_lib_dir, "#{swo_clib}.sha256")
64
65
  clib = File.join(swo_lib_dir, swo_clib)
65
66
 
66
67
  retries = 3
67
68
  success = false
68
- while retries > 0
69
+ while retries.positive?
69
70
  begin
70
71
  IO.copy_stream(URI.parse(swo_item).open, clib)
71
72
  clib_checksum = Digest::SHA256.file(clib).hexdigest
@@ -73,29 +74,29 @@ while retries > 0
73
74
 
74
75
  # unfortunately these messages only show if the install command is run
75
76
  # with the `--verbose` flag
76
- if clib_checksum != checksum
77
- $stderr.puts '== ERROR ================================================================='
78
- $stderr.puts 'Checksum Verification failed for the c-extension of the solarwinds_apm gem'
79
- $stderr.puts 'Installation cannot continue'
80
- $stderr.puts "\nChecksum packaged with gem: #{checksum}"
81
- $stderr.puts "Checksum calculated from lib: #{clib_checksum}"
82
- $stderr.puts 'Contact technicalsupport@solarwinds.com if the problem persists'
83
- $stderr.puts '=========================================================================='
84
- exit 1
85
- else
77
+ if clib_checksum == checksum
86
78
  success = true
87
79
  retries = 0
80
+ else
81
+ warn '== ERROR ================================================================='
82
+ warn 'Checksum Verification failed for the c-extension of the solarwinds_apm gem'
83
+ warn 'Installation cannot continue'
84
+ warn "\nChecksum packaged with gem: #{checksum}"
85
+ warn "Checksum calculated from lib: #{clib_checksum}"
86
+ warn 'Contact technicalsupport@solarwinds.com if the problem persists'
87
+ warn '=========================================================================='
88
+ exit 1
88
89
  end
89
90
  rescue StandardError => e
90
91
  File.write(clib, '')
91
92
  retries -= 1
92
- if retries == 0
93
- $stderr.puts '== ERROR =========================================================='
94
- $stderr.puts 'Download of the c-extension for the solarwinds_apm gem failed.'
95
- $stderr.puts 'solarwinds_apm will not instrument the code. No tracing will occur.'
96
- $stderr.puts 'Contact technicalsupport@solarwinds.com if the problem persists.'
97
- $stderr.puts "error: #{swo_item}\n#{e.message}"
98
- $stderr.puts '==================================================================='
93
+ if retries.zero?
94
+ warn '== ERROR =========================================================='
95
+ warn 'Download of the c-extension for the solarwinds_apm gem failed.'
96
+ warn 'solarwinds_apm will not instrument the code. No tracing will occur.'
97
+ warn 'Contact technicalsupport@solarwinds.com if the problem persists.'
98
+ warn "error: #{swo_item}\n#{e.message}"
99
+ warn '==================================================================='
99
100
  create_makefile('oboe_noop', 'noop')
100
101
  end
101
102
  sleep 0.5
@@ -116,35 +117,35 @@ if success
116
117
  $libs = append_library($libs, 'oboe')
117
118
  $libs = append_library($libs, 'stdc++')
118
119
 
119
- $CFLAGS << " #{ENV['CFLAGS']}"
120
+ $CFLAGS << " #{ENV.fetch('CFLAGS', nil)}"
120
121
  # $CPPFLAGS << " #{ENV['CPPFLAGS']} -std=c++11"
121
122
  # TODO for debugging: -pg -gdwarf-2, remove for production
122
123
  # -pg does not work on alpine https://www.openwall.com/lists/musl/2014/11/05/2
123
- $CPPFLAGS << " #{ENV['CPPFLAGS']} -std=c++11 -gdwarf-2 -I$$ORIGIN/../ext/oboe_metal/include -I$$ORIGIN/../ext/oboe_metal/src"
124
+ $CPPFLAGS << " #{ENV.fetch('CPPFLAGS', nil)} -std=c++11 -gdwarf-2 -I$$ORIGIN/../ext/oboe_metal/include -I$$ORIGIN/../ext/oboe_metal/src"
124
125
  # $CPPFLAGS << " #{ENV['CPPFLAGS']} -std=c++11 -I$$ORIGIN/../ext/oboe_metal/include"
125
- $LIBS << " #{ENV['LIBS']}"
126
+ $LIBS << " #{ENV.fetch('LIBS', nil)}"
126
127
 
127
128
  # use "z,defs" to see what happens during linking
128
129
  # $LDFLAGS << " #{ENV['LDFLAGS']} '-Wl,-rpath=$$ORIGIN/../ext/oboe_metal/lib,-z,defs' -lrt"
129
- $LDFLAGS << " #{ENV['LDFLAGS']} '-Wl,-rpath=$$ORIGIN/../ext/oboe_metal/lib' -lrt"
130
- $CXXFLAGS += " -std=c++11 "
130
+ $LDFLAGS << " #{ENV.fetch('LDFLAGS', nil)} '-Wl,-rpath=$$ORIGIN/../ext/oboe_metal/lib' -lrt"
131
+ $CXXFLAGS += ' -std=c++11 '
131
132
 
132
133
  # ____ include debug info, comment out when not debugging
133
134
  # ____ -pg -> profiling info for gprof
134
- CONFIG["debugflags"] = "-ggdb3 "
135
- CONFIG["optflags"] = "-O0"
135
+ CONFIG['debugflags'] = '-ggdb3 '
136
+ CONFIG['optflags'] = '-O0'
136
137
 
137
138
  create_makefile('libsolarwinds_apm', 'src')
138
139
  else
139
- $stderr.puts '== ERROR ========================================================='
140
+ warn '== ERROR ========================================================='
140
141
  if have_library('oboe')
141
- $stderr.puts "The c-library either needs to be updated or doesn't match the OS."
142
- $stderr.puts 'No tracing will occur.'
142
+ warn "The c-library either needs to be updated or doesn't match the OS."
143
+ warn 'No tracing will occur.'
143
144
  else
144
- $stderr.puts 'Could not find a matching c-library. No tracing will occur.'
145
+ warn 'Could not find a matching c-library. No tracing will occur.'
145
146
  end
146
- $stderr.puts 'Contact technicalsupport@solarwinds.com if the problem persists.'
147
- $stderr.puts '=================================================================='
147
+ warn 'Contact technicalsupport@solarwinds.com if the problem persists.'
148
+ warn '=================================================================='
148
149
  create_makefile('oboe_noop', 'noop')
149
150
  end
150
- end
151
+ end
@@ -1 +1 @@
1
- b3a0b342e5d59ea95b457bcc647b9a2e202d623d5c17a109df2719a5d61815d2
1
+ bcf8ad33da8e896e946e376f9e7d75a584bb98a3a4b41e89e231783f97a1380f
@@ -1 +1 @@
1
- 5f98ddec2afd1992080d4e751b583a075e1a91b95ca3a5e5d7db49978225c8bd
1
+ 0cf5329232ec370db869fa207c2a27813d970199f3f319828155481718e2ab01
@@ -1 +1 @@
1
- 5227b6cc86a1d60c479f9e2021200b09e3ba70f47a563788c857f51747dbebe8
1
+ dd02f77cf106ed0f61a333ede73864db61d6c4c11b474a0db82c83d3ea6c7199
@@ -0,0 +1 @@
1
+ ff5cdc5a3da9a7585fd95bc806ac465993b97981832d8dc768d362e0ff1a3221
@@ -0,0 +1 @@
1
+ 6caa7a24c9d3377f08b93ef6eb8191e2addb1f880ad4759fbafdf4e88b6620ce
@@ -1 +1 @@
1
- 22d5c810eaf9b663b46ae67586059edf18e7e1e3beab89f079d2b86353ef55d9
1
+ 8a35ff7ae2feb1ca630b15453143f3d440f91aeb1a7cc7b595d0039600fe297f
@@ -1 +1 @@
1
- 14.0.1
1
+ 15.0.1
@@ -919,6 +919,9 @@ bool oboe_consume_triggered_trace_count(unsigned int* value);
919
919
  bool oboe_get_last_used_sample_rate(unsigned int* value);
920
920
  bool oboe_get_last_used_sample_source(unsigned int* value);
921
921
 
922
+ void oboe_metrics_attributes_upsert(const char* key, const char* value);
923
+ bool oboe_metrics_attributes_remove(const char* key);
924
+
922
925
  #ifdef __cplusplus
923
926
  } // extern "C"
924
927
  #endif
@@ -772,7 +772,7 @@ bool OboeAPI::consumeTokenBucketExhaustionCount(unsigned int& counter) {
772
772
  return oboe_consume_token_bucket_exhaustion_count(&counter);
773
773
  }
774
774
  bool OboeAPI::consumeTraceCount(unsigned int& counter) {
775
- return oboe_consume_through_trace_count(&counter);
775
+ return oboe_consume_trace_count(&counter);
776
776
  }
777
777
  bool OboeAPI::consumeSampleCount(unsigned int& counter) {
778
778
  return oboe_consume_sample_count(&counter);
data/lib/oboe_metal.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -9,11 +11,12 @@
9
11
  module SolarWindsAPM
10
12
  include Oboe_metal
11
13
 
12
- @loaded = false
13
- @reporter = nil
14
+ @loaded = false
15
+ @reporter = nil
16
+ @oboe_api = nil
14
17
 
15
18
  class << self
16
- attr_accessor :reporter, :loaded
19
+ attr_accessor :reporter, :loaded, :oboe_api
17
20
 
18
21
  def sample_rate(rate)
19
22
  return unless SolarWindsAPM.loaded
@@ -32,17 +35,15 @@ module SolarWindsAPM
32
35
  # Start the SolarWindsAPM Reporter
33
36
  #
34
37
  def start
35
- begin
36
- options = SolarWindsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
37
- SolarWindsAPM.reporter = Oboe_metal::Reporter.new(*options)
38
- report_init
39
- SolarWindsAPM.loaded = true
40
- rescue StandardError=> e
41
- $stderr.puts e.message
42
- SolarWindsAPM.loaded = false
43
- end
38
+ options = SolarWindsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
39
+ SolarWindsAPM.reporter = Oboe_metal::Reporter.new(*options)
40
+ report_init
41
+ SolarWindsAPM.loaded = true
42
+ rescue StandardError => e
43
+ warn e.message
44
+ SolarWindsAPM.loaded = false
44
45
  end
45
- alias :restart :start
46
+ alias restart start
46
47
 
47
48
  ##
48
49
  # sendReport
@@ -58,7 +59,7 @@ module SolarWindsAPM
58
59
  #
59
60
  # Send the report for the given event
60
61
  #
61
- def send_status(evt, context=nil, with_system_timestamp: true)
62
+ def send_status(evt, context = nil, with_system_timestamp: true)
62
63
  SolarWindsAPM.reporter.sendStatus(evt, context, with_system_timestamp)
63
64
  end
64
65
 
@@ -68,7 +69,7 @@ module SolarWindsAPM
68
69
  # installed, as well as the version of instrumentation and version of
69
70
  # layer.
70
71
  #
71
- def report_init(layer=:rack) # :nodoc:
72
+ def report_init(layer = :rack) # :nodoc:
72
73
  # Don't send __Init in test or if SolarWindsAPM
73
74
  # isn't fully loaded (e.g. missing c-extension)
74
75
  return unless SolarWindsAPM.loaded
@@ -85,7 +86,7 @@ module SolarWindsAPM
85
86
  #
86
87
  # * +layer+ - The layer the reported event belongs to
87
88
  # * +kvs+ - A hash containing key/value pairs that will be reported along with this event
88
- def log_init(layer=:rack, kvs={})
89
+ def log_init(layer = :rack, kvs = {})
89
90
  context = SolarWindsAPM::Metadata.makeRandom
90
91
  return SolarWindsAPM::Context.toString unless context.isValid
91
92
 
@@ -108,15 +109,15 @@ module SolarWindsAPM
108
109
  # and for SolarWindsAPM.support_report.
109
110
  #
110
111
  def build_swo_init_report
111
-
112
- platform_info = {'__Init' => true}
112
+ platform_info = { '__Init' => true }
113
113
 
114
114
  begin
115
115
  platform_info['APM.Version'] = SolarWindsAPM::Version::STRING
116
116
  platform_info['APM.Extension.Version'] = extension_lib_version
117
117
 
118
118
  # OTel Resource Attributes (Optional)
119
- platform_info['process.executable.path'] = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
119
+ platform_info['process.executable.path'] =
120
+ File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
120
121
  platform_info['process.executable.name'] = RbConfig::CONFIG['ruby_install_name']
121
122
  platform_info['process.command_line'] = $PROGRAM_NAME
122
123
  platform_info['process.telemetry.path'] = Gem::Specification.find_by_name('solarwinds_apm')&.full_gem_path
@@ -127,10 +128,14 @@ module SolarWindsAPM
127
128
  # Collect up opentelemetry sdk version (Instrumented Library Versions) (Required)
128
129
  begin
129
130
  require 'opentelemetry/sdk'
130
- ::OpenTelemetry::SDK::Resources::Resource.telemetry_sdk.attribute_enumerator.each {|k,v| platform_info[k] = v}
131
- ::OpenTelemetry::SDK::Resources::Resource.process.attribute_enumerator.each {|k,v| platform_info[k] = v}
131
+ ::OpenTelemetry::SDK::Resources::Resource.telemetry_sdk.attribute_enumerator.each do |k, v|
132
+ platform_info[k] = v
133
+ end
134
+ ::OpenTelemetry::SDK::Resources::Resource.process.attribute_enumerator.each { |k, v| platform_info[k] = v }
132
135
  rescue StandardError => e
133
- SolarWindsAPM.logger.warn {"[#{self.class}/#{__method__}] Fail to extract telemetry attributes. Error: #{e.message}"}
136
+ SolarWindsAPM.logger.warn do
137
+ "[#{self.class}/#{__method__}] Fail to extract telemetry attributes. Error: #{e.message}"
138
+ end
134
139
  end
135
140
  rescue StandardError, ScriptError => e
136
141
  # Also rescue ScriptError (aka SyntaxError) in case one of the expected
@@ -138,8 +143,8 @@ module SolarWindsAPM
138
143
 
139
144
  platform_info['Error'] = "Error in build_report: #{e.message}"
140
145
 
141
- SolarWindsAPM.logger.warn {"[#{self.class}/#{__method__}] Error in build_init_report: #{e.message}"}
142
- SolarWindsAPM.logger.debug {e.backtrace}
146
+ SolarWindsAPM.logger.warn { "[#{self.class}/#{__method__}] Error in build_init_report: #{e.message}" }
147
+ SolarWindsAPM.logger.debug { e.backtrace }
143
148
  end
144
149
  platform_info
145
150
  end
@@ -150,7 +155,7 @@ module SolarWindsAPM
150
155
  def report_gem_in_use
151
156
  platform_info = {}
152
157
  if defined?(Gem) && Gem.respond_to?(:loaded_specs)
153
- Gem.loaded_specs.each_pair {|k, v| platform_info["Ruby.#{k}.Version"] = v.version.to_s}
158
+ Gem.loaded_specs.each_pair { |k, v| platform_info["Ruby.#{k}.Version"] = v.version.to_s }
154
159
  else
155
160
  platform_info.merge!(legacy_build_init_report)
156
161
  end
@@ -170,8 +175,6 @@ module SolarWindsAPM
170
175
  end
171
176
  end
172
177
 
173
- # rubocop:enable Style/Documentation
174
-
175
178
  # Setup an alias
176
179
  SolarWindsApm = SolarWindsAPM
177
180
  SolarwindsApm = SolarWindsAPM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -8,39 +10,39 @@ module SolarWindsAPM
8
10
  # InstallGenerator
9
11
  class InstallGenerator < ::Rails::Generators::Base
10
12
  source_root File.join(File.dirname(__FILE__), 'templates')
11
- desc "Copies a SolarWindsAPM gem initializer file to your application."
13
+ desc 'Copies a SolarWindsAPM gem initializer file to your application.'
12
14
 
13
- @namespace = "solarwinds_apm:install"
15
+ @namespace = 'solarwinds_apm:install'
14
16
 
15
17
  def copy_initializer
16
18
  print_header
17
19
  print_footer
18
20
 
19
- template "solarwinds_apm_initializer.rb", "config/initializers/solarwinds_apm.rb"
21
+ template 'solarwinds_apm_initializer.rb', 'config/initializers/solarwinds_apm.rb'
20
22
  end
21
23
 
22
24
  private
23
25
 
24
26
  def print_header
25
- say ""
26
- say shell.set_color "Welcome to the SolarWindsAPM Ruby instrumentation setup.", :green, :bold
27
- say ""
28
- say shell.set_color "Documentation Links", :magenta
29
- say "-------------------"
30
- say ""
31
- say "SolarWindsAPM Installation Overview:"
32
- say "https://documentation.solarwinds.com/en/success_center/observability"
33
- say ""
34
- say "More information on instrumenting Ruby applications can be found here:"
35
- say "https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent"
27
+ say ''
28
+ say shell.set_color 'Welcome to the SolarWindsAPM Ruby instrumentation setup.', :green, :bold
29
+ say ''
30
+ say shell.set_color 'Documentation Links', :magenta
31
+ say '-------------------'
32
+ say ''
33
+ say 'SolarWindsAPM Installation Overview:'
34
+ say 'https://documentation.solarwinds.com/en/success_center/observability'
35
+ say ''
36
+ say 'More information on instrumenting Ruby applications can be found here:'
37
+ say 'https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent'
36
38
  end
37
39
 
38
40
  def print_footer
39
- say ""
40
- say "You can change configuration values in the future by modifying config/initializers/solarwinds_apm.rb"
41
- say ""
42
- say "Thanks! Creating the SolarWindsAPM initializer..."
43
- say ""
41
+ say ''
42
+ say 'You can change configuration values in the future by modifying config/initializers/solarwinds_apm.rb'
43
+ say ''
44
+ say 'Thanks! Creating the SolarWindsAPM initializer...'
45
+ say ''
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -13,8 +15,8 @@ module SolarWindsAPM
13
15
  # {TraceInfo#trace_flags}<br>
14
16
  # {TraceInfo#for_log}<br>
15
17
  # {TraceInfo#hash_for_log}
16
- #
17
- # The <tt>SolarWindsAPM::Config[:log_traceId]</tt> configuration setting for automatic trace context in logs affects the
18
+ #
19
+ # The <tt>SolarWindsAPM::Config[:log_traceId]</tt> configuration setting for automatic trace context in logs affects the
18
20
  # return value of methods in this module.
19
21
  #
20
22
  # The following options are available:<br>
@@ -51,18 +53,18 @@ module SolarWindsAPM
51
53
  class TraceInfo
52
54
  attr_reader :tracestring, :trace_id, :span_id, :trace_flags, :do_log
53
55
 
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
56
+ REGEXP = /^(?<tracestring>(?<version>[a-f0-9]{2})-(?<trace_id>[a-f0-9]{32})-(?<span_id>[a-f0-9]{16})-(?<flags>[a-f0-9]{2}))$/
55
57
  private_constant :REGEXP
56
58
 
57
59
  def initialize
58
60
  @trace_id, @span_id, @trace_flags, @tracestring = current_span
59
- @service_name = ENV['OTEL_SERVICE_NAME']
61
+ @service_name = ENV.fetch('OTEL_SERVICE_NAME', nil)
60
62
  @do_log = log? # true if the tracecontext should be added to logs
61
63
  end
62
64
 
63
65
  # for_log returns a string in the format
64
66
  # 'trace_id=<trace_id> span_id=<span_id> trace_flags=<trace_flags>' or empty string.
65
- #
67
+ #
66
68
  # An empty string is returned depending on the setting for
67
69
  # <tt>SolarWindsAPM::Config[:log_traceId]</tt>, which can be :never,
68
70
  # :sampled, :traced, or :always.
@@ -88,7 +90,7 @@ module SolarWindsAPM
88
90
  # span_id: '49e60702469db05f',
89
91
  # trace_flags: 01,
90
92
  # resource.service.name: 'otel_service_name' } or {} depends on Config
91
- #
93
+ #
92
94
  # # For lograge:
93
95
  # Lograge.custom_options = lambda do |event|
94
96
  # SolarWindsAPM::API.current_trace_info.hash_for_log
@@ -98,7 +100,12 @@ module SolarWindsAPM
98
100
  # * Hash
99
101
  #
100
102
  def hash_for_log
101
- @hash_for_log = @do_log ? {'trace_id' => @trace_id, 'span_id' => @span_id, 'trace_flags' => @trace_flags, 'resource.service.name' => @service_name} : {}
103
+ @hash_for_log = if @do_log
104
+ { 'trace_id' => @trace_id, 'span_id' => @span_id, 'trace_flags' => @trace_flags,
105
+ 'resource.service.name' => @service_name }
106
+ else
107
+ {}
108
+ end
102
109
  end
103
110
 
104
111
  private
@@ -107,7 +114,7 @@ module SolarWindsAPM
107
114
  span = ::OpenTelemetry::Trace.current_span if defined?(::OpenTelemetry::Trace)
108
115
  trace_id = span.context.hex_trace_id
109
116
  span_id = span.context.hex_span_id
110
- trace_flags = span.context.trace_flags.sampled?? '01' : '00'
117
+ trace_flags = span.context.trace_flags.sampled? ? '01' : '00'
111
118
  tracestring = "00-#{trace_id}-#{span_id}-#{trace_flags}"
112
119
  [trace_id, span_id, trace_flags, tracestring]
113
120
  end
@@ -130,7 +137,7 @@ module SolarWindsAPM
130
137
  def valid?(tracestring)
131
138
  matches = REGEXP.match(tracestring)
132
139
 
133
- matches && matches[:trace_id] != ("0" * 32)
140
+ matches && matches[:trace_id] != ('0' * 32)
134
141
  end
135
142
 
136
143
  def sampled?(tracestring)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -30,12 +32,12 @@ module SolarWindsAPM
30
32
  # === Returns:
31
33
  # * Boolean
32
34
  #
33
- def increment_metric(name, count=1, with_hostname=false, tags_kvs={}) # rubocop:disable Style/OptionalBooleanParameter
35
+ def increment_metric(name, count = 1, with_hostname = false, tags_kvs = {}) # rubocop:disable Style/OptionalBooleanParameter
34
36
  return true unless SolarWindsAPM.loaded
35
37
 
36
38
  with_hostname = with_hostname ? 1 : 0
37
39
  tags, tags_count = make_tags(tags_kvs)
38
- SolarWindsAPM::CustomMetrics.increment(name.to_s, count, with_hostname, nil, tags, tags_count) == 0
40
+ SolarWindsAPM::CustomMetrics.increment(name.to_s, count, with_hostname, nil, tags, tags_count).zero?
39
41
  end
40
42
 
41
43
  # Send values with counts
@@ -64,12 +66,12 @@ module SolarWindsAPM
64
66
  # === Returns:
65
67
  # * Boolean
66
68
  #
67
- def summary_metric(name, value, count=1, with_hostname=false, tags_kvs={}) # rubocop:disable Style/OptionalBooleanParameter
69
+ def summary_metric(name, value, count = 1, with_hostname = false, tags_kvs = {}) # rubocop:disable Style/OptionalBooleanParameter
68
70
  return true unless SolarWindsAPM.loaded
69
71
 
70
72
  with_hostname = with_hostname ? 1 : 0
71
73
  tags, tags_count = make_tags(tags_kvs)
72
- SolarWindsAPM::CustomMetrics.summary(name.to_s, value, count, with_hostname, nil, tags, tags_count) == 0
74
+ SolarWindsAPM::CustomMetrics.summary(name.to_s, value, count, with_hostname, nil, tags, tags_count).zero?
73
75
  end
74
76
 
75
77
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -26,18 +28,20 @@ module SolarWindsAPM
26
28
  # req = Net::HTTP::Get.new(url.to_s)
27
29
  # res = Net::HTTP.start(url.host, url.port) {|http| http.request(req)}
28
30
  # end
29
- #
31
+ #
30
32
  # === Returns:
31
33
  # * value returned by block
32
34
  #
33
35
  def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, &block)
34
36
  if block.nil?
35
- SolarWindsAPM.logger.warn {"[#{name}/#{__method__}] please provide block when using in_span function"}
37
+ SolarWindsAPM.logger.warn { "[#{name}/#{__method__}] please provide block when using in_span function" }
36
38
  return
37
39
  end
38
40
 
39
- SolarWindsAPM.logger.debug {"[#{name}/#{__method__}] solarwinds_apm in_span with OTEL_SERVICE_NAME #{ENV['OTEL_SERVICE_NAME']}"}
40
- current_tracer = ::OpenTelemetry.tracer_provider.tracer(ENV['OTEL_SERVICE_NAME'])
41
+ SolarWindsAPM.logger.debug do
42
+ "[#{name}/#{__method__}] solarwinds_apm in_span with OTEL_SERVICE_NAME #{ENV.fetch('OTEL_SERVICE_NAME', nil)}"
43
+ end
44
+ current_tracer = ::OpenTelemetry.tracer_provider.tracer(ENV.fetch('OTEL_SERVICE_NAME', nil))
41
45
  current_tracer.in_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, &block)
42
46
  end
43
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
2
4
  #
3
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
@@ -13,7 +15,7 @@ module SolarWindsAPM
13
15
  # information during the whole time the process is running. It returns boolean if <tt>integer_response</tt> is false,
14
16
  # and it will return integer if setting <tt>integer_response</tt> as true.
15
17
  # Usually SolarWinds doesn't block an application while it is starting up.
16
- #
18
+ #
17
19
  # For status code reference:
18
20
  # 0: unknown error
19
21
  # 1: is ready
@@ -32,18 +34,18 @@ module SolarWindsAPM
32
34
  # unless SolarWindsAPM::API.solarwinds_ready?(10_000)
33
35
  # Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent"
34
36
  # end
35
- #
37
+ #
36
38
  # # with status code print out
37
39
  # status = SolarWindsAPM::API.solarwinds_ready?(10_000, integer_response: true)
38
40
  # unless status == 1
39
41
  # Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent. Error code "#{status}"
40
42
  # end
41
- #
43
+ #
42
44
  # === Returns:
43
45
  # * Boolean (if integer_response: false)
44
46
  # * Integer (if integer_response: true)
45
47
  #
46
- def solarwinds_ready?(wait_milliseconds=3000, integer_response: false)
48
+ def solarwinds_ready?(wait_milliseconds = 3000, integer_response: false)
47
49
  return false unless SolarWindsAPM.loaded
48
50
 
49
51
  is_ready = SolarWindsAPM::Context.isReady(wait_milliseconds)