skywalking 0.0.0.alpha → 0.0.0.beta2
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/.dockerignore +19 -0
- data/.github/PULL_REQUEST_TEMPLATE +42 -0
- data/.github/workflows/ci.yml +70 -0
- data/.github/workflows/e2e.yml +73 -0
- data/.gitignore +80 -0
- data/.gitmodules +18 -0
- data/.licenserc.yaml +36 -0
- data/.rspec +1 -2
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +20 -0
- data/NOTICE +1 -1
- data/README.md +3 -0
- data/docs/README.md +7 -0
- data/docs/en/agent/plugins.md +12 -0
- data/docs/{How-to-release.md → en/development-and-contribution/how-to-release.md} +6 -5
- data/docs/en/setup/quick-start.md +106 -0
- data/docs/menu.yml +31 -0
- data/lib/rails/generators/skywalking/start_generator.rb +47 -0
- data/{examples/rails-demo/config/initializers/skywalking_ruby.rb → lib/rails/generators/skywalking/templates/skywalking_initializer.rb} +0 -2
- data/lib/skywalking/agent.rb +5 -5
- data/lib/skywalking/configuration.rb +55 -34
- data/lib/skywalking/environment.rb +103 -11
- data/lib/skywalking/log/logger.rb +1 -1
- data/lib/skywalking/plugins/elasticsearch.rb +61 -0
- data/lib/skywalking/plugins/memcached.rb +74 -0
- data/lib/skywalking/plugins/net_http.rb +73 -0
- data/lib/skywalking/plugins/redis5.rb +8 -3
- data/lib/skywalking/plugins/sinatra.rb +6 -5
- data/lib/skywalking/plugins_manager.rb +1 -1
- data/lib/skywalking/reporter/buffer_trigger.rb +1 -1
- data/lib/skywalking/reporter/client/grpc_client.rb +2 -2
- data/lib/skywalking/reporter/report.rb +1 -1
- data/lib/skywalking/tracing/carrier.rb +9 -8
- data/lib/skywalking/tracing/constants.rb +13 -18
- data/lib/skywalking/tracing/exit_span.rb +1 -1
- data/lib/skywalking/tracing/noop_span.rb +1 -1
- data/lib/skywalking/tracing/segment.rb +1 -1
- data/lib/skywalking/tracing/span.rb +2 -1
- data/lib/skywalking/tracing/span_context.rb +6 -6
- data/lib/skywalking/tracing/tag.rb +50 -1
- data/lib/skywalking/version.rb +1 -1
- data/skywalking.gemspec +58 -0
- data/spec/fixtures/agent.yaml +33 -0
- data/spec/scenarios/common/Dockerfile.agent +26 -0
- data/spec/scenarios/common/base-compose.yml +46 -0
- data/spec/scenarios/common/common_spec_helper.rb +40 -0
- data/spec/scenarios/common/compose_context.rb +39 -0
- data/spec/scenarios/common/validator.rb +41 -0
- data/spec/scenarios/elasticsearch/docker-compose.yml +72 -0
- data/spec/scenarios/elasticsearch/elasticsearch.rb +54 -0
- data/spec/scenarios/elasticsearch/elasticsearch_spec.rb +29 -0
- data/spec/scenarios/elasticsearch/expected.yml +94 -0
- data/spec/scenarios/memcached/docker-compose.yml +67 -0
- data/spec/scenarios/memcached/expected.yml +81 -0
- data/spec/scenarios/memcached/memcached.rb +31 -0
- data/spec/scenarios/memcached/memcached_spec.rb +29 -0
- data/spec/scenarios/net_http/docker-compose.yml +49 -0
- data/spec/scenarios/net_http/expected.yml +39 -0
- data/spec/scenarios/net_http/net_http.rb +33 -0
- data/spec/scenarios/net_http/net_http_spec.rb +43 -0
- data/spec/scenarios/redis/docker-compose.yml +67 -0
- data/spec/scenarios/redis/expected.yml +66 -0
- data/{examples/sinatra-demo/sinatra-demo.rb → spec/scenarios/redis/redis.rb} +8 -10
- data/spec/scenarios/redis/redis_spec.rb +29 -0
- data/spec/scenarios/sinatra/docker-compose.yml +54 -0
- data/spec/scenarios/sinatra/expected.yml +38 -0
- data/spec/scenarios/sinatra/sinatra.rb +26 -0
- data/spec/scenarios/sinatra/sinatra_spec.rb +29 -0
- data/spec/skywalking/config_spec.rb +41 -0
- data/spec/skywalking/utils/id_gen_spec.rb +26 -0
- data/spec/spec_helper.rb +115 -0
- metadata +102 -143
- data/examples/rails-demo/.dockerignore +0 -47
- data/examples/rails-demo/.gitattributes +0 -9
- data/examples/rails-demo/.gitignore +0 -34
- data/examples/rails-demo/.kamal/hooks/docker-setup.sample +0 -3
- data/examples/rails-demo/.kamal/hooks/post-deploy.sample +0 -14
- data/examples/rails-demo/.kamal/hooks/post-proxy-reboot.sample +0 -3
- data/examples/rails-demo/.kamal/hooks/pre-build.sample +0 -51
- data/examples/rails-demo/.kamal/hooks/pre-connect.sample +0 -47
- data/examples/rails-demo/.kamal/hooks/pre-deploy.sample +0 -109
- data/examples/rails-demo/.kamal/hooks/pre-proxy-reboot.sample +0 -3
- data/examples/rails-demo/.kamal/secrets +0 -17
- data/examples/rails-demo/.rubocop.yml +0 -8
- data/examples/rails-demo/.ruby-version +0 -1
- data/examples/rails-demo/Dockerfile +0 -72
- data/examples/rails-demo/Gemfile +0 -64
- data/examples/rails-demo/README.md +0 -24
- data/examples/rails-demo/Rakefile +0 -6
- data/examples/rails-demo/app/assets/images/.keep +0 -0
- data/examples/rails-demo/app/assets/stylesheets/application.css +0 -10
- data/examples/rails-demo/app/controllers/application_controller.rb +0 -4
- data/examples/rails-demo/app/controllers/concerns/.keep +0 -0
- data/examples/rails-demo/app/helpers/application_helper.rb +0 -2
- data/examples/rails-demo/app/javascript/application.js +0 -3
- data/examples/rails-demo/app/javascript/controllers/application.js +0 -9
- data/examples/rails-demo/app/javascript/controllers/hello_controller.js +0 -7
- data/examples/rails-demo/app/javascript/controllers/index.js +0 -4
- data/examples/rails-demo/app/jobs/application_job.rb +0 -7
- data/examples/rails-demo/app/mailers/application_mailer.rb +0 -4
- data/examples/rails-demo/app/models/application_record.rb +0 -3
- data/examples/rails-demo/app/models/concerns/.keep +0 -0
- data/examples/rails-demo/app/views/layouts/application.html.erb +0 -28
- data/examples/rails-demo/app/views/layouts/mailer.html.erb +0 -13
- data/examples/rails-demo/app/views/layouts/mailer.text.erb +0 -1
- data/examples/rails-demo/app/views/pwa/manifest.json.erb +0 -22
- data/examples/rails-demo/app/views/pwa/service-worker.js +0 -26
- data/examples/rails-demo/bin/brakeman +0 -7
- data/examples/rails-demo/bin/bundle +0 -109
- data/examples/rails-demo/bin/dev +0 -2
- data/examples/rails-demo/bin/docker-entrypoint +0 -14
- data/examples/rails-demo/bin/importmap +0 -4
- data/examples/rails-demo/bin/jobs +0 -6
- data/examples/rails-demo/bin/kamal +0 -27
- data/examples/rails-demo/bin/rails +0 -4
- data/examples/rails-demo/bin/rake +0 -4
- data/examples/rails-demo/bin/rubocop +0 -8
- data/examples/rails-demo/bin/setup +0 -34
- data/examples/rails-demo/bin/thrust +0 -5
- data/examples/rails-demo/config/application.rb +0 -27
- data/examples/rails-demo/config/boot.rb +0 -4
- data/examples/rails-demo/config/cable.yml +0 -17
- data/examples/rails-demo/config/cache.yml +0 -16
- data/examples/rails-demo/config/credentials.yml.enc +0 -1
- data/examples/rails-demo/config/database.yml +0 -41
- data/examples/rails-demo/config/deploy.yml +0 -116
- data/examples/rails-demo/config/environment.rb +0 -5
- data/examples/rails-demo/config/environments/development.rb +0 -72
- data/examples/rails-demo/config/environments/production.rb +0 -90
- data/examples/rails-demo/config/environments/test.rb +0 -53
- data/examples/rails-demo/config/importmap.rb +0 -7
- data/examples/rails-demo/config/initializers/assets.rb +0 -7
- data/examples/rails-demo/config/initializers/content_security_policy.rb +0 -25
- data/examples/rails-demo/config/initializers/filter_parameter_logging.rb +0 -8
- data/examples/rails-demo/config/initializers/inflections.rb +0 -16
- data/examples/rails-demo/config/locales/en.yml +0 -31
- data/examples/rails-demo/config/puma.rb +0 -41
- data/examples/rails-demo/config/queue.yml +0 -18
- data/examples/rails-demo/config/recurring.yml +0 -10
- data/examples/rails-demo/config/routes.rb +0 -14
- data/examples/rails-demo/config/storage.yml +0 -34
- data/examples/rails-demo/config.ru +0 -6
- data/examples/rails-demo/db/cable_schema.rb +0 -11
- data/examples/rails-demo/db/cache_schema.rb +0 -14
- data/examples/rails-demo/db/queue_schema.rb +0 -129
- data/examples/rails-demo/db/seeds.rb +0 -9
- data/examples/rails-demo/lib/tasks/.keep +0 -0
- data/examples/rails-demo/log/.keep +0 -0
- data/examples/rails-demo/public/400.html +0 -114
- data/examples/rails-demo/public/404.html +0 -114
- data/examples/rails-demo/public/406-unsupported-browser.html +0 -114
- data/examples/rails-demo/public/422.html +0 -114
- data/examples/rails-demo/public/500.html +0 -114
- data/examples/rails-demo/public/icon.png +0 -0
- data/examples/rails-demo/public/icon.svg +0 -3
- data/examples/rails-demo/public/robots.txt +0 -1
- data/examples/rails-demo/script/.keep +0 -0
- data/examples/rails-demo/storage/.keep +0 -0
- data/examples/rails-demo/test/application_system_test_case.rb +0 -5
- data/examples/rails-demo/test/controllers/.keep +0 -0
- data/examples/rails-demo/test/fixtures/files/.keep +0 -0
- data/examples/rails-demo/test/helpers/.keep +0 -0
- data/examples/rails-demo/test/integration/.keep +0 -0
- data/examples/rails-demo/test/mailers/.keep +0 -0
- data/examples/rails-demo/test/models/.keep +0 -0
- data/examples/rails-demo/test/system/.keep +0 -0
- data/examples/rails-demo/test/test_helper.rb +0 -15
- data/examples/rails-demo/tmp/.keep +0 -0
- data/examples/rails-demo/tmp/pids/.keep +0 -0
- data/examples/rails-demo/tmp/storage/.keep +0 -0
- data/examples/rails-demo/vendor/.keep +0 -0
- data/examples/rails-demo/vendor/javascript/.keep +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership.
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
6
|
+
# the License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Skywalking
|
17
|
+
class StartGenerator < ::Rails::Generators::Base
|
18
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
19
|
+
desc 'Creates a skywalking initializer'
|
20
|
+
|
21
|
+
@namespace = "skywalking:start"
|
22
|
+
|
23
|
+
def copy_initializer
|
24
|
+
print_header
|
25
|
+
print_footer
|
26
|
+
|
27
|
+
template "skywalking_initializer.rb", "config/initializers/skywalking.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def print_header
|
33
|
+
say ""
|
34
|
+
say shell.set_color "Welcome to the SkyWalking Ruby Agent instrumentation setup.", :green, :bold
|
35
|
+
say ""
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_footer
|
39
|
+
say ""
|
40
|
+
say "You can configure skywalking start parameters by modifying config/initializers/skywalking.rb."
|
41
|
+
say ""
|
42
|
+
say "Thanks for using! Welcome to contribute to the SkyWalking community."
|
43
|
+
say ""
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/lib/skywalking/agent.rb
CHANGED
@@ -41,7 +41,9 @@ module Skywalking
|
|
41
41
|
config ||= {}
|
42
42
|
config = Configuration.new(config) unless config.is_a?(Configuration)
|
43
43
|
|
44
|
-
@
|
44
|
+
@logger = config.logger
|
45
|
+
@agent_config = config.agent_config
|
46
|
+
@agent = new(@agent_config).start!
|
45
47
|
config.freeze
|
46
48
|
end
|
47
49
|
end
|
@@ -59,12 +61,10 @@ module Skywalking
|
|
59
61
|
!!(defined?(@agent) && @agent)
|
60
62
|
end
|
61
63
|
|
62
|
-
|
63
|
-
@config ||= Configuration.new.agent_config
|
64
|
-
end
|
64
|
+
attr_reader :logger, :agent_config
|
65
65
|
end
|
66
66
|
|
67
|
-
attr_reader :plugins, :
|
67
|
+
attr_reader :plugins, :reporter
|
68
68
|
|
69
69
|
def initialize(config)
|
70
70
|
@plugins = Plugins::PluginsManager.new(config)
|
@@ -29,7 +29,17 @@ module Skywalking
|
|
29
29
|
default: 'Your_InstanceName',
|
30
30
|
desc: 'The name of this particular awesome Ruby service instance'
|
31
31
|
},
|
32
|
-
:
|
32
|
+
:namespace => {
|
33
|
+
type: :string,
|
34
|
+
default: '',
|
35
|
+
desc: 'The namespace of the service'
|
36
|
+
},
|
37
|
+
:environment => {
|
38
|
+
type: :string,
|
39
|
+
default: '',
|
40
|
+
desc: 'The name of the environment this service is deployed in'
|
41
|
+
},
|
42
|
+
:collector_backend_services => {
|
33
43
|
type: :string,
|
34
44
|
default: '127.0.0.1:11800',
|
35
45
|
desc: 'Backend service addresses'
|
@@ -37,16 +47,16 @@ module Skywalking
|
|
37
47
|
:config_file => {
|
38
48
|
type: :string,
|
39
49
|
default: '',
|
40
|
-
desc: 'The path to the
|
50
|
+
desc: 'The absolute path to the configuration file'
|
41
51
|
},
|
42
|
-
:
|
52
|
+
:log_file_name => {
|
43
53
|
type: :string,
|
44
|
-
default: 'skywalking
|
54
|
+
default: 'skywalking',
|
45
55
|
desc: 'The name of the log file'
|
46
56
|
},
|
47
57
|
:log_file_path => {
|
48
58
|
type: :string,
|
49
|
-
default: '
|
59
|
+
default: '',
|
50
60
|
desc: 'The path to the log file'
|
51
61
|
},
|
52
62
|
:log_level => {
|
@@ -57,7 +67,7 @@ module Skywalking
|
|
57
67
|
:disable_plugins => {
|
58
68
|
type: :string,
|
59
69
|
default: '',
|
60
|
-
desc:
|
70
|
+
desc: "The plugins to disable, multiple names should be split by comma, e.g. 'redis5,elasticsearch'"
|
61
71
|
},
|
62
72
|
:report_protocol => {
|
63
73
|
type: :string,
|
@@ -69,11 +79,6 @@ module Skywalking
|
|
69
79
|
default: '',
|
70
80
|
desc: 'Ignore specific URL paths'
|
71
81
|
},
|
72
|
-
:namespace => {
|
73
|
-
type: :string,
|
74
|
-
default: '',
|
75
|
-
desc: 'The namespace of the service'
|
76
|
-
},
|
77
82
|
:instance_properties_json => {
|
78
83
|
type: :string,
|
79
84
|
default: '',
|
@@ -98,19 +103,24 @@ module Skywalking
|
|
98
103
|
}.freeze
|
99
104
|
|
100
105
|
# @api private
|
101
|
-
attr_reader :agent_config
|
106
|
+
attr_reader :agent_config, :logger
|
102
107
|
|
103
108
|
def initialize(opts = {})
|
104
109
|
@agent_config = {}
|
105
110
|
initialize_config(opts)
|
111
|
+
if @logger.nil?
|
112
|
+
@logger ||= Mutex.new.synchronize { build_logger }
|
113
|
+
end
|
106
114
|
end
|
107
115
|
|
108
116
|
def initialize_config(opts)
|
109
117
|
# from the default value
|
110
118
|
merge_config(DEFAULTS.transform_values { |v| v[:default] })
|
119
|
+
# start parameters
|
111
120
|
merge_config(opts)
|
112
121
|
# from the custom config file
|
113
122
|
merge_config(override_config_by_file)
|
123
|
+
# environment variables
|
114
124
|
merge_config(override_config_by_env)
|
115
125
|
end
|
116
126
|
|
@@ -124,10 +134,15 @@ module Skywalking
|
|
124
134
|
|
125
135
|
def override_config_by_file
|
126
136
|
config_yaml = @agent_config[:config_file]
|
127
|
-
|
137
|
+
if config_yaml.nil? || config_yaml.empty?
|
138
|
+
config_yaml = File.join(srv_root, "config", "skywalking.yml")
|
139
|
+
end
|
128
140
|
|
129
141
|
unless File.exist?(config_yaml)
|
130
|
-
|
142
|
+
return
|
143
|
+
end
|
144
|
+
|
145
|
+
unless srv_environment
|
131
146
|
return
|
132
147
|
end
|
133
148
|
|
@@ -140,10 +155,10 @@ module Skywalking
|
|
140
155
|
else
|
141
156
|
YAML.safe_load(erb_file, permitted_classes: [], permitted_symbols: [], aliases: true)
|
142
157
|
end
|
158
|
+
loaded_yaml = loaded_yaml[srv_environment]
|
143
159
|
error = "Invalid format in config file" if loaded_yaml && !loaded_yaml.is_a?(Hash)
|
144
160
|
rescue Exception => e
|
145
161
|
error = e.message
|
146
|
-
logger.error "override config by file failed, error=%s", e.message
|
147
162
|
nil
|
148
163
|
end
|
149
164
|
raise StandardError, "Error loading config file: #{config_yaml} - #{error}" if error
|
@@ -187,14 +202,18 @@ module Skywalking
|
|
187
202
|
self
|
188
203
|
end
|
189
204
|
|
205
|
+
def srv_environment
|
206
|
+
@agent_config[:environment].to_s.empty? ? Skywalking::Environment.instance.framework_env : @agent_config[:environment]
|
207
|
+
end
|
208
|
+
|
209
|
+
def srv_root
|
210
|
+
Skywalking::Environment.instance.framework_root
|
211
|
+
end
|
212
|
+
|
190
213
|
#####
|
191
214
|
# LOAD LOG
|
192
215
|
#####
|
193
|
-
def
|
194
|
-
@logger ||= Mutex.new.synchronize { get_logger }
|
195
|
-
end
|
196
|
-
|
197
|
-
def get_logger
|
216
|
+
def build_logger
|
198
217
|
return @logger if @logger
|
199
218
|
|
200
219
|
log_dest = log_destination
|
@@ -203,17 +222,17 @@ module Skywalking
|
|
203
222
|
|
204
223
|
def create_log(log_dest, level)
|
205
224
|
if log_dest.is_a?(String)
|
206
|
-
log_dest = File.expand_path(
|
225
|
+
log_dest = File.expand_path(log_dest, Pathname.new(Dir.pwd).realpath)
|
207
226
|
FileUtils.mkdir_p(File.dirname(log_dest))
|
208
227
|
end
|
209
228
|
|
210
229
|
begin
|
211
|
-
logger = ::Logger.new(log_dest, progname: "Skywalking
|
230
|
+
logger = ::Logger.new(log_dest, progname: "Skywalking", level: level)
|
212
231
|
logger.formatter = log_formatter
|
213
232
|
|
214
233
|
logger
|
215
234
|
rescue => e
|
216
|
-
logger = ::Logger.new($stdout, progname: "Skywalking
|
235
|
+
logger = ::Logger.new($stdout, progname: "Skywalking", level: level)
|
217
236
|
logger.warn "Create logger for file #{log_dest} failed, using standard out for logging error=#{e.message}"
|
218
237
|
end
|
219
238
|
end
|
@@ -226,30 +245,32 @@ module Skywalking
|
|
226
245
|
end
|
227
246
|
|
228
247
|
def log_destination
|
229
|
-
|
248
|
+
candidate = @agent_config[:log_file_path].upcase
|
249
|
+
|
250
|
+
case candidate
|
251
|
+
when "STDOUT"
|
230
252
|
$stdout
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
"#{agent_config[:log_file_path]}/skywalking.log"
|
235
|
-
else
|
253
|
+
when "STDERR"
|
254
|
+
$stderr
|
255
|
+
when nil? || ''
|
236
256
|
$stdout
|
257
|
+
else
|
258
|
+
"#{@agent_config[:log_file_path]}/#{@agent_config[:log_file_name]}.log"
|
237
259
|
end
|
238
260
|
end
|
239
261
|
|
240
262
|
def get_log_level
|
241
|
-
|
263
|
+
candidate = @agent_config[:log_level].downcase
|
264
|
+
|
265
|
+
case candidate
|
242
266
|
when "debug" then ::Logger::DEBUG
|
243
267
|
when "info" then ::Logger::INFO
|
244
268
|
when "warn" then ::Logger::WARN
|
245
269
|
when "error" then ::Logger::ERROR
|
246
270
|
when "fatal" then ::Logger::FATAL
|
271
|
+
when ::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR, ::Logger::FATAL then candidate
|
247
272
|
else ::Logger::INFO
|
248
273
|
end
|
249
274
|
end
|
250
|
-
|
251
|
-
def stdout?
|
252
|
-
@agent_config[:log_file_path] == "STDOUT"
|
253
|
-
end
|
254
275
|
end
|
255
276
|
end
|
@@ -20,27 +20,119 @@ module Skywalking
|
|
20
20
|
include Singleton
|
21
21
|
include Log::Logging
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
class RailsFramework
|
24
|
+
def name
|
25
|
+
:rails
|
26
|
+
end
|
27
|
+
|
28
|
+
def present?
|
29
|
+
defined?(::Rails) && defined?(::Rails::VERSION)
|
30
|
+
end
|
31
|
+
|
32
|
+
def app_name
|
33
|
+
if defined?(::Rails)
|
34
|
+
::Rails.application.class.to_s
|
35
|
+
.sub(/::Application$/, '')
|
36
|
+
end
|
37
|
+
rescue
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def env
|
42
|
+
::Rails.env
|
43
|
+
end
|
25
44
|
end
|
26
45
|
|
27
|
-
|
28
|
-
|
29
|
-
:rails
|
30
|
-
elsif defined?(::Sinatra::Base)
|
46
|
+
class SinatraFramework
|
47
|
+
def name
|
31
48
|
:sinatra
|
32
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
def present?
|
52
|
+
defined?(::Sinatra) && defined?(::Sinatra::Base)
|
53
|
+
end
|
54
|
+
|
55
|
+
def app_name
|
56
|
+
candidate = ObjectSpace.each_object(Class).select { |klass| klass < ::Sinatra::Base } - [::Sinatra::Application]
|
57
|
+
|
58
|
+
if candidate.length == 1
|
59
|
+
candidate.first.name
|
60
|
+
else
|
61
|
+
"Sinatra"
|
62
|
+
end
|
63
|
+
rescue
|
64
|
+
"Sinatra"
|
65
|
+
end
|
66
|
+
|
67
|
+
def env
|
68
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class RubyFramework
|
73
|
+
def name
|
33
74
|
:ruby
|
34
75
|
end
|
76
|
+
|
77
|
+
def present?
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
def app_name
|
82
|
+
"Ruby"
|
83
|
+
end
|
84
|
+
|
85
|
+
def env
|
86
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
FRAMEWORKS = [
|
91
|
+
RailsFramework.new,
|
92
|
+
SinatraFramework.new,
|
93
|
+
RubyFramework.new
|
94
|
+
].freeze
|
95
|
+
|
96
|
+
def framework_info
|
97
|
+
@framework ||= FRAMEWORKS.detect { |candidate| candidate.present? }
|
98
|
+
end
|
99
|
+
|
100
|
+
def framework_name
|
101
|
+
@framework_name ||= framework_info.name
|
102
|
+
end
|
103
|
+
|
104
|
+
def framework_root
|
105
|
+
@framework_root ||= case @framework_name
|
106
|
+
when :rails
|
107
|
+
::Rails.root
|
108
|
+
when :sinatra
|
109
|
+
Sinatra::Application.root || "."
|
110
|
+
else
|
111
|
+
"."
|
112
|
+
end
|
35
113
|
end
|
36
114
|
|
37
|
-
def
|
38
|
-
@
|
115
|
+
def framework_env
|
116
|
+
@framework_env ||= framework_info.env
|
117
|
+
end
|
118
|
+
|
119
|
+
def app_name
|
120
|
+
framework_info.app_name
|
121
|
+
end
|
122
|
+
|
123
|
+
def rails?
|
124
|
+
if defined?(::Rails)
|
125
|
+
::Rails.application.class.to_s
|
126
|
+
.sub(/::Application$/, '')
|
127
|
+
end
|
128
|
+
rescue
|
129
|
+
nil
|
39
130
|
end
|
40
131
|
|
41
132
|
def shutdown_handler_supported?
|
42
|
-
|
43
|
-
|
133
|
+
case framework_name
|
134
|
+
when :sinatra
|
135
|
+
warn "Shutdown handler not supported for Sinatra"
|
44
136
|
false
|
45
137
|
else
|
46
138
|
true
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership.
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
6
|
+
# the License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Skywalking
|
17
|
+
module Plugins
|
18
|
+
class Elasticsearch < PluginsManager::SWPlugin
|
19
|
+
def plugin_valid?
|
20
|
+
defined?(::Elasticsearch)
|
21
|
+
end
|
22
|
+
|
23
|
+
def install
|
24
|
+
inst_target = if defined?(::Elastic::Transport::Client)
|
25
|
+
::Elastic::Transport::Client
|
26
|
+
elsif defined?(::Elasticsearch::Transport::Client)
|
27
|
+
::Elasticsearch::Transport::Client
|
28
|
+
end
|
29
|
+
|
30
|
+
inst_target.class_eval do
|
31
|
+
def perform_request_with_skywalking(method, path, *args, &block)
|
32
|
+
peer_info = transport.hosts.first
|
33
|
+
db_statement = [{ params: args&.[](0) }]
|
34
|
+
unless args[1].nil? || args[1].empty?
|
35
|
+
db_statement << { body: args[1] }
|
36
|
+
end
|
37
|
+
|
38
|
+
Tracing::ContextManager.new_exit_span(
|
39
|
+
operation: "Elasticsearch/#{method}/#{path}",
|
40
|
+
peer: "#{peer_info[:protocol]}://#{peer_info[:host]}:#{peer_info[:port]}",
|
41
|
+
component: Tracing::Component::Elasticsearch
|
42
|
+
) do |span|
|
43
|
+
span&.tag(Tracing::TagDbType.new("Elasticsearch"))
|
44
|
+
span&.tag(Tracing::TagDbStatement.new(db_statement))
|
45
|
+
span&.layer = Tracing::Layer::Database
|
46
|
+
|
47
|
+
zuper_perform_request(method, path, *args, &block)
|
48
|
+
rescue
|
49
|
+
span&.error_occurred = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method :zuper_perform_request, :perform_request
|
54
|
+
alias_method :perform_request, :perform_request_with_skywalking
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
register :elasticsearch
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership.
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
6
|
+
# the License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Skywalking
|
17
|
+
module Plugins
|
18
|
+
module MemcachedIntercept
|
19
|
+
def self.included(klass)
|
20
|
+
supported_method =
|
21
|
+
[:add, :append, :delete, :cas, :incr, :increment, :prepend, :replace, :set, :get, :fetch]
|
22
|
+
.select do |method_name|
|
23
|
+
klass.method_defined?(method_name) || klass.private_method_defined?(method_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
supported_method.each do |method_name|
|
27
|
+
zuper_method = :"zuper_#{method_name}"
|
28
|
+
method_with_skywalking = :"#{method_name}_with_skywalking"
|
29
|
+
|
30
|
+
klass.class_eval do
|
31
|
+
define_method(method_with_skywalking) do |*args, &block|
|
32
|
+
cache_key = args[0].to_s if args.length && !args[0].is_a?(Array)
|
33
|
+
Tracing::ContextManager.new_exit_span(
|
34
|
+
operation: "Memcached/#{method_name}",
|
35
|
+
peer: @normalized_servers.join(','),
|
36
|
+
component: Tracing::Component::Memcached
|
37
|
+
) do |span|
|
38
|
+
span&.layer = Tracing::Layer::Cache
|
39
|
+
span&.tag(Tracing::TagCacheType.new("Memcached"))
|
40
|
+
span&.tag(Tracing::TagCacheKey.new(cache_key))
|
41
|
+
|
42
|
+
resp = __send__(zuper_method, *args, &block)
|
43
|
+
if method_name == :get && args.length && args[0].instance_of?(String)
|
44
|
+
span&.tag(Tracing::TagCacheMiss.new(resp.nil?))
|
45
|
+
end
|
46
|
+
|
47
|
+
resp
|
48
|
+
rescue
|
49
|
+
span&.error_occurred = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method zuper_method, method_name
|
54
|
+
alias_method method_name, method_with_skywalking
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Memcached < PluginsManager::SWPlugin
|
61
|
+
def plugin_valid?
|
62
|
+
defined?(::Dalli::Client)
|
63
|
+
end
|
64
|
+
|
65
|
+
def install
|
66
|
+
::Dalli::Client.class_eval do
|
67
|
+
include Skywalking::Plugins::MemcachedIntercept
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
register :memcached
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership.
|
4
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with
|
6
|
+
# the License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Skywalking
|
17
|
+
module Plugins
|
18
|
+
class NetHttp < PluginsManager::SWPlugin
|
19
|
+
module HttpIntercept
|
20
|
+
def request(req, body = nil, &block)
|
21
|
+
method = req.method
|
22
|
+
host = req['host']&.split(':')&.first || address || 'localhost'
|
23
|
+
req_path = URI(req.path)
|
24
|
+
req_info = ""
|
25
|
+
uri = if req_path.host
|
26
|
+
req_path
|
27
|
+
else
|
28
|
+
path, query = req.path.split('?')
|
29
|
+
scheme = use_ssl? ? 'https' : 'http'
|
30
|
+
req_info = "#{path}#{query ? "?#{query}" : ''}"
|
31
|
+
full_url = "#{scheme}://#{host}#{":#{port}" if port}#{req_info}"
|
32
|
+
URI(full_url)
|
33
|
+
end
|
34
|
+
|
35
|
+
Tracing::ContextManager.new_exit_span(
|
36
|
+
operation: "#{method}:#{req_info}",
|
37
|
+
peer: host,
|
38
|
+
component: Tracing::Component::HttpClient
|
39
|
+
) do |span|
|
40
|
+
span&.tag(Tracing::TagHttpMethod.new(method))
|
41
|
+
span&.tag(Tracing::TagHttpURL.new(uri))
|
42
|
+
span&.layer = Tracing::Layer::Http
|
43
|
+
|
44
|
+
carrier = span&.inject
|
45
|
+
headers = req.instance_variable_get(:@header)
|
46
|
+
carrier&.each do |item|
|
47
|
+
headers[item.key] ||= []
|
48
|
+
headers[item.key].concat(Array(item.value))
|
49
|
+
end
|
50
|
+
|
51
|
+
result = super(req, body, &block)
|
52
|
+
span&.tag(Tracing::TagHttpStatusCode.new(result.code))
|
53
|
+
if result.code >= "400"
|
54
|
+
span&.error_occurred = true
|
55
|
+
end
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def plugin_valid?
|
63
|
+
defined?(::Net) && defined?(::Net::HTTP)
|
64
|
+
end
|
65
|
+
|
66
|
+
def install
|
67
|
+
::Net::HTTP.prepend HttpIntercept
|
68
|
+
end
|
69
|
+
|
70
|
+
register :net_http
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -26,10 +26,15 @@ module Skywalking
|
|
26
26
|
peer: _endpoint_info,
|
27
27
|
component: Tracing::Component::Redis
|
28
28
|
) do |span|
|
29
|
-
span&.tag(Tracing::
|
30
|
-
span&.
|
29
|
+
span&.tag(Tracing::TagCacheType.new("Redis"))
|
30
|
+
span&.tag(Tracing::TagCacheOp.new(operation))
|
31
|
+
span&.layer = Tracing::Layer::Cache
|
31
32
|
|
32
|
-
|
33
|
+
begin
|
34
|
+
super(args, &block)
|
35
|
+
rescue
|
36
|
+
span&.error_occurred = true
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -21,21 +21,22 @@ module Skywalking
|
|
21
21
|
req_method = @request.request_method if @request.respond_to?(:request_method)
|
22
22
|
carrier = Tracing::Carrier.new
|
23
23
|
carrier.each do |item|
|
24
|
-
item.
|
24
|
+
item.value = request.env["HTTP_#{item.key.upcase}"]
|
25
25
|
end
|
26
26
|
|
27
27
|
Tracing::ContextManager.new_entry_span(
|
28
|
-
operation: request.env['REQUEST_URI']
|
29
|
-
carrier: carrier
|
30
|
-
inherit: Tracing::Component::General
|
28
|
+
operation: "#{req_method}:#{request.env['REQUEST_URI']}",
|
29
|
+
carrier: carrier
|
31
30
|
) do |span|
|
32
31
|
span&.tag(Tracing::TagHttpMethod.new(req_method))
|
33
32
|
span&.tag(Tracing::TagHttpURL.new(request.env['REQUEST_URI']))
|
34
|
-
span&.layer = Tracing
|
33
|
+
span&.layer = Tracing::Layer::Http
|
35
34
|
span&.peer = "#{request.env['SERVER_NAME']}:#{request.env['SERVER_PORT']}"
|
36
35
|
span&.component = Tracing::Component::Sinatra
|
37
36
|
|
38
37
|
super(*args, &block)
|
38
|
+
rescue
|
39
|
+
span&.error_occurred = true
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|