solarwinds_apm 6.1.0 → 6.1.2

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -2
  3. data/ext/oboe_metal/extconf.rb +15 -9
  4. data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +1 -1
  5. data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +1 -1
  6. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +1 -1
  7. data/ext/oboe_metal/lib/liboboe-1.0-lambda-aarch64.so.sha256 +1 -1
  8. data/ext/oboe_metal/lib/liboboe-1.0-lambda-x86_64.so.sha256 +1 -1
  9. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
  10. data/ext/oboe_metal/src/VERSION +1 -1
  11. data/ext/oboe_metal/src/oboe.h +2 -1
  12. data/ext/oboe_metal/src/oboe_api.cpp +5 -3
  13. data/ext/oboe_metal/src/oboe_api.h +2 -1
  14. data/ext/oboe_metal/src/oboe_swig_wrap.cc +219 -120
  15. data/lib/oboe_metal.rb +8 -4
  16. data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +0 -4
  17. data/lib/solarwinds_apm/api/custom_instrumentation.rb +80 -0
  18. data/lib/solarwinds_apm/api.rb +2 -0
  19. data/lib/solarwinds_apm/oboe_init_options.rb +14 -1
  20. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +2 -2
  21. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +4 -3
  22. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +2 -0
  23. data/lib/solarwinds_apm/otel_config.rb +10 -0
  24. data/lib/solarwinds_apm/patch/tag_sql/sw_dbo_utils.rb +35 -0
  25. data/lib/solarwinds_apm/patch/tag_sql/sw_mysql2_patch.rb +25 -0
  26. data/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb +39 -0
  27. data/lib/solarwinds_apm/patch/tag_sql_patch.rb +11 -0
  28. data/lib/solarwinds_apm/support.rb +0 -14
  29. data/lib/solarwinds_apm/version.rb +1 -1
  30. metadata +10 -12
  31. data/lib/solarwinds_apm/support/swomarginalia/LICENSE +0 -20
  32. data/lib/solarwinds_apm/support/swomarginalia/README.md +0 -46
  33. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +0 -206
  34. data/lib/solarwinds_apm/support/swomarginalia/formatter.rb +0 -20
  35. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +0 -55
  36. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +0 -24
  37. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +0 -89
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'socket'
4
- require 'opentelemetry-api'
5
-
6
- module SolarWindsAPM
7
- module SWOMarginalia
8
- module Comment
9
- mattr_accessor :components, :lines_to_ignore, :prepend_comment
10
- SWOMarginalia::Comment.components ||= [:traceparent]
11
- # To add new components:
12
- # Create file and load after loading solarwinds_apm, and add following:
13
- # SolarWindsAPM::SWOMarginalia::Comment.component = [:user_defined]
14
-
15
- def self.update!(controller = nil)
16
- self.marginalia_controller = controller
17
- end
18
-
19
- def self.update_job!(job)
20
- self.marginalia_job = job
21
- end
22
-
23
- def self.update_adapter!(adapter)
24
- self.marginalia_adapter = adapter
25
- end
26
-
27
- def self.construct_comment
28
- ret = +''
29
- components.each do |c|
30
- component_value = send(c)
31
- ret << "#{c}='#{component_value}'," if component_value.present?
32
- end
33
- ret.chop!
34
- escape_sql_comment(ret)
35
- end
36
-
37
- def self.construct_inline_comment
38
- return nil if inline_annotations.none?
39
-
40
- escape_sql_comment(inline_annotations.join)
41
- end
42
-
43
- def self.escape_sql_comment(str)
44
- str = str.gsub('/*', '').gsub('*/', '') while str.include?('/*') || str.include?('*/')
45
- str
46
- end
47
-
48
- def self.clear!
49
- self.marginalia_controller = nil
50
- end
51
-
52
- def self.clear_job!
53
- self.marginalia_job = nil
54
- end
55
-
56
- def self.marginalia_controller=(controller)
57
- Thread.current[:marginalia_controller] = controller
58
- end
59
-
60
- def self.marginalia_controller
61
- Thread.current[:marginalia_controller]
62
- end
63
-
64
- def self.marginalia_job=(job)
65
- Thread.current[:marginalia_job] = job
66
- end
67
-
68
- def self.marginalia_job
69
- Thread.current[:marginalia_job]
70
- end
71
-
72
- def self.marginalia_adapter=(adapter)
73
- Thread.current[:marginalia_adapter] = adapter
74
- end
75
-
76
- def self.marginalia_adapter
77
- Thread.current[:marginalia_adapter]
78
- end
79
-
80
- def self.application
81
- SWOMarginalia.application_name ||= if defined?(::Rails.application)
82
- ::Rails.application.class.name.split('::').first
83
- else
84
- 'rails'
85
- end
86
-
87
- SWOMarginalia.application_name
88
- end
89
-
90
- def self.job
91
- marginalia_job&.class&.name
92
- end
93
-
94
- def self.controller
95
- marginalia_controller.controller_name if marginalia_controller.respond_to? :controller_name
96
- end
97
-
98
- def self.controller_with_namespace
99
- marginalia_controller&.class&.name
100
- end
101
-
102
- def self.action
103
- marginalia_controller.action_name if marginalia_controller.respond_to? :action_name
104
- end
105
-
106
- def self.sidekiq_job
107
- marginalia_job['class'] if marginalia_job.respond_to?(:[])
108
- end
109
-
110
- DEFAULT_LINES_TO_IGNORE_REGEX = %r{\.rvm|/ruby/gems/|vendor/|marginalia|rbenv|monitor\.rb.*mon_synchronize}
111
-
112
- def self.line
113
- SWOMarginalia::Comment.lines_to_ignore ||= DEFAULT_LINES_TO_IGNORE_REGEX
114
-
115
- last_line = caller.detect do |line|
116
- line !~ SWOMarginalia::Comment.lines_to_ignore
117
- end
118
- return unless last_line
119
-
120
- root = if defined?(Rails) && Rails.respond_to?(:root)
121
- Rails.root.to_s
122
- elsif defined?(RAILS_ROOT)
123
- RAILS_ROOT
124
- else
125
- ''
126
- end
127
- last_line = last_line[root.length..] if last_line.start_with? root
128
- last_line
129
- end
130
-
131
- def self.hostname
132
- @hostname ||= Socket.gethostname
133
- end
134
-
135
- def self.pid
136
- Process.pid
137
- end
138
-
139
- def self.request_id
140
- return unless marginalia_controller.respond_to?(:request) && marginalia_controller.request.respond_to?(:uuid)
141
-
142
- marginalia_controller.request.uuid
143
- end
144
-
145
- def self.socket
146
- return unless connection_config.present?
147
-
148
- connection_config[:socket]
149
- end
150
-
151
- def self.db_host
152
- return unless connection_config.present?
153
-
154
- connection_config[:host]
155
- end
156
-
157
- def self.database
158
- return unless connection_config.present?
159
-
160
- connection_config[:database]
161
- end
162
-
163
- ##
164
- # Insert trace string as traceparent to sql statement
165
- # Not insert if:
166
- # there is no valid current trace context
167
- # current trace context is not sampled
168
- #
169
- def self.traceparent
170
- span_context = ::OpenTelemetry::Trace.current_span.context
171
- return '' if span_context == ::OpenTelemetry::Trace::SpanContext::INVALID
172
-
173
- trace_flag = span_context.trace_flags.sampled? ? '01' : '00'
174
- return '' if trace_flag == '00'
175
-
176
- format(
177
- '00-%<trace_id>s-%<span_id>s-%<trace_flags>.2d',
178
- trace_id: span_context.hex_trace_id,
179
- span_id: span_context.hex_span_id,
180
- trace_flags: trace_flag
181
- )
182
- rescue NameError => e
183
- SolarWindsAPM.logger.error { "[#{name}/#{__method__}] Couldn't find OpenTelemetry. Error: #{e.message}" }
184
- end
185
-
186
- if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1')
187
- def self.connection_config
188
- return if marginalia_adapter.pool.nil?
189
-
190
- marginalia_adapter.pool.spec.config
191
- end
192
- else
193
- def self.connection_config
194
- # `pool` might be a NullPool which has no db_config
195
- return unless marginalia_adapter.pool.respond_to?(:db_config)
196
-
197
- marginalia_adapter.pool.db_config.configuration_hash
198
- end
199
- end
200
-
201
- def self.inline_annotations
202
- Thread.current[:marginalia_inline_annotations] ||= []
203
- end
204
- end
205
- end
206
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolarWindsAPM
4
- module SWOMarginalia
5
- module Formatter
6
- def tag_content
7
- comment = super
8
- comment.tr!(':', '=')
9
- comment
10
- end
11
- end
12
- end
13
- end
14
-
15
- # Prepend the Formatter module to the singleton class of ActiveRecord::QueryLogs
16
- if defined?(ActiveRecord::QueryLogs)
17
- class << ActiveRecord::QueryLogs
18
- prepend SolarWindsAPM::SWOMarginalia::Formatter
19
- end
20
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # © 2023 SolarWinds Worldwide, LLC. All rights reserved.
4
- #
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
6
- #
7
- # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8
-
9
- require_relative 'swomarginalia'
10
-
11
- module SolarWindsAPM
12
- module SWOMarginalia
13
- module LoadSWOMarginalia
14
- def self.insert
15
- insert_into_active_record
16
- insert_into_action_controller
17
- insert_into_active_job
18
- end
19
-
20
- def self.insert_into_active_job
21
- return unless defined? ::ActiveJob::Base
22
-
23
- ::ActiveJob::Base.class_eval do
24
- around_perform do |job, block|
25
- SWOMarginalia::Comment.update_job! job
26
- block.call
27
- ensure
28
- SWOMarginalia::Comment.clear_job!
29
- end
30
- end
31
- end
32
-
33
- def self.insert_into_action_controller
34
- return unless defined? ::ActionController::Base
35
-
36
- ::ActionController::Base.include SWOMarginalia::ActionControllerInstrumentation
37
-
38
- return unless defined? ::ActionController::API
39
-
40
- ::ActionController::API.include SWOMarginalia::ActionControllerInstrumentation
41
- end
42
-
43
- def self.insert_into_active_record
44
- ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
45
- ActiveRecord::ConnectionAdapters::MysqlAdapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
46
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
47
- return unless defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
48
-
49
- return unless defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
50
-
51
- ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(SWOMarginalia::ActiveRecordInstrumentation)
52
- end
53
- end
54
- end
55
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/railtie'
4
- require_relative 'load_swomarginalia'
5
-
6
- module SolarWindsAPM
7
- module SWOMarginalia
8
- class Railtie < Rails::Railtie
9
- initializer 'swomarginalia.insert' do
10
- ActiveSupport.on_load :active_record do
11
- ::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_active_record
12
- end
13
-
14
- ActiveSupport.on_load :action_controller do
15
- ::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_action_controller
16
- end
17
-
18
- ActiveSupport.on_load :active_job do
19
- ::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_active_job
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'comment'
4
-
5
- module SolarWindsAPM
6
- module SWOMarginalia
7
- mattr_accessor :application_name
8
-
9
- # This ActiveRecordInstrumentation should only work for activerecord < 7.0 since after rails 7
10
- # this module won't be prepend to activerecord
11
- module ActiveRecordInstrumentation
12
- def execute(sql, *args, **options)
13
- super(annotate_sql(sql), *args, **options)
14
- end
15
-
16
- # only for postgresql adapter
17
- def execute_and_clear(sql, *args, **options)
18
- super(annotate_sql(sql), *args, **options)
19
- end
20
-
21
- def exec_query(sql, *args, **options)
22
- super(annotate_sql(sql), *args, **options)
23
- end
24
-
25
- def exec_delete(sql, *args)
26
- super(annotate_sql(sql), *args)
27
- end
28
-
29
- def exec_update(sql, *args)
30
- super(annotate_sql(sql), *args)
31
- end
32
-
33
- def annotate_sql(sql)
34
- SWOMarginalia::Comment.update_adapter!(self) # switch to current sql adapter
35
- comment = SWOMarginalia::Comment.construct_comment # comment will include traceparent
36
- if comment.present? && !sql.include?(comment)
37
- sql = if SWOMarginalia::Comment.prepend_comment
38
- "/*#{comment}*/ #{sql}"
39
- else
40
- "#{sql} /*#{comment}*/"
41
- end
42
- end
43
-
44
- inline_comment = SWOMarginalia::Comment.construct_inline_comment # this is for customized_swo_inline_annotations (user-defined value)
45
- if inline_comment.present? && !sql.include?(inline_comment)
46
- sql = if SWOMarginalia::Comment.prepend_comment
47
- "/*#{inline_comment}*/ #{sql}"
48
- else
49
- "#{sql} /*#{inline_comment}*/"
50
- end
51
- end
52
-
53
- sql
54
- end
55
-
56
- # We don't want to trace framework caches.
57
- # Only instrument SQL that directly hits the database.
58
- def ignore_payload?(name)
59
- %w[SCHEMA EXPLAIN CACHE].include?(name.to_s)
60
- end
61
- end
62
-
63
- module ActionControllerInstrumentation
64
- def self.included(instrumented_class)
65
- instrumented_class.class_eval do
66
- if respond_to?(:around_action)
67
- around_action :record_query_comment
68
- else
69
- around_filter :record_query_comment
70
- end
71
- end
72
- end
73
-
74
- def record_query_comment
75
- SWOMarginalia::Comment.update!(self)
76
- yield
77
- ensure
78
- SWOMarginalia::Comment.clear!
79
- end
80
- end
81
-
82
- def self.with_annotation(comment, &block)
83
- SWOMarginalia::Comment.inline_annotations.push(comment)
84
- yield if block.present?
85
- ensure
86
- SWOMarginalia::Comment.inline_annotations.pop
87
- end
88
- end
89
- end