solarwinds_apm 6.0.0.prev6 → 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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/ext/oboe_metal/extconf.rb +43 -42
  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 +46 -84
  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 +10 -6
  17. data/lib/solarwinds_apm/api/tracing.rb +7 -5
  18. data/lib/solarwinds_apm/api/transaction_name.rb +21 -11
  19. data/lib/solarwinds_apm/api.rb +8 -6
  20. data/lib/solarwinds_apm/config.rb +72 -47
  21. data/lib/solarwinds_apm/constants.rb +26 -26
  22. data/lib/solarwinds_apm/logger.rb +2 -0
  23. data/lib/solarwinds_apm/noop/README.md +1 -1
  24. data/lib/solarwinds_apm/noop/api.rb +85 -0
  25. data/lib/solarwinds_apm/noop/context.rb +15 -2
  26. data/lib/solarwinds_apm/noop/metadata.rb +7 -2
  27. data/lib/solarwinds_apm/{base.rb → noop/span.rb} +16 -15
  28. data/lib/solarwinds_apm/noop.rb +33 -0
  29. data/lib/solarwinds_apm/oboe_init_options.rb +50 -111
  30. data/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +135 -0
  31. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +66 -41
  32. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +50 -52
  33. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +30 -22
  34. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +29 -16
  35. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +136 -99
  36. data/lib/solarwinds_apm/opentelemetry.rb +8 -5
  37. data/lib/solarwinds_apm/otel_config.rb +38 -43
  38. data/lib/solarwinds_apm/otel_lambda_config.rb +53 -0
  39. data/lib/solarwinds_apm/patch/dummy_patch.rb +12 -0
  40. data/lib/solarwinds_apm/{thread_local.rb → patch.rb} +6 -22
  41. data/lib/solarwinds_apm/support/logger_formatter.rb +4 -2
  42. data/lib/solarwinds_apm/support/logging_log_event.rb +2 -0
  43. data/lib/solarwinds_apm/support/lumberjack_formatter.rb +2 -0
  44. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +22 -22
  45. data/lib/solarwinds_apm/support/service_key_checker.rb +106 -0
  46. data/lib/solarwinds_apm/{support_report.rb → support/support_report.rb} +15 -10
  47. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +18 -17
  48. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +13 -12
  49. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +4 -2
  50. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +3 -1
  51. data/lib/solarwinds_apm/support/transaction_cache.rb +6 -4
  52. data/lib/solarwinds_apm/support/transaction_settings.rb +7 -3
  53. data/lib/solarwinds_apm/support/txn_name_manager.rb +8 -3
  54. data/lib/solarwinds_apm/support/utils.rb +12 -9
  55. data/lib/solarwinds_apm/support/x_trace_options.rb +23 -17
  56. data/lib/solarwinds_apm/support.rb +28 -23
  57. data/lib/solarwinds_apm/version.rb +4 -2
  58. data/lib/solarwinds_apm.rb +82 -52
  59. metadata +23 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 512ec5ee7d54316580c83a629faccc98c8c435151f0dade34d102597ad700a9f
4
- data.tar.gz: 7a6f84e7c04493d368a157ed098ae2ea67898c40d2eba23e6a2467d6de6faf18
3
+ metadata.gz: 0ad230df4c45bce0d25321678bc23a0a5fcfa62e98970e3d1ceda24430716314
4
+ data.tar.gz: bf4556eb3a109b25c8589bd7d4347e34f1475f1be6e86200af88ee604df3ffb0
5
5
  SHA512:
6
- metadata.gz: 5fbd2c89241e02a6ab3e54bc430f92f98a5ac13ebf9f3cad135b045aea679a9f170ff0cbf5c3f6cf162f3fd90fdb2d6200e692be4259527cf06eea05904b91b4
7
- data.tar.gz: e49ec590eb79e9d4c436f8341bffe16cb8d6fe07e77cb2939159da6b0b33222aed3d4d9bb8610cef55a59b572543c5d74eef2bef9179b2a5a65df258b2a0e8ca
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)
@@ -42,7 +42,7 @@ system_arch.delete!("\n")
42
42
  case system_arch
43
43
  when 'x86_64'
44
44
  swo_arch = 'x86_64'
45
- when 'aarch64'
45
+ when 'aarch64' || 'arm64'
46
46
  swo_arch = 'aarch64'
47
47
  end
48
48
 
@@ -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
@@ -7,9 +9,23 @@
7
9
  # Disable docs and Camelcase warns since we're implementing
8
10
  # an interface here. See OboeBase for details.
9
11
  module SolarWindsAPM
10
- extend SolarWindsAPMBase
11
12
  include Oboe_metal
12
13
 
14
+ @loaded = false
15
+ @reporter = nil
16
+ @oboe_api = nil
17
+
18
+ class << self
19
+ attr_accessor :reporter, :loaded, :oboe_api
20
+
21
+ def sample_rate(rate)
22
+ return unless SolarWindsAPM.loaded
23
+
24
+ # Update liboboe with the new SampleRate value
25
+ SolarWindsAPM::Context.setDefaultSampleRate(rate.to_i)
26
+ end
27
+ end
28
+
13
29
  # Reporter that send span data to SWO
14
30
  class Reporter
15
31
  class << self
@@ -19,21 +35,15 @@ module SolarWindsAPM
19
35
  # Start the SolarWindsAPM Reporter
20
36
  #
21
37
  def start
22
- SolarWindsAPM.loaded = false unless SolarWindsAPM::OboeInitOptions.instance.service_key_ok?
23
- return unless SolarWindsAPM.loaded
24
-
25
- begin
26
- options = SolarWindsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
27
-
28
- SolarWindsAPM.reporter = Oboe_metal::Reporter.new(*options)
29
-
30
- report_init
31
- rescue StandardError=> e
32
- $stderr.puts e.message
33
- raise
34
- 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
35
45
  end
36
- alias :restart :start
46
+ alias restart start
37
47
 
38
48
  ##
39
49
  # sendReport
@@ -49,63 +59,17 @@ module SolarWindsAPM
49
59
  #
50
60
  # Send the report for the given event
51
61
  #
52
- def send_status(evt, context=nil, with_system_timestamp: true)
62
+ def send_status(evt, context = nil, with_system_timestamp: true)
53
63
  SolarWindsAPM.reporter.sendStatus(evt, context, with_system_timestamp)
54
64
  end
55
65
 
56
- ##
57
- # clear_all_traces
58
- #
59
- # Truncates the trace output file to zero
60
- #
61
- def clear_all_traces
62
- File.truncate(SolarWindsAPM::OboeInitOptions.instance.host, 0)
63
- end
64
-
65
- ##
66
- # obtain_all_traces
67
- #
68
- # Retrieves all traces written to the trace file
69
- #
70
- def obtain_all_traces
71
- io = File.open(SolarWindsAPM::OboeInitOptions.instance.host, 'r')
72
- contents = io.readlines(nil)
73
- io.close
74
-
75
- return contents if contents.empty?
76
-
77
- traces = []
78
-
79
- # We use Gem.loaded_spec because older versions of the bson
80
- # gem didn't even have a version embedded in the gem. If the
81
- # gem isn't in the bundle, it should rightfully error out
82
- # anyways.
83
- #
84
- if Gem.loaded_specs['bson'] && Gem.loaded_specs['bson'].version.to_s < '4.0'
85
- s = StringIO.new(contents[0])
86
-
87
- until s.eof?
88
- traces << if ::BSON.respond_to? :read_bson_document
89
- BSON.read_bson_document(s)
90
- else
91
- BSON::Document.from_bson(s)
92
- end
93
- end
94
- else
95
- bbb = ::BSON::ByteBuffer.new(contents[0])
96
- traces << Hash.from_bson(bbb) until bbb.length == 0
97
- end
98
-
99
- traces
100
- end
101
-
102
66
  private
103
67
 
104
68
  # Internal: Report that instrumentation for the given layer has been
105
69
  # installed, as well as the version of instrumentation and version of
106
70
  # layer.
107
71
  #
108
- def report_init(layer=:rack) # :nodoc:
72
+ def report_init(layer = :rack) # :nodoc:
109
73
  # Don't send __Init in test or if SolarWindsAPM
110
74
  # isn't fully loaded (e.g. missing c-extension)
111
75
  return unless SolarWindsAPM.loaded
@@ -122,7 +86,7 @@ module SolarWindsAPM
122
86
  #
123
87
  # * +layer+ - The layer the reported event belongs to
124
88
  # * +kvs+ - A hash containing key/value pairs that will be reported along with this event
125
- def log_init(layer=:rack, kvs={})
89
+ def log_init(layer = :rack, kvs = {})
126
90
  context = SolarWindsAPM::Metadata.makeRandom
127
91
  return SolarWindsAPM::Context.toString unless context.isValid
128
92
 
@@ -145,15 +109,15 @@ module SolarWindsAPM
145
109
  # and for SolarWindsAPM.support_report.
146
110
  #
147
111
  def build_swo_init_report
148
-
149
- platform_info = {'__Init' => true}
112
+ platform_info = { '__Init' => true }
150
113
 
151
114
  begin
152
115
  platform_info['APM.Version'] = SolarWindsAPM::Version::STRING
153
116
  platform_info['APM.Extension.Version'] = extension_lib_version
154
117
 
155
118
  # OTel Resource Attributes (Optional)
156
- 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, '"\&"')
157
121
  platform_info['process.executable.name'] = RbConfig::CONFIG['ruby_install_name']
158
122
  platform_info['process.command_line'] = $PROGRAM_NAME
159
123
  platform_info['process.telemetry.path'] = Gem::Specification.find_by_name('solarwinds_apm')&.full_gem_path
@@ -164,10 +128,14 @@ module SolarWindsAPM
164
128
  # Collect up opentelemetry sdk version (Instrumented Library Versions) (Required)
165
129
  begin
166
130
  require 'opentelemetry/sdk'
167
- ::OpenTelemetry::SDK::Resources::Resource.telemetry_sdk.attribute_enumerator.each {|k,v| platform_info[k] = v}
168
- ::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 }
169
135
  rescue StandardError => e
170
- 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
171
139
  end
172
140
  rescue StandardError, ScriptError => e
173
141
  # Also rescue ScriptError (aka SyntaxError) in case one of the expected
@@ -175,8 +143,8 @@ module SolarWindsAPM
175
143
 
176
144
  platform_info['Error'] = "Error in build_report: #{e.message}"
177
145
 
178
- SolarWindsAPM.logger.warn {"[#{self.class}/#{__method__}] Error in build_init_report: #{e.message}"}
179
- 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 }
180
148
  end
181
149
  platform_info
182
150
  end
@@ -187,7 +155,7 @@ module SolarWindsAPM
187
155
  def report_gem_in_use
188
156
  platform_info = {}
189
157
  if defined?(Gem) && Gem.respond_to?(:loaded_specs)
190
- 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 }
191
159
  else
192
160
  platform_info.merge!(legacy_build_init_report)
193
161
  end
@@ -205,16 +173,10 @@ module SolarWindsAPM
205
173
  end
206
174
  end
207
175
  end
208
-
209
- class << self
210
- def sample_rate(rate)
211
- return unless SolarWindsAPM.loaded
212
-
213
- # Update liboboe with the new SampleRate value
214
- SolarWindsAPM::Context.setDefaultSampleRate(rate.to_i)
215
- end
216
- end
217
176
  end
218
177
 
219
- SolarWindsAPM.loaded = true
220
- # rubocop:enable Style/Documentation
178
+ # Setup an alias
179
+ SolarWindsApm = SolarWindsAPM
180
+ SolarwindsApm = SolarWindsAPM
181
+ SolarwindsAPM = SolarWindsAPM
182
+ 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,20 +28,22 @@ 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
- # * Objective
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
44
48
  end
45
- end
49
+ end