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.
- checksums.yaml +4 -4
- data/ext/oboe_metal/extconf.rb +42 -41
- data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +1 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +1 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +1 -1
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-aarch64.so.sha256 +1 -0
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-x86_64.so.sha256 +1 -0
- data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
- data/ext/oboe_metal/src/VERSION +1 -1
- data/ext/oboe_metal/src/oboe.h +3 -0
- data/ext/oboe_metal/src/oboe_api.cpp +1 -1
- data/lib/oboe_metal.rb +30 -27
- data/lib/rails/generators/solarwinds_apm/install_generator.rb +21 -19
- data/lib/solarwinds_apm/api/current_trace_info.rb +16 -9
- data/lib/solarwinds_apm/api/custom_metrics.rb +6 -4
- data/lib/solarwinds_apm/api/opentelemetry.rb +8 -4
- data/lib/solarwinds_apm/api/tracing.rb +6 -4
- data/lib/solarwinds_apm/api/transaction_name.rb +21 -11
- data/lib/solarwinds_apm/api.rb +7 -5
- data/lib/solarwinds_apm/config.rb +70 -46
- data/lib/solarwinds_apm/constants.rb +25 -23
- data/lib/solarwinds_apm/logger.rb +2 -0
- data/lib/solarwinds_apm/noop/api.rb +3 -1
- data/lib/solarwinds_apm/noop/context.rb +2 -0
- data/lib/solarwinds_apm/noop/metadata.rb +2 -0
- data/lib/solarwinds_apm/noop/span.rb +2 -0
- data/lib/solarwinds_apm/noop.rb +8 -6
- data/lib/solarwinds_apm/oboe_init_options.rb +47 -39
- data/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +135 -0
- data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +66 -41
- data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +49 -51
- data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +30 -22
- data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +29 -16
- data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +135 -98
- data/lib/solarwinds_apm/opentelemetry.rb +8 -5
- data/lib/solarwinds_apm/otel_config.rb +32 -25
- data/lib/solarwinds_apm/otel_lambda_config.rb +53 -0
- data/lib/solarwinds_apm/patch.rb +2 -0
- data/lib/solarwinds_apm/support/logger_formatter.rb +4 -2
- data/lib/solarwinds_apm/support/logging_log_event.rb +2 -0
- data/lib/solarwinds_apm/support/lumberjack_formatter.rb +2 -0
- data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +2 -0
- data/lib/solarwinds_apm/support/service_key_checker.rb +18 -6
- data/lib/solarwinds_apm/support/support_report.rb +5 -3
- data/lib/solarwinds_apm/support/swomarginalia/comment.rb +18 -17
- data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +13 -12
- data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +4 -2
- data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +3 -1
- data/lib/solarwinds_apm/support/transaction_cache.rb +6 -4
- data/lib/solarwinds_apm/support/transaction_settings.rb +7 -3
- data/lib/solarwinds_apm/support/txn_name_manager.rb +8 -3
- data/lib/solarwinds_apm/support/utils.rb +12 -9
- data/lib/solarwinds_apm/support/x_trace_options.rb +23 -17
- data/lib/solarwinds_apm/support.rb +28 -24
- data/lib/solarwinds_apm/version.rb +3 -1
- data/lib/solarwinds_apm.rb +44 -34
- metadata +14 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad230df4c45bce0d25321678bc23a0a5fcfa62e98970e3d1ceda24430716314
|
4
|
+
data.tar.gz: bf4556eb3a109b25c8589bd7d4347e34f1475f1be6e86200af88ee604df3ffb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a7b0a9a5cfa5d0276c1fe5f3a52430380e3c4f2b9ecd8dc1426e29eda4aa7a98b245425dba6b574e9180c088e2dbff02239f66e802efd84938aa39502a418dc
|
7
|
+
data.tar.gz: b20dd4f228fe7ffbc8415c5f33cede6161232f928d99871023b1340a92ded360c5c776efff355a5e8323486227eb008616963d27492c5aeff315bd8aa4ad6dc3
|
data/ext/oboe_metal/extconf.rb
CHANGED
@@ -7,14 +7,14 @@ require 'mkmf'
|
|
7
7
|
require 'rbconfig'
|
8
8
|
require 'open-uri'
|
9
9
|
|
10
|
-
CONFIG['warnflags'] = CONFIG['warnflags'].gsub(
|
11
|
-
.gsub(
|
12
|
-
.gsub(
|
13
|
-
.gsub(
|
14
|
-
.gsub(
|
15
|
-
.gsub(
|
16
|
-
.gsub(
|
17
|
-
.gsub(
|
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 =
|
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
|
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
|
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
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
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
|
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
|
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
|
130
|
-
$CXXFLAGS +=
|
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[
|
135
|
-
CONFIG[
|
135
|
+
CONFIG['debugflags'] = '-ggdb3 '
|
136
|
+
CONFIG['optflags'] = '-O0'
|
136
137
|
|
137
138
|
create_makefile('libsolarwinds_apm', 'src')
|
138
139
|
else
|
139
|
-
|
140
|
+
warn '== ERROR ========================================================='
|
140
141
|
if have_library('oboe')
|
141
|
-
|
142
|
-
|
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
|
-
|
145
|
+
warn 'Could not find a matching c-library. No tracing will occur.'
|
145
146
|
end
|
146
|
-
|
147
|
-
|
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
|
-
|
1
|
+
bcf8ad33da8e896e946e376f9e7d75a584bb98a3a4b41e89e231783f97a1380f
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
0cf5329232ec370db869fa207c2a27813d970199f3f319828155481718e2ab01
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
dd02f77cf106ed0f61a333ede73864db61d6c4c11b474a0db82c83d3ea6c7199
|
@@ -0,0 +1 @@
|
|
1
|
+
ff5cdc5a3da9a7585fd95bc806ac465993b97981832d8dc768d362e0ff1a3221
|
@@ -0,0 +1 @@
|
|
1
|
+
6caa7a24c9d3377f08b93ef6eb8191e2addb1f880ad4759fbafdf4e88b6620ce
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
8a35ff7ae2feb1ca630b15453143f3d440f91aeb1a7cc7b595d0039600fe297f
|
data/ext/oboe_metal/src/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
15.0.1
|
data/ext/oboe_metal/src/oboe.h
CHANGED
@@ -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
|
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
|
13
|
-
@reporter
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
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
|
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
|
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'] =
|
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
|
131
|
-
|
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
|
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
|
13
|
+
desc 'Copies a SolarWindsAPM gem initializer file to your application.'
|
12
14
|
|
13
|
-
@namespace =
|
15
|
+
@namespace = 'solarwinds_apm:install'
|
14
16
|
|
15
17
|
def copy_initializer
|
16
18
|
print_header
|
17
19
|
print_footer
|
18
20
|
|
19
|
-
template
|
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
|
27
|
-
say
|
28
|
-
say shell.set_color
|
29
|
-
say
|
30
|
-
say
|
31
|
-
say
|
32
|
-
say
|
33
|
-
say
|
34
|
-
say
|
35
|
-
say
|
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
|
41
|
-
say
|
42
|
-
say
|
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}))
|
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
|
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
|
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
|
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] != (
|
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)
|
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)
|
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
|
40
|
-
|
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)
|