solarwinds_apm 6.1.1 → 7.0.0.prev1
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/README.md +53 -4
- data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +0 -4
- data/lib/solarwinds_apm/api/current_trace_info.rb +10 -6
- data/lib/solarwinds_apm/api/custom_instrumentation.rb +80 -0
- data/lib/solarwinds_apm/api/custom_metrics.rb +8 -25
- data/lib/solarwinds_apm/api/tracing.rb +12 -27
- data/lib/solarwinds_apm/api/transaction_name.rb +6 -10
- data/lib/solarwinds_apm/api.rb +2 -0
- data/lib/solarwinds_apm/config.rb +1 -1
- data/lib/solarwinds_apm/constants.rb +1 -0
- data/lib/solarwinds_apm/noop/api.rb +5 -2
- data/lib/solarwinds_apm/noop.rb +0 -24
- data/lib/solarwinds_apm/opentelemetry/otlp_processor.rb +90 -69
- data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +0 -2
- data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +5 -4
- data/lib/solarwinds_apm/opentelemetry.rb +5 -7
- data/lib/solarwinds_apm/otel_native_config.rb +177 -0
- data/lib/solarwinds_apm/patch/README.md +15 -0
- data/lib/solarwinds_apm/patch/tag_sql/sw_dbo_utils.rb +35 -0
- data/lib/solarwinds_apm/patch/tag_sql/sw_mysql2_patch.rb +1 -12
- data/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb +39 -0
- data/lib/solarwinds_apm/patch/tag_sql_patch.rb +2 -0
- data/lib/solarwinds_apm/{noop/metadata.rb → sampling/dice.rb} +19 -17
- data/lib/solarwinds_apm/sampling/http_sampler.rb +87 -0
- data/lib/solarwinds_apm/sampling/json_sampler.rb +52 -0
- data/lib/solarwinds_apm/sampling/metrics.rb +38 -0
- data/lib/solarwinds_apm/sampling/oboe_sampler.rb +348 -0
- data/lib/solarwinds_apm/sampling/sampler.rb +197 -0
- data/lib/solarwinds_apm/sampling/sampling_constants.rb +127 -0
- data/lib/solarwinds_apm/sampling/sampling_patch.rb +49 -0
- data/lib/solarwinds_apm/sampling/setting_example.txt +1 -0
- data/lib/solarwinds_apm/{noop/context.rb → sampling/settings.rb} +14 -25
- data/lib/solarwinds_apm/sampling/token_bucket.rb +126 -0
- data/lib/solarwinds_apm/sampling/trace_options.rb +100 -0
- data/lib/solarwinds_apm/{patch.rb → sampling.rb} +20 -4
- data/lib/solarwinds_apm/{noop/span.rb → support/aws_resource_detector.rb} +5 -18
- data/lib/solarwinds_apm/support/logger_formatter.rb +1 -1
- data/lib/solarwinds_apm/support/logging_log_event.rb +1 -1
- data/lib/solarwinds_apm/support/lumberjack_formatter.rb +1 -1
- data/lib/solarwinds_apm/support/otlp_endpoint.rb +99 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/beanstalk.rb +51 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/ec2.rb +145 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/ecs.rb +173 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/eks.rb +174 -0
- data/lib/solarwinds_apm/support/resource_detector/aws/lambda.rb +66 -0
- data/lib/solarwinds_apm/support/resource_detector.rb +192 -0
- data/lib/solarwinds_apm/support/service_key_checker.rb +12 -6
- data/lib/solarwinds_apm/support/transaction_settings.rb +6 -0
- data/lib/solarwinds_apm/support/txn_name_manager.rb +54 -9
- data/lib/solarwinds_apm/support/utils.rb +9 -0
- data/lib/solarwinds_apm/support.rb +3 -4
- data/lib/solarwinds_apm/version.rb +4 -4
- data/lib/solarwinds_apm.rb +27 -73
- metadata +105 -50
- data/ext/oboe_metal/extconf.rb +0 -168
- data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-aarch64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-lambda-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +0 -1
- data/ext/oboe_metal/src/VERSION +0 -1
- data/ext/oboe_metal/src/bson/bson.h +0 -220
- data/ext/oboe_metal/src/bson/platform_hacks.h +0 -91
- data/ext/oboe_metal/src/init_solarwinds_apm.cc +0 -18
- data/ext/oboe_metal/src/oboe.h +0 -930
- data/ext/oboe_metal/src/oboe_api.cpp +0 -793
- data/ext/oboe_metal/src/oboe_api.h +0 -621
- data/ext/oboe_metal/src/oboe_debug.h +0 -17
- data/ext/oboe_metal/src/oboe_swig_wrap.cc +0 -10954
- data/lib/oboe_metal.rb +0 -187
- data/lib/solarwinds_apm/cert/star.appoptics.com.issuer.crt +0 -24
- data/lib/solarwinds_apm/oboe_init_options.rb +0 -222
- data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +0 -239
- data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +0 -174
- data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +0 -333
- data/lib/solarwinds_apm/otel_config.rb +0 -174
- data/lib/solarwinds_apm/otel_lambda_config.rb +0 -56
- data/lib/solarwinds_apm/patch/dummy_patch.rb +0 -12
- data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +0 -33
- data/lib/solarwinds_apm/support/support_report.rb +0 -99
- data/lib/solarwinds_apm/support/swomarginalia/LICENSE +0 -20
- data/lib/solarwinds_apm/support/swomarginalia/README.md +0 -46
- data/lib/solarwinds_apm/support/swomarginalia/comment.rb +0 -206
- data/lib/solarwinds_apm/support/swomarginalia/formatter.rb +0 -20
- data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +0 -55
- data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +0 -24
- data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +0 -89
- data/lib/solarwinds_apm/support/transaction_cache.rb +0 -57
- data/lib/solarwinds_apm/support/x_trace_options.rb +0 -138
@@ -1,56 +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 'solarwinds_apm/constants'
|
10
|
-
require 'solarwinds_apm/api'
|
11
|
-
require 'solarwinds_apm/support'
|
12
|
-
require 'solarwinds_apm/opentelemetry'
|
13
|
-
|
14
|
-
module SolarWindsAPM
|
15
|
-
# OTelLambdaConfig module
|
16
|
-
module OTelLambdaConfig
|
17
|
-
def self.initialize
|
18
|
-
return unless defined?(::OpenTelemetry::SDK::Configurator)
|
19
|
-
|
20
|
-
if ENV['OTEL_TRACES_EXPORTER'].to_s.empty?
|
21
|
-
ENV['OTEL_TRACES_EXPORTER'] = 'otlp'
|
22
|
-
elsif !ENV['OTEL_TRACES_EXPORTER'].include? 'otlp'
|
23
|
-
ENV['OTEL_TRACES_EXPORTER'] += ',otlp'
|
24
|
-
end
|
25
|
-
|
26
|
-
ENV['OTEL_RESOURCE_ATTRIBUTES'] = "sw.apm.version=#{SolarWindsAPM::Version::STRING},sw.data.module=apm,service.name=#{ENV['OTEL_SERVICE_NAME'] || ENV.fetch('AWS_LAMBDA_FUNCTION_NAME', nil)}," + ENV['OTEL_RESOURCE_ATTRIBUTES'].to_s
|
27
|
-
::OpenTelemetry::SDK.configure(&:use_all)
|
28
|
-
|
29
|
-
# append our propagators
|
30
|
-
::OpenTelemetry.propagation.instance_variable_get(:@propagators).append(SolarWindsAPM::OpenTelemetry::SolarWindsPropagator::TextMapPropagator.new)
|
31
|
-
|
32
|
-
# register metrics_exporter to meter_provider
|
33
|
-
::OpenTelemetry.meter_provider.add_metric_reader(::OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new)
|
34
|
-
|
35
|
-
# append our processors
|
36
|
-
::OpenTelemetry.tracer_provider.add_span_processor(SolarWindsAPM::OpenTelemetry::OTLPProcessor.new)
|
37
|
-
|
38
|
-
# configure sampler afterwards
|
39
|
-
::OpenTelemetry.tracer_provider.sampler = ::OpenTelemetry::SDK::Trace::Samplers.parent_based(
|
40
|
-
root: SolarWindsAPM::OpenTelemetry::SolarWindsSampler.new,
|
41
|
-
remote_parent_sampled: SolarWindsAPM::OpenTelemetry::SolarWindsSampler.new,
|
42
|
-
remote_parent_not_sampled: SolarWindsAPM::OpenTelemetry::SolarWindsSampler.new
|
43
|
-
)
|
44
|
-
|
45
|
-
SolarWindsAPM.logger.info do
|
46
|
-
"[#{name}/#{__method__}] SolarWindsAPM lambda configuration initialized \
|
47
|
-
\n Installed instrumentation: #{::OpenTelemetry.tracer_provider.instance_variable_get(:@registry).keys} \
|
48
|
-
\n SpanProcessor: #{::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors).map(&:class)} \
|
49
|
-
\n Sampler: #{::OpenTelemetry.tracer_provider.instance_variable_get(:@sampler).inspect} \
|
50
|
-
\n Resource: #{::OpenTelemetry.tracer_provider.instance_variable_get(:@resource).inspect}"
|
51
|
-
end
|
52
|
-
|
53
|
-
nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,33 +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
|
-
module SolarWindsAPM
|
10
|
-
# OboeTracingMode
|
11
|
-
# Used in solarwinds_sampler
|
12
|
-
class OboeTracingMode
|
13
|
-
OBOE_SETTINGS_UNSET = -1
|
14
|
-
OBOE_TRACE_DISABLED = 0
|
15
|
-
OBOE_TRACE_ENABLED = 1
|
16
|
-
OBOE_TRIGGER_DISABLED = 0
|
17
|
-
OBOE_TRIGGER_ENABLED = 1
|
18
|
-
|
19
|
-
def self.get_oboe_trace_mode(tracing_mode)
|
20
|
-
mode = OBOE_SETTINGS_UNSET
|
21
|
-
mode = OBOE_TRACE_ENABLED if tracing_mode == :enabled
|
22
|
-
mode = OBOE_TRACE_DISABLED if tracing_mode == :disabled
|
23
|
-
mode
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.get_oboe_trigger_trace_mode(trigger_trace_mode)
|
27
|
-
mode = OBOE_SETTINGS_UNSET
|
28
|
-
mode = OBOE_TRIGGER_ENABLED if trigger_trace_mode == :enabled
|
29
|
-
mode = OBOE_TRIGGER_DISABLED if trigger_trace_mode == :disabled
|
30
|
-
mode
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,99 +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 'rbconfig'
|
10
|
-
require 'logger'
|
11
|
-
|
12
|
-
##
|
13
|
-
# This module is used to debug problematic setups and/or environments.
|
14
|
-
# Depending on the environment, output may be to stdout or the framework
|
15
|
-
# log file (e.g. log/production.log)
|
16
|
-
module SolarWindsAPM
|
17
|
-
##
|
18
|
-
# yesno
|
19
|
-
#
|
20
|
-
# Utility method to translate value/nil to "yes"/"no" strings
|
21
|
-
def self.yesno(condition)
|
22
|
-
condition ? 'yes' : 'no'
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.support_report
|
26
|
-
@logger_level = SolarWindsAPM.logger.level
|
27
|
-
SolarWindsAPM.logger.level = ::Logger::DEBUG
|
28
|
-
|
29
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
30
|
-
SolarWindsAPM.logger.warn '* BEGIN SolarWindsAPM Support Report'
|
31
|
-
SolarWindsAPM.logger.warn '* Please email the output of this report to SWO-support@solarwinds.com'
|
32
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
33
|
-
SolarWindsAPM.logger.warn "Ruby: #{RUBY_DESCRIPTION}"
|
34
|
-
SolarWindsAPM.logger.warn "PROGRAM_NAME: #{$PROGRAM_NAME}" # replace $0 to get executing script
|
35
|
-
SolarWindsAPM.logger.warn "ARGV: #{ARGV.inspect}"
|
36
|
-
SolarWindsAPM.logger.warn "SolarWindsAPM.loaded == #{SolarWindsAPM.loaded}"
|
37
|
-
|
38
|
-
SolarWindsAPM.logger.warn "SolarWindsAPM::Ruby defined?: #{yesno(defined?(SolarWindsAPM::Ruby))}"
|
39
|
-
SolarWindsAPM.logger.warn "SolarWindsAPM.reporter: #{SolarWindsAPM.reporter}"
|
40
|
-
|
41
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
42
|
-
SolarWindsAPM.logger.warn '* Frameworks'
|
43
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
44
|
-
|
45
|
-
using_rails = defined?(::Rails)
|
46
|
-
SolarWindsAPM.logger.warn "Using Rails?: #{yesno(using_rails)}"
|
47
|
-
if using_rails
|
48
|
-
SolarWindsAPM.logger.warn "SolarWindsAPM::Rails loaded?: #{yesno(defined?(SolarWindsAPM::Rails))}"
|
49
|
-
SolarWindsAPM.logger.warn "SolarWindsAPM::Rack middleware loaded?: #{yesno(::Rails.configuration.middleware.include?(SolarWindsAPM::Rack))}" if defined?(SolarWindsAPM::Rack)
|
50
|
-
end
|
51
|
-
|
52
|
-
using_sinatra = defined?(::Sinatra)
|
53
|
-
SolarWindsAPM.logger.warn "Using Sinatra?: #{yesno(using_sinatra)}"
|
54
|
-
|
55
|
-
using_padrino = defined?(::Padrino)
|
56
|
-
SolarWindsAPM.logger.warn "Using Padrino?: #{yesno(using_padrino)}"
|
57
|
-
|
58
|
-
using_grape = defined?(::Grape)
|
59
|
-
SolarWindsAPM.logger.warn "Using Grape?: #{yesno(using_grape)}"
|
60
|
-
|
61
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
62
|
-
SolarWindsAPM.logger.warn '* ActiveRecord Adapter'
|
63
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
64
|
-
if defined?(::ActiveRecord)
|
65
|
-
if defined?(::ActiveRecord::Base.connection.adapter_name)
|
66
|
-
SolarWindsAPM.logger.warn "ActiveRecord adapter: #{::ActiveRecord::Base.connection.adapter_name}"
|
67
|
-
end
|
68
|
-
else
|
69
|
-
SolarWindsAPM.logger.warn 'No ActiveRecord'
|
70
|
-
end
|
71
|
-
|
72
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
73
|
-
SolarWindsAPM.logger.warn '* SolarWindsAPM::Config Values'
|
74
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
75
|
-
SolarWindsAPM.logger.warn SolarWindsAPM::Config.print_config.to_s
|
76
|
-
|
77
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
78
|
-
SolarWindsAPM.logger.warn '* SolarWindsAPM::OTelConfig Values'
|
79
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
80
|
-
SolarWindsAPM.logger.warn SolarWindsAPM::OTelConfig.print_config.to_s
|
81
|
-
|
82
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
83
|
-
SolarWindsAPM.logger.warn '* OS, Platform + Env'
|
84
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
85
|
-
SolarWindsAPM.logger.warn "host_os: #{RbConfig::CONFIG['host_os']}"
|
86
|
-
SolarWindsAPM.logger.warn "sitearch: #{RbConfig::CONFIG['sitearch']}"
|
87
|
-
SolarWindsAPM.logger.warn "arch: #{RbConfig::CONFIG['arch']}"
|
88
|
-
SolarWindsAPM.logger.warn "Platform: #{RUBY_PLATFORM}"
|
89
|
-
|
90
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
91
|
-
SolarWindsAPM.logger.warn '* END SolarWindsAPM Support Report'
|
92
|
-
SolarWindsAPM.logger.warn '* Support Email: technicalsupport@solarwinds.com'
|
93
|
-
SolarWindsAPM.logger.warn '* Github: https://github.com/solarwinds/apm-ruby'
|
94
|
-
SolarWindsAPM.logger.warn '********************************************************'
|
95
|
-
|
96
|
-
SolarWindsAPM.logger.level = @logger_level
|
97
|
-
nil
|
98
|
-
end
|
99
|
-
end
|
@@ -1,20 +0,0 @@
|
|
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.
|
@@ -1,46 +0,0 @@
|
|
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
|
-
```console
|
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
|
-
|
21
|
-
1. Moved prepend logic into load_swomarginalia.rb in case that non-rails app using activerecord
|
22
|
-
|
23
|
-
### swomarginlia.rb
|
24
|
-
|
25
|
-
1. Removed the alias_method to achieve function override; instead, we use prepend.
|
26
|
-
2. Added step of cleaning-up previous transparent comments
|
27
|
-
|
28
|
-
### comment.rb
|
29
|
-
|
30
|
-
1. Added the traceparent comment (trace string constructed based on opentelemetry)
|
31
|
-
|
32
|
-
### load_swomarginalia.rb
|
33
|
-
|
34
|
-
1. (new file) prepend the ActiveRecordInstrumentation to activerecord adapter
|
35
|
-
|
36
|
-
## Example
|
37
|
-
|
38
|
-
### Sample output of rails application
|
39
|
-
|
40
|
-
```console
|
41
|
-
Post Load (1.1ms) SELECT `posts`.* FROM `posts` /*application=SqlcommenterRailsDemo,controller=posts,action=index,traceparent=00-a448f096d441e167d12ebd32a927c1a5-a29655a47e430119-01*/
|
42
|
-
```
|
43
|
-
|
44
|
-
## License
|
45
|
-
|
46
|
-
This project is licensed under the [MIT License](https://github.com/solarwinds/apm-ruby/blob/main/lib/solarwinds_apm/support/swomarginalia/LICENSE).
|
@@ -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
|