solarwinds_apm 5.1.8 → 6.0.0.preV1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -1
- data/ext/oboe_metal/extconf.rb +19 -23
- 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-x86_64.so.sha256 +1 -1
- data/ext/oboe_metal/src/VERSION +1 -1
- data/ext/oboe_metal/src/oboe_api.cpp +9 -7
- data/ext/oboe_metal/src/oboe_api.h +7 -7
- data/ext/oboe_metal/src/oboe_debug.h +2 -0
- data/ext/oboe_metal/src/oboe_swig_wrap.cc +19 -18
- data/lib/oboe_metal.rb +116 -80
- data/lib/rails/generators/solarwinds_apm/install_generator.rb +1 -2
- data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +44 -260
- data/lib/solarwinds_apm/api/current_trace_info.rb +148 -0
- data/lib/solarwinds_apm/api/tracing.rb +30 -0
- data/lib/solarwinds_apm/api/transaction_name.rb +57 -0
- data/lib/solarwinds_apm/api.rb +8 -15
- data/lib/solarwinds_apm/base.rb +4 -131
- data/lib/solarwinds_apm/config.rb +128 -175
- data/lib/solarwinds_apm/constants.rb +32 -0
- data/lib/solarwinds_apm/logger.rb +1 -1
- data/lib/solarwinds_apm/noop/context.rb +2 -5
- data/lib/solarwinds_apm/noop/metadata.rb +1 -2
- data/lib/solarwinds_apm/noop/profiling.rb +3 -7
- data/lib/solarwinds_apm/oboe_init_options.rb +71 -33
- data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +204 -0
- data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +163 -0
- data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +92 -0
- data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +72 -0
- data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +330 -0
- data/lib/solarwinds_apm/opentelemetry.rb +8 -0
- data/lib/solarwinds_apm/otel_config.rb +161 -0
- data/lib/solarwinds_apm/{inst → support}/logger_formatter.rb +5 -6
- data/lib/solarwinds_apm/{inst → support}/logging_log_event.rb +3 -6
- data/lib/solarwinds_apm/{inst → support}/lumberjack_formatter.rb +1 -4
- data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +27 -0
- data/lib/solarwinds_apm/support/swomarginalia/LICENSE +20 -0
- data/lib/solarwinds_apm/support/swomarginalia/README.md +41 -0
- data/lib/solarwinds_apm/support/swomarginalia/comment.rb +205 -0
- data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +48 -0
- data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +22 -0
- data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +86 -0
- data/lib/solarwinds_apm/support/transaction_cache.rb +24 -0
- data/lib/solarwinds_apm/support/transaction_settings.rb +26 -209
- data/lib/solarwinds_apm/support/transformer.rb +56 -0
- data/lib/solarwinds_apm/support/txn_name_manager.rb +25 -0
- data/lib/solarwinds_apm/support/x_trace_options.rb +42 -26
- data/lib/solarwinds_apm/support.rb +33 -10
- data/lib/solarwinds_apm/support_report.rb +10 -32
- data/lib/solarwinds_apm/thread_local.rb +1 -1
- data/lib/solarwinds_apm/version.rb +4 -4
- data/lib/solarwinds_apm.rb +31 -26
- metadata +76 -121
- data/.dockerignore +0 -5
- data/.gitignore +0 -58
- data/.rubocop.yml +0 -29
- data/.whitesource +0 -22
- data/.yardopts +0 -7
- data/CHANGELOG-appoptics.md +0 -766
- data/CHANGELOG.md +0 -72
- data/CONFIG.md +0 -31
- data/Gemfile +0 -15
- data/README.md +0 -385
- data/bin/solarwinds_apm_config +0 -15
- data/examples/prepend.rb +0 -13
- data/examples/sdk_examples.rb +0 -158
- data/ext/oboe_metal/README.md +0 -69
- data/ext/oboe_metal/extconf_local.rb +0 -75
- data/ext/oboe_metal/lib/.keep +0 -0
- data/ext/oboe_metal/noop/noop.c +0 -8
- data/ext/oboe_metal/src/README.md +0 -6
- data/ext/oboe_metal/src/frames.cc +0 -247
- data/ext/oboe_metal/src/frames.h +0 -40
- data/ext/oboe_metal/src/logging.cc +0 -97
- data/ext/oboe_metal/src/logging.h +0 -34
- data/ext/oboe_metal/src/profiling.cc +0 -435
- data/ext/oboe_metal/src/profiling.h +0 -78
- data/ext/oboe_metal/test/CMakeLists.txt +0 -53
- data/ext/oboe_metal/test/FindGMock.cmake +0 -43
- data/ext/oboe_metal/test/README.md +0 -56
- data/ext/oboe_metal/test/frames_test.cc +0 -164
- data/ext/oboe_metal/test/profiling_test.cc +0 -93
- data/ext/oboe_metal/test/ruby_inc_dir.rb +0 -8
- data/ext/oboe_metal/test/ruby_prefix.rb +0 -8
- data/ext/oboe_metal/test/ruby_test_helper.rb +0 -67
- data/ext/oboe_metal/test/test.h +0 -11
- data/ext/oboe_metal/test/test_main.cc +0 -32
- data/init.rb +0 -4
- data/lib/solarwinds_apm/api/layerinit.rb +0 -41
- data/lib/solarwinds_apm/api/logging.rb +0 -356
- data/lib/solarwinds_apm/api/memcache.rb +0 -37
- data/lib/solarwinds_apm/api/metrics.rb +0 -63
- data/lib/solarwinds_apm/api/util.rb +0 -98
- data/lib/solarwinds_apm/frameworks/grape.rb +0 -96
- data/lib/solarwinds_apm/frameworks/padrino.rb +0 -78
- data/lib/solarwinds_apm/frameworks/rails/inst/action_controller.rb +0 -100
- data/lib/solarwinds_apm/frameworks/rails/inst/action_controller5.rb +0 -50
- data/lib/solarwinds_apm/frameworks/rails/inst/action_controller_api.rb +0 -50
- data/lib/solarwinds_apm/frameworks/rails/inst/action_view.rb +0 -88
- data/lib/solarwinds_apm/frameworks/rails/inst/active_record.rb +0 -26
- data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +0 -29
- data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +0 -22
- data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +0 -103
- data/lib/solarwinds_apm/frameworks/rails/inst/logger_formatters.rb +0 -14
- data/lib/solarwinds_apm/frameworks/rails.rb +0 -100
- data/lib/solarwinds_apm/frameworks/sinatra.rb +0 -96
- data/lib/solarwinds_apm/inst/bunny-client.rb +0 -157
- data/lib/solarwinds_apm/inst/bunny-consumer.rb +0 -102
- data/lib/solarwinds_apm/inst/curb.rb +0 -289
- data/lib/solarwinds_apm/inst/dalli.rb +0 -89
- data/lib/solarwinds_apm/inst/delayed_job.rb +0 -100
- data/lib/solarwinds_apm/inst/excon.rb +0 -113
- data/lib/solarwinds_apm/inst/faraday.rb +0 -96
- data/lib/solarwinds_apm/inst/graphql.rb +0 -206
- data/lib/solarwinds_apm/inst/grpc_client.rb +0 -147
- data/lib/solarwinds_apm/inst/grpc_server.rb +0 -119
- data/lib/solarwinds_apm/inst/httpclient.rb +0 -182
- data/lib/solarwinds_apm/inst/memcached.rb +0 -86
- data/lib/solarwinds_apm/inst/mongo.rb +0 -246
- data/lib/solarwinds_apm/inst/mongo2.rb +0 -225
- data/lib/solarwinds_apm/inst/moped.rb +0 -466
- data/lib/solarwinds_apm/inst/net_http.rb +0 -60
- data/lib/solarwinds_apm/inst/rack.rb +0 -223
- data/lib/solarwinds_apm/inst/rack_cache.rb +0 -35
- data/lib/solarwinds_apm/inst/redis.rb +0 -280
- data/lib/solarwinds_apm/inst/redis_v4.rb +0 -273
- data/lib/solarwinds_apm/inst/resque.rb +0 -129
- data/lib/solarwinds_apm/inst/rest-client.rb +0 -43
- data/lib/solarwinds_apm/inst/sequel.rb +0 -241
- data/lib/solarwinds_apm/inst/sidekiq-client.rb +0 -63
- data/lib/solarwinds_apm/inst/sidekiq-worker.rb +0 -64
- data/lib/solarwinds_apm/inst/typhoeus.rb +0 -90
- data/lib/solarwinds_apm/instrumentation.rb +0 -22
- data/lib/solarwinds_apm/loading.rb +0 -65
- data/lib/solarwinds_apm/ruby.rb +0 -35
- data/lib/solarwinds_apm/sdk/current_trace_info.rb +0 -123
- data/lib/solarwinds_apm/sdk/custom_metrics.rb +0 -94
- data/lib/solarwinds_apm/sdk/logging.rb +0 -37
- data/lib/solarwinds_apm/sdk/trace_context_headers.rb +0 -69
- data/lib/solarwinds_apm/sdk/tracing.rb +0 -432
- data/lib/solarwinds_apm/support/profiling.rb +0 -25
- data/lib/solarwinds_apm/support/trace_context.rb +0 -53
- data/lib/solarwinds_apm/support/trace_state.rb +0 -69
- data/lib/solarwinds_apm/support/trace_string.rb +0 -89
- data/lib/solarwinds_apm/support/transaction_metrics.rb +0 -67
- data/lib/solarwinds_apm/test.rb +0 -165
- data/lib/solarwinds_apm/util.rb +0 -426
- data/log/.keep +0 -0
- data/log/postgresql/.keep +0 -0
- data/solarwinds_apm.gemspec +0 -55
- data/yardoc_frontpage.md +0 -24
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright (c) 2012 37signals, LLC
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# swomarginalia
|
2
|
+
|
3
|
+
This folder contains the code that is copied from original [marginalia](https://github.com/basecamp/marginalia)
|
4
|
+
|
5
|
+
## File structure
|
6
|
+
|
7
|
+
```
|
8
|
+
|-- swomarginalia
|
9
|
+
| |-- LICENSE
|
10
|
+
| |-- README.md
|
11
|
+
| |-- comment.rb
|
12
|
+
| |-- railtie.rb
|
13
|
+
| |-- load_swomarginalia.rb
|
14
|
+
| `-- swomarginalia.rb
|
15
|
+
```
|
16
|
+
|
17
|
+
## Modification
|
18
|
+
|
19
|
+
### railitie.rb
|
20
|
+
1. Moved prepend logic into load_swomarginalia.rb in case that non-rails app using activerecord
|
21
|
+
|
22
|
+
### swomarginlia.rb
|
23
|
+
1. Removed the alias_method to achieve function override; instead, we use prepend.
|
24
|
+
2. Added step of cleaning-up previous transparent comments
|
25
|
+
|
26
|
+
### comment.rb
|
27
|
+
1. Added the traceparent comment (trace string constructed based on opentelemetry)
|
28
|
+
|
29
|
+
### load_swomarginalia.rb
|
30
|
+
1. (new file) prepend the ActiveRecordInstrumentation to activerecord adapter
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
### Sample output of rails application
|
35
|
+
|
36
|
+
```
|
37
|
+
Post Load (1.1ms) SELECT `posts`.* FROM `posts` /*application=SqlcommenterRailsDemo,controller=posts,action=index,traceparent=00-a448f096d441e167d12ebd32a927c1a5-a29655a47e430119-01*/
|
38
|
+
```
|
39
|
+
|
40
|
+
## License
|
41
|
+
This project is licensed under the [MIT License](https://github.com/solarwindscloud/swotel-ruby/tree/main/lib/solarwinds_apm/support/swomarginalia/LICENSE).
|
@@ -0,0 +1,205 @@
|
|
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 swotel-ruby, 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 = String.new
|
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
|
+
if defined?(::Rails.application)
|
82
|
+
SWOMarginalia.application_name ||= ::Rails.application.class.name.split("::").first
|
83
|
+
else
|
84
|
+
SWOMarginalia.application_name ||= "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}.freeze
|
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
|
+
rescue NameError => e
|
182
|
+
SolarWindsAPM.logger.error {"[#{self.name}/#{__method__}] Couldn't find OpenTelemetry. Error: #{e.message}"}
|
183
|
+
end
|
184
|
+
|
185
|
+
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1')
|
186
|
+
def self.connection_config
|
187
|
+
return if marginalia_adapter.pool.nil?
|
188
|
+
|
189
|
+
marginalia_adapter.pool.spec.config
|
190
|
+
end
|
191
|
+
else
|
192
|
+
def self.connection_config
|
193
|
+
# `pool` might be a NullPool which has no db_config
|
194
|
+
return unless marginalia_adapter.pool.respond_to?(:db_config)
|
195
|
+
|
196
|
+
marginalia_adapter.pool.db_config.configuration_hash
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def self.inline_annotations
|
201
|
+
Thread.current[:marginalia_inline_annotations] ||= []
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative './swomarginalia'
|
2
|
+
|
3
|
+
module SolarWindsAPM
|
4
|
+
module SWOMarginalia
|
5
|
+
module LoadSWOMarginalia
|
6
|
+
def self.insert
|
7
|
+
insert_into_active_record
|
8
|
+
insert_into_action_controller
|
9
|
+
insert_into_active_job
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.insert_into_active_job
|
13
|
+
return unless defined? ::ActiveJob::Base
|
14
|
+
|
15
|
+
::ActiveJob::Base.class_eval do
|
16
|
+
around_perform do |job, block|
|
17
|
+
begin
|
18
|
+
SWOMarginalia::Comment.update_job! job
|
19
|
+
block.call
|
20
|
+
ensure
|
21
|
+
SWOMarginalia::Comment.clear_job!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.insert_into_action_controller
|
28
|
+
return unless defined? ::ActionController::Base
|
29
|
+
|
30
|
+
::ActionController::Base.include SWOMarginalia::ActionControllerInstrumentation
|
31
|
+
|
32
|
+
return unless defined? ::ActionController::API
|
33
|
+
|
34
|
+
::ActionController::API.include SWOMarginalia::ActionControllerInstrumentation
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.insert_into_active_record
|
38
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
39
|
+
ActiveRecord::ConnectionAdapters::MysqlAdapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
|
40
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
41
|
+
return unless defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
42
|
+
|
43
|
+
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(SWOMarginalia::ActiveRecordInstrumentation) if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require_relative './load_swomarginalia'
|
3
|
+
|
4
|
+
module SolarWindsAPM
|
5
|
+
module SWOMarginalia
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'swomarginalia.insert' do
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_active_record
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveSupport.on_load :action_controller do
|
13
|
+
::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_action_controller
|
14
|
+
end
|
15
|
+
|
16
|
+
ActiveSupport.on_load :active_job do
|
17
|
+
::SolarWindsAPM::SWOMarginalia::LoadSWOMarginalia.insert_into_active_job
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative './comment'
|
2
|
+
|
3
|
+
module SolarWindsAPM
|
4
|
+
module SWOMarginalia
|
5
|
+
mattr_accessor :application_name
|
6
|
+
|
7
|
+
# This ActiveRecordInstrumentation should only work for activerecord < 7.0 since after rails 7
|
8
|
+
# this module won't be prepend to activerecord
|
9
|
+
module ActiveRecordInstrumentation
|
10
|
+
def execute(sql, *args)
|
11
|
+
super(annotate_sql(sql), *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute_and_clear(sql, *args, &block)
|
15
|
+
super(annotate_sql(sql), *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def exec_query(sql, *args, **options)
|
19
|
+
super(annotate_sql(sql), *args, **options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def exec_delete(sql, *args)
|
23
|
+
super(annotate_sql(sql), *args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def exec_update(sql, *args)
|
27
|
+
super(annotate_sql(sql), *args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def annotate_sql(sql)
|
31
|
+
SWOMarginalia::Comment.update_adapter!(self) # switch to current sql adapter
|
32
|
+
comment = SWOMarginalia::Comment.construct_comment # comment will include traceparent
|
33
|
+
if comment.present? && !sql.include?(comment)
|
34
|
+
sql = if SWOMarginalia::Comment.prepend_comment
|
35
|
+
"/*#{comment}*/ #{sql}"
|
36
|
+
else
|
37
|
+
"#{sql} /*#{comment}*/"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
inline_comment = SWOMarginalia::Comment.construct_inline_comment # this is for customized_swo_inline_annotations (user-defined value)
|
42
|
+
if inline_comment.present? && !sql.include?(inline_comment)
|
43
|
+
sql = if SWOMarginalia::Comment.prepend_comment
|
44
|
+
"/*#{inline_comment}*/ #{sql}"
|
45
|
+
else
|
46
|
+
"#{sql} /*#{inline_comment}*/"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
sql
|
51
|
+
end
|
52
|
+
|
53
|
+
# We don't want to trace framework caches.
|
54
|
+
# Only instrument SQL that directly hits the database.
|
55
|
+
def ignore_payload?(name)
|
56
|
+
%w(SCHEMA EXPLAIN CACHE).include?(name.to_s)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module ActionControllerInstrumentation
|
61
|
+
def self.included(instrumented_class)
|
62
|
+
instrumented_class.class_eval do
|
63
|
+
if respond_to?(:around_action)
|
64
|
+
around_action :record_query_comment
|
65
|
+
else
|
66
|
+
around_filter :record_query_comment
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def record_query_comment
|
72
|
+
SWOMarginalia::Comment.update!(self)
|
73
|
+
yield
|
74
|
+
ensure
|
75
|
+
SWOMarginalia::Comment.clear!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.with_annotation(comment, &block)
|
80
|
+
SWOMarginalia::Comment.inline_annotations.push(comment)
|
81
|
+
block.call if block.present?
|
82
|
+
ensure
|
83
|
+
SWOMarginalia::Comment.inline_annotations.pop
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SolarWindsAPM
|
2
|
+
# Simple TransactionCache
|
3
|
+
# TODO: improve cache to have lru mechanism that avoid too many values
|
4
|
+
module TransactionCache
|
5
|
+
def self.initialize
|
6
|
+
@cache = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get(key)
|
10
|
+
@cache[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.del(key)
|
14
|
+
@cache.delete(key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.set(key, value)
|
18
|
+
@cache[key] = value
|
19
|
+
SolarWindsAPM.logger.debug {"[#{self.class}/#{__method__}] current TransactionCache #{@cache.inspect}"}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
SolarWindsAPM::TransactionCache.initialize
|