skywalking 0.0.0.alpha → 0.0.0.beta1

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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +19 -0
  3. data/.github/PULL_REQUEST_TEMPLATE +42 -0
  4. data/.github/workflows/ci.yml +70 -0
  5. data/.github/workflows/e2e.yml +73 -0
  6. data/.gitignore +80 -0
  7. data/.gitmodules +18 -0
  8. data/.licenserc.yaml +36 -0
  9. data/.rspec +1 -2
  10. data/.rubocop.yml +6 -0
  11. data/CHANGELOG.md +3 -0
  12. data/Gemfile +20 -0
  13. data/NOTICE +1 -1
  14. data/docs/README.md +7 -0
  15. data/docs/en/agent/plugins.md +10 -0
  16. data/docs/{How-to-release.md → en/development-and-contribution/how-to-release.md} +6 -5
  17. data/docs/en/setup/quick-start.md +106 -0
  18. data/docs/menu.yml +31 -0
  19. data/lib/rails/generators/skywalking/start_generator.rb +47 -0
  20. data/{examples/rails-demo/config/initializers/skywalking_ruby.rb → lib/rails/generators/skywalking/templates/skywalking_initializer.rb} +0 -2
  21. data/lib/skywalking/agent.rb +5 -5
  22. data/lib/skywalking/configuration.rb +54 -33
  23. data/lib/skywalking/environment.rb +103 -11
  24. data/lib/skywalking/log/logger.rb +1 -1
  25. data/lib/skywalking/plugins/net_http.rb +73 -0
  26. data/lib/skywalking/plugins/redis5.rb +3 -2
  27. data/lib/skywalking/plugins/sinatra.rb +2 -2
  28. data/lib/skywalking/reporter/buffer_trigger.rb +1 -1
  29. data/lib/skywalking/reporter/client/grpc_client.rb +2 -2
  30. data/lib/skywalking/reporter/report.rb +1 -1
  31. data/lib/skywalking/tracing/carrier.rb +9 -8
  32. data/lib/skywalking/tracing/constants.rb +11 -18
  33. data/lib/skywalking/tracing/exit_span.rb +1 -1
  34. data/lib/skywalking/tracing/noop_span.rb +1 -1
  35. data/lib/skywalking/tracing/span.rb +1 -1
  36. data/lib/skywalking/tracing/span_context.rb +4 -4
  37. data/lib/skywalking/tracing/tag.rb +36 -1
  38. data/lib/skywalking/version.rb +1 -1
  39. data/skywalking.gemspec +61 -0
  40. data/spec/fixtures/agent.yaml +33 -0
  41. data/spec/scenarios/common/Dockerfile.agent +26 -0
  42. data/spec/scenarios/common/base-compose.yml +46 -0
  43. data/spec/scenarios/common/common_spec_helper.rb +40 -0
  44. data/spec/scenarios/common/compose_context.rb +39 -0
  45. data/spec/scenarios/common/validator.rb +41 -0
  46. data/spec/scenarios/net_http/docker-compose.yml +49 -0
  47. data/spec/scenarios/net_http/expected.yml +39 -0
  48. data/spec/scenarios/net_http/net_http.rb +33 -0
  49. data/spec/scenarios/net_http/net_http_spec.rb +43 -0
  50. data/spec/scenarios/redis/docker-compose.yml +67 -0
  51. data/spec/scenarios/redis/expected.yml +66 -0
  52. data/{examples/sinatra-demo/sinatra-demo.rb → spec/scenarios/redis/redis.rb} +8 -10
  53. data/spec/scenarios/redis/redis_spec.rb +29 -0
  54. data/spec/scenarios/sinatra/docker-compose.yml +54 -0
  55. data/spec/scenarios/sinatra/expected.yml +38 -0
  56. data/spec/scenarios/sinatra/sinatra.rb +26 -0
  57. data/spec/scenarios/sinatra/sinatra_spec.rb +29 -0
  58. data/spec/skywalking/config_spec.rb +41 -0
  59. data/spec/skywalking/utils/id_gen_spec.rb +26 -0
  60. data/spec/spec_helper.rb +115 -0
  61. metadata +134 -143
  62. data/examples/rails-demo/.dockerignore +0 -47
  63. data/examples/rails-demo/.gitattributes +0 -9
  64. data/examples/rails-demo/.gitignore +0 -34
  65. data/examples/rails-demo/.kamal/hooks/docker-setup.sample +0 -3
  66. data/examples/rails-demo/.kamal/hooks/post-deploy.sample +0 -14
  67. data/examples/rails-demo/.kamal/hooks/post-proxy-reboot.sample +0 -3
  68. data/examples/rails-demo/.kamal/hooks/pre-build.sample +0 -51
  69. data/examples/rails-demo/.kamal/hooks/pre-connect.sample +0 -47
  70. data/examples/rails-demo/.kamal/hooks/pre-deploy.sample +0 -109
  71. data/examples/rails-demo/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  72. data/examples/rails-demo/.kamal/secrets +0 -17
  73. data/examples/rails-demo/.rubocop.yml +0 -8
  74. data/examples/rails-demo/.ruby-version +0 -1
  75. data/examples/rails-demo/Dockerfile +0 -72
  76. data/examples/rails-demo/Gemfile +0 -64
  77. data/examples/rails-demo/README.md +0 -24
  78. data/examples/rails-demo/Rakefile +0 -6
  79. data/examples/rails-demo/app/assets/images/.keep +0 -0
  80. data/examples/rails-demo/app/assets/stylesheets/application.css +0 -10
  81. data/examples/rails-demo/app/controllers/application_controller.rb +0 -4
  82. data/examples/rails-demo/app/controllers/concerns/.keep +0 -0
  83. data/examples/rails-demo/app/helpers/application_helper.rb +0 -2
  84. data/examples/rails-demo/app/javascript/application.js +0 -3
  85. data/examples/rails-demo/app/javascript/controllers/application.js +0 -9
  86. data/examples/rails-demo/app/javascript/controllers/hello_controller.js +0 -7
  87. data/examples/rails-demo/app/javascript/controllers/index.js +0 -4
  88. data/examples/rails-demo/app/jobs/application_job.rb +0 -7
  89. data/examples/rails-demo/app/mailers/application_mailer.rb +0 -4
  90. data/examples/rails-demo/app/models/application_record.rb +0 -3
  91. data/examples/rails-demo/app/models/concerns/.keep +0 -0
  92. data/examples/rails-demo/app/views/layouts/application.html.erb +0 -28
  93. data/examples/rails-demo/app/views/layouts/mailer.html.erb +0 -13
  94. data/examples/rails-demo/app/views/layouts/mailer.text.erb +0 -1
  95. data/examples/rails-demo/app/views/pwa/manifest.json.erb +0 -22
  96. data/examples/rails-demo/app/views/pwa/service-worker.js +0 -26
  97. data/examples/rails-demo/bin/brakeman +0 -7
  98. data/examples/rails-demo/bin/bundle +0 -109
  99. data/examples/rails-demo/bin/dev +0 -2
  100. data/examples/rails-demo/bin/docker-entrypoint +0 -14
  101. data/examples/rails-demo/bin/importmap +0 -4
  102. data/examples/rails-demo/bin/jobs +0 -6
  103. data/examples/rails-demo/bin/kamal +0 -27
  104. data/examples/rails-demo/bin/rails +0 -4
  105. data/examples/rails-demo/bin/rake +0 -4
  106. data/examples/rails-demo/bin/rubocop +0 -8
  107. data/examples/rails-demo/bin/setup +0 -34
  108. data/examples/rails-demo/bin/thrust +0 -5
  109. data/examples/rails-demo/config/application.rb +0 -27
  110. data/examples/rails-demo/config/boot.rb +0 -4
  111. data/examples/rails-demo/config/cable.yml +0 -17
  112. data/examples/rails-demo/config/cache.yml +0 -16
  113. data/examples/rails-demo/config/credentials.yml.enc +0 -1
  114. data/examples/rails-demo/config/database.yml +0 -41
  115. data/examples/rails-demo/config/deploy.yml +0 -116
  116. data/examples/rails-demo/config/environment.rb +0 -5
  117. data/examples/rails-demo/config/environments/development.rb +0 -72
  118. data/examples/rails-demo/config/environments/production.rb +0 -90
  119. data/examples/rails-demo/config/environments/test.rb +0 -53
  120. data/examples/rails-demo/config/importmap.rb +0 -7
  121. data/examples/rails-demo/config/initializers/assets.rb +0 -7
  122. data/examples/rails-demo/config/initializers/content_security_policy.rb +0 -25
  123. data/examples/rails-demo/config/initializers/filter_parameter_logging.rb +0 -8
  124. data/examples/rails-demo/config/initializers/inflections.rb +0 -16
  125. data/examples/rails-demo/config/locales/en.yml +0 -31
  126. data/examples/rails-demo/config/puma.rb +0 -41
  127. data/examples/rails-demo/config/queue.yml +0 -18
  128. data/examples/rails-demo/config/recurring.yml +0 -10
  129. data/examples/rails-demo/config/routes.rb +0 -14
  130. data/examples/rails-demo/config/storage.yml +0 -34
  131. data/examples/rails-demo/config.ru +0 -6
  132. data/examples/rails-demo/db/cable_schema.rb +0 -11
  133. data/examples/rails-demo/db/cache_schema.rb +0 -14
  134. data/examples/rails-demo/db/queue_schema.rb +0 -129
  135. data/examples/rails-demo/db/seeds.rb +0 -9
  136. data/examples/rails-demo/lib/tasks/.keep +0 -0
  137. data/examples/rails-demo/log/.keep +0 -0
  138. data/examples/rails-demo/public/400.html +0 -114
  139. data/examples/rails-demo/public/404.html +0 -114
  140. data/examples/rails-demo/public/406-unsupported-browser.html +0 -114
  141. data/examples/rails-demo/public/422.html +0 -114
  142. data/examples/rails-demo/public/500.html +0 -114
  143. data/examples/rails-demo/public/icon.png +0 -0
  144. data/examples/rails-demo/public/icon.svg +0 -3
  145. data/examples/rails-demo/public/robots.txt +0 -1
  146. data/examples/rails-demo/script/.keep +0 -0
  147. data/examples/rails-demo/storage/.keep +0 -0
  148. data/examples/rails-demo/test/application_system_test_case.rb +0 -5
  149. data/examples/rails-demo/test/controllers/.keep +0 -0
  150. data/examples/rails-demo/test/fixtures/files/.keep +0 -0
  151. data/examples/rails-demo/test/helpers/.keep +0 -0
  152. data/examples/rails-demo/test/integration/.keep +0 -0
  153. data/examples/rails-demo/test/mailers/.keep +0 -0
  154. data/examples/rails-demo/test/models/.keep +0 -0
  155. data/examples/rails-demo/test/system/.keep +0 -0
  156. data/examples/rails-demo/test/test_helper.rb +0 -15
  157. data/examples/rails-demo/tmp/.keep +0 -0
  158. data/examples/rails-demo/tmp/pids/.keep +0 -0
  159. data/examples/rails-demo/tmp/storage/.keep +0 -0
  160. data/examples/rails-demo/vendor/.keep +0 -0
  161. data/examples/rails-demo/vendor/javascript/.keep +0 -0
@@ -13,6 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require_relative '../../../../lib/skywalking'
17
-
18
16
  Skywalking.start
@@ -41,7 +41,9 @@ module Skywalking
41
41
  config ||= {}
42
42
  config = Configuration.new(config) unless config.is_a?(Configuration)
43
43
 
44
- @agent = new(config.agent_config).start!
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
- def config
63
- @config ||= Configuration.new.agent_config
64
- end
64
+ attr_reader :logger, :agent_config
65
65
  end
66
66
 
67
- attr_reader :plugins, :logger, :reporter
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
- :collector_backend_service => {
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 config file'
50
+ desc: 'The absolute path to the configuration file'
41
51
  },
42
- :log_file => {
52
+ :log_file_name => {
43
53
  type: :string,
44
- default: 'skywalking.log',
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: 'STDOUT',
59
+ default: '',
50
60
  desc: 'The path to the log file'
51
61
  },
52
62
  :log_level => {
@@ -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
- return if config_yaml.nil? || config_yaml.empty?
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
- logger.warn "No config file found at #{config_yaml}"
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 logger
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(out, Pathname.new(Dir.pwd).realpath)
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-Ruby", level: level)
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-Ruby", level: level)
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
- if stdout?
248
+ candidate = @agent_config[:log_file_path].upcase
249
+
250
+ case candidate
251
+ when "STDOUT"
230
252
  $stdout
231
- elsif !agent_config[:log_file].nil?
232
- agent_config[:log_file]
233
- elsif !agent_config[:log_file_path].nil?
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
- case @agent_config[:log_level]
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
- def framework_info
24
- @framework_info ||= generate_framework_info
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
- def generate_framework_info
28
- if defined?(::Rails::Application)
29
- :rails
30
- elsif defined?(::Sinatra::Base)
46
+ class SinatraFramework
47
+ def name
31
48
  :sinatra
32
- else
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 sinatra?
38
- @framework_info = :sinatra
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
- if sinatra?
43
- info "Shutdown handler not supported for Sinatra"
133
+ case framework_name
134
+ when :sinatra
135
+ warn "Shutdown handler not supported for Sinatra"
44
136
  false
45
137
  else
46
138
  true
@@ -33,7 +33,7 @@ module Skywalking
33
33
  end
34
34
 
35
35
  def log(level, msg, *args)
36
- logger = Configuration.new.logger
36
+ logger = Agent.logger
37
37
  if logger
38
38
  if logger.respond_to?(level)
39
39
  if args.empty?
@@ -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::Http
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,8 +26,9 @@ module Skywalking
26
26
  peer: _endpoint_info,
27
27
  component: Tracing::Component::Redis
28
28
  ) do |span|
29
- span&.tag(Tracing::TagDbType.new("Redis"))
30
- span&.layer = Tracing.find_mapping(Tracing::Layer, Tracing::Layer::Cache)
29
+ span&.tag(Tracing::TagCacheType.new("Redis"))
30
+ span&.tag(Tracing::TagCacheOp.new(operation))
31
+ span&.layer = Tracing::Layer::Cache
31
32
 
32
33
  super(args, &block)
33
34
  end
@@ -25,13 +25,13 @@ module Skywalking
25
25
  end
26
26
 
27
27
  Tracing::ContextManager.new_entry_span(
28
- operation: request.env['REQUEST_URI'].to_s,
28
+ operation: "#{req_method}:#{request.env['REQUEST_URI']}",
29
29
  carrier: carrier,
30
30
  inherit: Tracing::Component::General
31
31
  ) do |span|
32
32
  span&.tag(Tracing::TagHttpMethod.new(req_method))
33
33
  span&.tag(Tracing::TagHttpURL.new(request.env['REQUEST_URI']))
34
- span&.layer = Tracing.find_mapping(Tracing::Layer, Tracing::Layer::Http)
34
+ span&.layer = Tracing::Layer::Http
35
35
  span&.peer = "#{request.env['SERVER_NAME']}:#{request.env['SERVER_PORT']}"
36
36
  span&.component = Tracing::Component::Sinatra
37
37
 
@@ -83,7 +83,7 @@ module Skywalking
83
83
  endTime: span.end_time,
84
84
  operationName: span.operation,
85
85
  peer: span.peer,
86
- spanType: Tracing.find_mapping(Tracing::Kind, span.kind),
86
+ spanType: span.kind,
87
87
  spanLayer: span.layer,
88
88
  componentId: span.component,
89
89
  refs: span.refs.select { |ref| ref.trace_id }.map do |ref|
@@ -26,7 +26,7 @@ module Skywalking
26
26
  def initialize(config)
27
27
  @config = config
28
28
  @management_service ||= ManagementServiceStub.new(
29
- @config[:collector_backend_service],
29
+ @config[:collector_backend_services],
30
30
  :this_channel_is_insecure
31
31
  )
32
32
  end
@@ -97,7 +97,7 @@ module Skywalking
97
97
  def initialize(config)
98
98
  @config = config
99
99
  @trace_service ||= TraceSegmentReportServiceStub.new(
100
- @config[:collector_backend_service],
100
+ @config[:collector_backend_services],
101
101
  :this_channel_is_insecure
102
102
  )
103
103
  end
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
 
16
16
  require_relative 'grpc'
17
- require_relative 'Scheduler'
17
+ require_relative 'scheduler'
18
18
  require_relative 'buffer_trigger'
19
19
 
20
20
  module Skywalking
@@ -20,7 +20,8 @@ module Skywalking
20
20
  module Tracing
21
21
  class Carrier < CarrierItem
22
22
  attr_reader :trace_id, :correlation_carrier, :service_instance,
23
- :endpoint, :segment_id, :span_id, :peer
23
+ :endpoint, :segment_id, :span_id,
24
+ :peer, :items, :iter_index
24
25
 
25
26
  def initialize(
26
27
  trace_id: '',
@@ -47,7 +48,7 @@ module Skywalking
47
48
  @correlation_carrier.correlation = correlation unless correlation.nil?
48
49
  end
49
50
 
50
- def val
51
+ def value
51
52
  [
52
53
  '1',
53
54
  Base64.strict_encode64(@trace_id),
@@ -56,11 +57,11 @@ module Skywalking
56
57
  Base64.strict_encode64(@service),
57
58
  Base64.strict_encode64(@service_instance),
58
59
  Base64.strict_encode64(@endpoint),
59
- Base64.strict_encode64(@client_address)
60
+ Base64.strict_encode64(@peer)
60
61
  ].join('-')
61
62
  end
62
63
 
63
- def val=(val)
64
+ def value=(val)
64
65
  @val = val
65
66
  return if val.nil? || val.empty?
66
67
 
@@ -73,13 +74,13 @@ module Skywalking
73
74
  @service = Base64.strict_decode64(parts[4])
74
75
  @service_instance = Base64.strict_decode64(parts[5])
75
76
  @endpoint = Base64.strict_decode64(parts[6])
76
- @client_address = Base64.strict_decode64(parts[7])
77
+ @peer = Base64.strict_decode64(parts[7])
77
78
  end
78
79
 
79
80
  def valid?
80
81
  !@trace_id.empty? && !@segment_id.empty? && !@service.empty? &&
81
82
  !@service_instance.empty? && !@endpoint.empty? &&
82
- !@client_address.empty? && @span_id.match?(/^\d+$/)
83
+ !@peer.empty? && @span_id.match?(/^\d+$/)
83
84
  end
84
85
 
85
86
  def suppressed?
@@ -99,13 +100,13 @@ module Skywalking
99
100
  @correlation = {}
100
101
  end
101
102
 
102
- def val
103
+ def value
103
104
  return '' if @correlation.nil? || @correlation.empty?
104
105
 
105
106
  @correlation.map { |k, v| "#{Base64.strict_encode64(k)}:#{Base64.strict_encode64(v)}" }.join(',')
106
107
  end
107
108
 
108
- def val=(val)
109
+ def value=(val)
109
110
  @val = val
110
111
  return if val.nil? || val.empty?
111
112
 
@@ -17,33 +17,26 @@ module Skywalking
17
17
  module Tracing
18
18
  module Component
19
19
  Unknown = 0
20
+ Http = 2
20
21
  Redis = 7
21
22
  General = 12000
22
23
  Sinatra = 12001
23
24
  end
24
25
 
25
26
  module Layer
26
- Unknown = 0
27
- Database = 1
28
- RPCFramework = 2
29
- Http = 3
30
- MQ = 4
31
- Cache = 5
32
- FAAS = 6
27
+ Unknown = "Unknown".freeze
28
+ Database = "Database".freeze
29
+ RPCFramework = "RPCFramework".freeze
30
+ Http = "Http".freeze
31
+ MQ = "MQ".freeze
32
+ Cache = "Cache".freeze
33
+ FAAS = "FAAS".freeze
33
34
  end
34
35
 
35
36
  module Kind
36
- Local = 0
37
- Entry = 1
38
- Exit = 2
39
- end
40
-
41
- def self.find_mapping(category, value)
42
- category.constants.each do |const_name|
43
- return const_name if category.const_get(const_name) == value
44
- end
45
-
46
- 'Unknown'
37
+ Local = "Local".freeze
38
+ Entry = "Entry".freeze
39
+ Exit = "Exit".freeze
47
40
  end
48
41
  end
49
42
  end
@@ -33,7 +33,7 @@ module Skywalking
33
33
  end
34
34
 
35
35
  def cfg
36
- @config ||= ::Skywalking::Agent.config
36
+ @config ||= ::Skywalking::Agent.agent_config
37
37
  end
38
38
 
39
39
  def inject
@@ -19,7 +19,7 @@ module Skywalking
19
19
  module Tracing
20
20
  class NoopSpan < Span
21
21
  def initialize(context: nil)
22
- super(context: context, operation: '', kind: Tracing::Kind::EXIT)
22
+ super(context: context, operation: '', kind: Kind::Exit)
23
23
  end
24
24
 
25
25
  def extract(carrier) end
@@ -21,7 +21,7 @@ module Skywalking
21
21
  module Tracing
22
22
  class Span
23
23
  attr_accessor :operation, :inherit, :component,
24
- :context, :tags, :peer, :layer
24
+ :context, :tags, :peer, :layer, :error_occurred
25
25
 
26
26
  attr_reader :stack_depth, :kind, :parent_id,
27
27
  :start_time, :end_time, :span_id, :refs
@@ -36,7 +36,7 @@ module Skywalking
36
36
  end
37
37
 
38
38
  def cfg
39
- @config ||= ::Skywalking::Agent.config
39
+ @config ||= ::Skywalking::Agent.agent_config
40
40
  end
41
41
 
42
42
  def ignore_check(operation, carrier: nil)
@@ -87,7 +87,7 @@ module Skywalking
87
87
  return span if span
88
88
 
89
89
  parent = peek
90
- info 'create new entry span'
90
+ debug 'create new entry span'
91
91
  if parent && parent.kind == Kind::Entry && inherit == parent.component
92
92
  span = parent
93
93
  span.operation = operation
@@ -104,7 +104,7 @@ module Skywalking
104
104
  return span if span
105
105
 
106
106
  parent = peek
107
- info 'create new local span'
107
+ debug 'create new local span'
108
108
  new_span(Span, parent, operation: operation, kind: Kind::Local)
109
109
  end
110
110
 
@@ -113,7 +113,7 @@ module Skywalking
113
113
  return span if span
114
114
 
115
115
  parent = peek
116
- info 'create new exit span'
116
+ debug 'create new exit span'
117
117
 
118
118
  if parent && parent.kind == Kind::Exit && inherit == parent.inherit
119
119
  span = parent