scout_apm 2.1.7 → 2.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f40f5bdf9854daba7e00560485c48995eca9ab99
4
- data.tar.gz: ad7ee5e02e7c3aeeac40eff374c833ad398899f0
3
+ metadata.gz: a8c4c269396ae187fe901317425d0c984e2906bb
4
+ data.tar.gz: 3b2c16163875d6b9dd4fb5b54a3485fa4fc27353
5
5
  SHA512:
6
- metadata.gz: 441475777c789a538940b14e442a49cddd93ff58fd701b3bff2ecc9e80e217a94460e9d782c11cd5475f6913d5dd05bdc43fdacfc5aecb75d3e044e0dcff8229
7
- data.tar.gz: 1b52f6e495117cd132abafef45606f7c7a6e98b6d6a30dc1802a2f51139e8c6638503110c69a25a5b56d0c5a34e1ddebec254cf237254c9fcce7e8e2e14ed5a0
6
+ metadata.gz: e8793cf1a126e0e8c7294c633a06648352d301a7214f31aa7b863b9f1d3862c0148585eb711ce671312d17d697e92f834886c630e1974b62370dea03aaaf7aab
7
+ data.tar.gz: 84db938d6d9972e14901a3c7b13095a70de32ad0b9dc8c2b688a302bf96c04bb176a0086783c01cc99e47b8c12906d2d05d6ea1a84940f3e8b01c177deb9dcb5
data/CHANGELOG.markdown CHANGED
@@ -1,4 +1,6 @@
1
- # master
1
+ # 2.1.8
2
+
3
+ * Adds Git revision detection, which is reported on app load and associated with transaction traces
2
4
 
3
5
  # 2.1.7
4
6
 
data/lib/scout_apm.rb CHANGED
@@ -62,9 +62,6 @@ require 'scout_apm/platform_integrations/server'
62
62
 
63
63
  require 'scout_apm/histogram'
64
64
 
65
- require 'scout_apm/deploy_integrations/capistrano_3'
66
- # require 'scout_apm/deploy_integrations/capistrano_2'
67
-
68
65
  require 'scout_apm/instruments/net_http'
69
66
  require 'scout_apm/instruments/http_client'
70
67
  require 'scout_apm/instruments/moped'
@@ -128,6 +125,7 @@ require 'scout_apm/request_histograms'
128
125
 
129
126
  require 'scout_apm/capacity'
130
127
  require 'scout_apm/attribute_arranger'
128
+ require 'scout_apm/git_revision'
131
129
 
132
130
  require 'scout_apm/serializers/payload_serializer'
133
131
  require 'scout_apm/serializers/payload_serializer_to_json'
@@ -136,7 +134,6 @@ require 'scout_apm/serializers/slow_jobs_serializer_to_json'
136
134
  require 'scout_apm/serializers/metrics_to_json_serializer'
137
135
  require 'scout_apm/serializers/directive_serializer'
138
136
  require 'scout_apm/serializers/app_server_load_serializer'
139
- require 'scout_apm/serializers/deploy_serializer'
140
137
 
141
138
  require 'scout_apm/middleware'
142
139
 
@@ -121,11 +121,6 @@ module ScoutApm
121
121
 
122
122
  @ignored_uris = ScoutApm::IgnoredUris.new(config.value('ignore'))
123
123
 
124
- if environment.deploy_integration
125
- logger.info "Starting monitoring for [#{environment.deploy_integration.name}]]."
126
- return environment.deploy_integration.install
127
- end
128
-
129
124
  load_instruments if should_load_instruments?(options)
130
125
 
131
126
  return false unless preconditions_met?(options)
@@ -324,10 +319,6 @@ module ScoutApm
324
319
  instance.install
325
320
  end
326
321
 
327
- def deploy_integration
328
- environment.deploy_integration
329
- end
330
-
331
322
  def app_server_missing?(options = {})
332
323
  !environment.app_server_integration(true).found? && !options[:skip_app_server_check]
333
324
  end
@@ -38,7 +38,8 @@ module ScoutApm
38
38
  :database_adapter => ScoutApm::Environment.instance.raw_database_adapter, # Raw
39
39
  :application_name => ScoutApm::Environment.instance.application_name,
40
40
  :libraries => ScoutApm::Utils::InstalledGems.new.run,
41
- :paas => ScoutApm::Environment.instance.platform_integration.name
41
+ :paas => ScoutApm::Environment.instance.platform_integration.name,
42
+ :git_sha => ScoutApm::Environment.instance.git_revision.sha
42
43
  }
43
44
  end
44
45
  end
@@ -41,13 +41,8 @@ module ScoutApm
41
41
  ScoutApm::PlatformIntegrations::Server.new,
42
42
  ]
43
43
 
44
- DEPLOY_INTEGRATIONS = [
45
- ScoutApm::DeployIntegrations::Capistrano3.new(STDOUT_LOGGER),
46
- # ScoutApm::DeployIntegrations::Capistrano2.new(STDOUT_LOGGER),
47
- ]
48
-
49
44
  def env
50
- @env ||= deploy_integration? ? deploy_integration.env : framework_integration.env
45
+ @env ||= framework_integration.env
51
46
  end
52
47
 
53
48
  def framework
@@ -88,7 +83,7 @@ module ScoutApm
88
83
  end
89
84
 
90
85
  def root
91
- @root ||= deploy_integration? ? deploy_integration.root : framework_root
86
+ @root ||= framework_root
92
87
  end
93
88
 
94
89
  def framework_root
@@ -110,6 +105,10 @@ module ScoutApm
110
105
  @hostname ||= Agent.instance.config.value("hostname") || platform_integration.hostname
111
106
  end
112
107
 
108
+ def git_revision
109
+ @git_revision ||= ScoutApm::GitRevision.new
110
+ end
111
+
113
112
  # Returns the whole integration object
114
113
  # This needs to be improved. Frequently, multiple app servers gem are present and which
115
114
  # ever is checked first becomes the designated app server.
@@ -143,14 +142,6 @@ module ScoutApm
143
142
  background_job_integration && background_job_integration.name
144
143
  end
145
144
 
146
- def deploy_integration
147
- @deploy_integration ||= DEPLOY_INTEGRATIONS.detect{ |integration| integration.present? }
148
- end
149
-
150
- def deploy_integration?
151
- !@deploy_integration.nil?
152
- end
153
-
154
145
  ### ruby checks
155
146
 
156
147
  def rubinius?
@@ -0,0 +1,51 @@
1
+ module ScoutApm
2
+ class GitRevision
3
+
4
+ attr_accessor :sha
5
+
6
+ def initialize
7
+ @sha = detect
8
+ ScoutApm::Agent.instance.logger.debug "Detected Git Revision [#{@sha}]"
9
+ end
10
+
11
+ private
12
+
13
+ def detect
14
+ detect_from_env_var ||
15
+ detect_from_heroku ||
16
+ detect_from_capistrano ||
17
+ detect_from_git
18
+ end
19
+
20
+ def detect_from_heroku
21
+ ENV['HEROKU_SLUG_COMMIT']
22
+ end
23
+
24
+ def detect_from_env_var
25
+ ENV['SCOUT_REVISION_SHA']
26
+ end
27
+
28
+ def detect_from_capistrano
29
+ version = File.read(File.join(app_root, 'REVISION')).strip
30
+ # Capistrano 3.0 - 3.1.x
31
+ version || File.open(File.join(app_root, '..', 'revisions.log')).to_a.last.strip.sub(/.*as release ([0-9]+).*/, '\1')
32
+ rescue
33
+ ScoutApm::Agent.instance.logger.debug "Unable to detect Git Revision from Capistrano: #{$!.message}"
34
+ nil
35
+ end
36
+
37
+ def detect_from_git
38
+ if File.directory?(".git")
39
+ `git rev-parse --short HEAD`.strip
40
+ end
41
+ rescue
42
+ ScoutApm::Agent.instance.logger.debug "Unable to detect Git Revision from Git: #{$!.message}"
43
+ nil
44
+ end
45
+
46
+ def app_root
47
+ ScoutApm::Environment.instance.root
48
+ end
49
+
50
+ end
51
+ end
@@ -21,6 +21,7 @@ module ScoutApm
21
21
  "allocations" => job.allocations,
22
22
  "seconds_since_startup" => job.seconds_since_startup,
23
23
  "hostname" => job.hostname,
24
+ "git_sha" => job.git_sha,
24
25
  "metrics" => MetricsToJsonSerializer.new(job.metrics).as_json, # New style of metrics
25
26
  "allocation_metrics" => MetricsToJsonSerializer.new(job.allocation_metrics).as_json, # New style of metrics
26
27
  "context" => job.context.to_hash,
@@ -20,6 +20,7 @@ module ScoutApm
20
20
  attr_reader :hostname
21
21
  attr_reader :seconds_since_startup
22
22
  attr_reader :score
23
+ attr_reader :git_sha
23
24
 
24
25
  def initialize(queue_name, job_name, time, total_time, exclusive_time, context, metrics, allocation_metrics, mem_delta, allocations, score)
25
26
  @queue_name = queue_name
@@ -34,6 +35,7 @@ module ScoutApm
34
35
  @allocations = allocations
35
36
  @seconds_since_startup = (Time.now - ScoutApm::Agent.instance.process_start_time)
36
37
  @hostname = ScoutApm::Environment.instance.hostname
38
+ @git_sha = ScoutApm::Environment.instance.git_revision.sha
37
39
  @score = score
38
40
  ScoutApm::Agent.instance.logger.debug { "Slow Job [#{metric_name}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta}"}
39
41
  end
@@ -15,6 +15,7 @@ module ScoutApm
15
15
  attr_reader :allocations
16
16
  attr_accessor :hostname # hack - we need to reset these server side.
17
17
  attr_accessor :seconds_since_startup # hack - we need to reset these server side.
18
+ attr_accessor :git_sha # hack - we need to reset these server side.
18
19
 
19
20
  def initialize(uri, metric_name, total_call_time, metrics, allocation_metrics, context, time, raw_stackprof, mem_delta, allocations, score)
20
21
  @uri = uri
@@ -30,6 +31,7 @@ module ScoutApm
30
31
  @seconds_since_startup = (Time.now - ScoutApm::Agent.instance.process_start_time)
31
32
  @hostname = ScoutApm::Environment.instance.hostname
32
33
  @score = score
34
+ @git_sha = ScoutApm::Environment.instance.git_revision.sha
33
35
  ScoutApm::Agent.instance.logger.debug { "Slow Request [#{uri}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta} Score: #{score}"}
34
36
  end
35
37
 
@@ -44,7 +46,7 @@ module ScoutApm
44
46
  end
45
47
 
46
48
  def as_json
47
- json_attributes = [:key, :time, :total_call_time, :uri, [:context, :context_hash], :score, :prof, :mem_delta, :allocations, :seconds_since_startup, :hostname]
49
+ json_attributes = [:key, :time, :total_call_time, :uri, [:context, :context_hash], :score, :prof, :mem_delta, :allocations, :seconds_since_startup, :hostname, :git_sha]
48
50
  ScoutApm::AttributeArranger.call(self, json_attributes)
49
51
  end
50
52
 
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "2.1.7"
2
+ VERSION = "2.1.8"
3
3
  end
4
4
 
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ require 'scout_apm/git_revision'
4
+
5
+ class GitRevisionTest < Minitest::Test
6
+ # TODO - other tests that would be nice:
7
+ # * ensure we only detect once, on initialize.
8
+ # * tests for reading cap files
9
+
10
+ def test_sha_from_heroku
11
+ ENV['HEROKU_SLUG_COMMIT'] = 'heroku_slug'
12
+ revision = ScoutApm::GitRevision.new
13
+ assert_equal 'heroku_slug', revision.sha
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -131,16 +131,13 @@ files:
131
131
  - lib/scout_apm/capacity.rb
132
132
  - lib/scout_apm/config.rb
133
133
  - lib/scout_apm/context.rb
134
- - lib/scout_apm/deploy_integrations/capistrano_2.cap
135
- - lib/scout_apm/deploy_integrations/capistrano_2.rb
136
- - lib/scout_apm/deploy_integrations/capistrano_3.cap
137
- - lib/scout_apm/deploy_integrations/capistrano_3.rb
138
134
  - lib/scout_apm/environment.rb
139
135
  - lib/scout_apm/fake_store.rb
140
136
  - lib/scout_apm/framework_integrations/rails_2.rb
141
137
  - lib/scout_apm/framework_integrations/rails_3_or_4.rb
142
138
  - lib/scout_apm/framework_integrations/ruby.rb
143
139
  - lib/scout_apm/framework_integrations/sinatra.rb
140
+ - lib/scout_apm/git_revision.rb
144
141
  - lib/scout_apm/histogram.rb
145
142
  - lib/scout_apm/ignored_uris.rb
146
143
  - lib/scout_apm/instant/assets/xmlhttp_instrumentation.html
@@ -191,7 +188,6 @@ files:
191
188
  - lib/scout_apm/request_manager.rb
192
189
  - lib/scout_apm/scored_item_set.rb
193
190
  - lib/scout_apm/serializers/app_server_load_serializer.rb
194
- - lib/scout_apm/serializers/deploy_serializer.rb
195
191
  - lib/scout_apm/serializers/directive_serializer.rb
196
192
  - lib/scout_apm/serializers/jobs_serializer_to_json.rb
197
193
  - lib/scout_apm/serializers/metrics_to_json_serializer.rb
@@ -232,6 +228,7 @@ files:
232
228
  - test/unit/config_test.rb
233
229
  - test/unit/context_test.rb
234
230
  - test/unit/environment_test.rb
231
+ - test/unit/git_revision_test.rb
235
232
  - test/unit/histogram_test.rb
236
233
  - test/unit/ignored_uris_test.rb
237
234
  - test/unit/instruments/active_record_instruments_test.rb
@@ -266,8 +263,30 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
263
  version: '0'
267
264
  requirements: []
268
265
  rubyforge_project: scout_apm
269
- rubygems_version: 2.2.2
266
+ rubygems_version: 2.4.6
270
267
  signing_key:
271
268
  specification_version: 4
272
269
  summary: Ruby application performance monitoring
273
- test_files: []
270
+ test_files:
271
+ - test/data/config_test_1.yml
272
+ - test/test_helper.rb
273
+ - test/unit/agent_test.rb
274
+ - test/unit/background_job_integrations/sidekiq_test.rb
275
+ - test/unit/config_test.rb
276
+ - test/unit/context_test.rb
277
+ - test/unit/environment_test.rb
278
+ - test/unit/git_revision_test.rb
279
+ - test/unit/histogram_test.rb
280
+ - test/unit/ignored_uris_test.rb
281
+ - test/unit/instruments/active_record_instruments_test.rb
282
+ - test/unit/layaway_test.rb
283
+ - test/unit/metric_set_test.rb
284
+ - test/unit/scored_item_set_test.rb
285
+ - test/unit/serializers/payload_serializer_test.rb
286
+ - test/unit/slow_job_policy_test.rb
287
+ - test/unit/slow_request_policy_test.rb
288
+ - test/unit/sql_sanitizer_test.rb
289
+ - test/unit/store_test.rb
290
+ - test/unit/utils/active_record_metric_name_test.rb
291
+ - test/unit/utils/backtrace_parser_test.rb
292
+ has_rdoc:
@@ -1,12 +0,0 @@
1
- namespace :scout_apm do
2
- namespace :deploy do
3
- task :starting do
4
- # Warn if missing scout apm deploy creds?
5
- end
6
- task :finished do
7
- ScoutApm::Agent.instance.deploy_integration.report
8
- end
9
- end
10
- end
11
-
12
- after 'deploy:finished', 'scout_apm:deploy:finished'
@@ -1,83 +0,0 @@
1
- require 'scout_apm'
2
-
3
- module ScoutApm
4
- module DeployIntegrations
5
- class Capistrano2
6
- attr_reader :logger
7
-
8
- def initialize(logger)
9
- @logger = logger
10
- @cap = defined?(Capistrano::Configuration) ? ObjectSpace.each_object(Capistrano::Configuration).map.first : nil rescue nil
11
- end
12
-
13
- def name
14
- :capistrano_2
15
- end
16
-
17
- def version
18
- present? ? Capistrano::VERSION : nil
19
- end
20
-
21
- def present?
22
- if !@cap.nil? && @cap.is_a?(Capistrano::Configuration)
23
- require 'capistrano/version'
24
- defined?(Capistrano::VERSION) && Gem::Dependency.new('', '~> 2.0').match?('', Capistrano::VERSION.to_s)
25
- else
26
- return false
27
- end
28
- return true
29
- rescue
30
- return false
31
- end
32
-
33
- def install
34
- logger.debug "Initializing Capistrano2 Deploy Integration."
35
- @cap.load File.expand_path("../capistrano_2.cap", __FILE__)
36
- end
37
-
38
- def root
39
- '.'
40
- end
41
-
42
- def env
43
- @cap.fetch(:stage)
44
- end
45
-
46
- def found?
47
- true
48
- end
49
-
50
- def report
51
- if reporter.can_report?
52
- data = deploy_data
53
- logger.debug "Sending deploy hook data: #{data}"
54
- payload = ScoutApm::Serializers::DeploySerializer.serialize(data)
55
- reporter.report(payload, ScoutApm::Serializers::DeploySerializer::HTTP_HEADERS)
56
- else
57
- logger.warn "Unable to post deploy hook data"
58
- end
59
- end
60
-
61
- def reporter
62
- @reporter ||= ScoutApm::Reporter.new(:deploy_hook, ScoutApm::Agent.instance.config, @logger)
63
- end
64
-
65
- def deploy_data
66
- {:revision => current_revision, :branch => branch, :deployed_by => deployed_by}
67
- end
68
-
69
- def branch
70
- @cap.fetch(:branch)
71
- end
72
-
73
- def current_revision
74
- @cap.fetch(:current_revision) || `git rev-list --max-count=1 --abbrev-commit --abbrev=12 #{branch}`.chomp
75
- end
76
-
77
- def deployed_by
78
- ScoutApm::Agent.instance.config.value('deployed_by')
79
- end
80
-
81
- end
82
- end
83
- end
@@ -1,12 +0,0 @@
1
- namespace :scout_apm do
2
- namespace :deploy do
3
- task :starting do
4
- # Warn if missing scout apm deploy creds?
5
- end
6
- task :finished do
7
- ScoutApm::Agent.instance.deploy_integration.report
8
- end
9
- end
10
- end
11
-
12
- after 'deploy:finished', 'scout_apm:deploy:finished'
@@ -1,88 +0,0 @@
1
- require 'scout_apm'
2
-
3
- module ScoutApm
4
- module DeployIntegrations
5
- class Capistrano3
6
- attr_reader :logger
7
-
8
- def initialize(logger)
9
- @logger = logger
10
- @cap = Rake.application rescue nil
11
- end
12
-
13
- def name
14
- :capistrano_3
15
- end
16
-
17
- def version
18
- present? ? Capistrano::VERSION : nil
19
- end
20
-
21
- def present?
22
- if !@cap.nil? && @cap.is_a?(Capistrano::Application)
23
- require 'capistrano/version'
24
- defined?(Capistrano::VERSION) && Gem::Dependency.new('', '~> 3.0').match?('', Capistrano::VERSION.to_s)
25
- else
26
- return false
27
- end
28
- rescue
29
- return false
30
- end
31
-
32
- def install
33
- logger.debug "Initializing Capistrano3 Deploy Integration."
34
- load File.expand_path("../capistrano_3.cap", __FILE__)
35
- end
36
-
37
- def root
38
- '.'
39
- end
40
-
41
- def env
42
- @cap.fetch(:stage).to_s
43
- end
44
-
45
- def found?
46
- true
47
- end
48
-
49
- def report
50
- if reporter.can_report?
51
- data = deploy_data
52
- logger.debug "Sending deploy hook data: #{data}"
53
- payload = ScoutApm::Serializers::DeploySerializer.serialize(data)
54
- reporter.report(payload, ScoutApm::Serializers::DeploySerializer::HTTP_HEADERS)
55
- else
56
- logger.warn "Unable to post deploy hook data"
57
- end
58
- end
59
-
60
- def reporter
61
- config = if env == ''
62
- ScoutApm::Agent.instance.config
63
- else
64
- ScoutApm::Config.with_file(nil, {:file => { :environment => env }}) # instantiate our own config, with an overridden environment for the deploy-to app name instead of deploy-from app name)
65
- end
66
-
67
- @reporter ||= ScoutApm::Reporter.new(:deploy_hook, config, @logger)
68
- end
69
-
70
- def deploy_data
71
- {:revision => current_revision, :branch => branch, :deployed_by => deployed_by}
72
- end
73
-
74
- def branch
75
- @cap.fetch(:branch)
76
- end
77
-
78
- def current_revision
79
- @cap.fetch(:current_revision) || `git rev-list --max-count=1 --abbrev-commit --abbrev=12 #{branch}`.chomp
80
- end
81
-
82
- def deployed_by
83
- ScoutApm::Agent.instance.config.value('deployed_by')
84
- end
85
-
86
- end
87
- end
88
- end
@@ -1,16 +0,0 @@
1
- # Serialize & deserialize deploy data up to the APM server
2
- module ScoutApm
3
- module Serializers
4
- class DeploySerializer
5
- HTTP_HEADERS = {'Content-Type' => 'application/x-www-form-urlencoded'}
6
-
7
- def self.serialize(data)
8
- URI.encode_www_form(data)
9
- end
10
-
11
- def self.deserialize(data)
12
- Marshal.load(data)
13
- end
14
- end
15
- end
16
- end