elastic-apm 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of elastic-apm might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/elastic_apm.rb +2 -6
- data/lib/elastic_apm/agent.rb +23 -12
- data/lib/elastic_apm/config.rb +8 -2
- data/lib/elastic_apm/instrumenter.rb +1 -1
- data/lib/elastic_apm/log.rb +1 -1
- data/lib/elastic_apm/railtie.rb +0 -2
- data/lib/elastic_apm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f733d62bd857f1f2b7e505d7bc2007422b8bd35219eff02c9c3b8c27c5264c
|
4
|
+
data.tar.gz: e5626d4e88f9aef2ca50a285530872f7a1cd6f2935135a196de51a90dd6b7aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc95fa28fe7acb5d81f3bc41c4b424b0732fcb9e8c79bf1b9687ba8a4ea153fdf9eef346f058ed6fa0e40de845a107fb7004c4abbfebaf34ea9f0d182bda4246
|
7
|
+
data.tar.gz: 91f2bc3ab67a4ccbd66c8423c2c65f88701ba99e0048479263555aa63188c2c009744c1393fd54d6230df6e20ecfa8dd7f26e24da2fdbc4bae6fea6b065048c1
|
data/lib/elastic_apm.rb
CHANGED
@@ -62,9 +62,7 @@ module ElasticAPM
|
|
62
62
|
# @yield [Transaction] Optional block encapsulating transaction
|
63
63
|
# @return [Transaction] Unless block given
|
64
64
|
def self.transaction(name, type = nil, context: nil, &block)
|
65
|
-
unless agent
|
66
|
-
return block_given? ? yield : nil
|
67
|
-
end
|
65
|
+
return (block_given? ? yield : nil) unless agent
|
68
66
|
|
69
67
|
agent.transaction(name, type, context: context, &block)
|
70
68
|
end
|
@@ -78,9 +76,7 @@ module ElasticAPM
|
|
78
76
|
# @return [Span] Unless block given
|
79
77
|
def self.span(name, type = nil, context: nil, include_stacktrace: true,
|
80
78
|
&block)
|
81
|
-
unless agent
|
82
|
-
return block_given? ? yield : nil
|
83
|
-
end
|
79
|
+
return (block_given? ? yield : nil) unless agent
|
84
80
|
|
85
81
|
agent.span(
|
86
82
|
name,
|
data/lib/elastic_apm/agent.rb
CHANGED
@@ -23,15 +23,26 @@ module ElasticAPM
|
|
23
23
|
@instance
|
24
24
|
end
|
25
25
|
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
26
27
|
def self.start(config)
|
27
28
|
return @instance if @instance
|
28
29
|
|
30
|
+
config = Config.new(config) if config.is_a?(Hash)
|
31
|
+
|
32
|
+
unless config.enabled_environments.include?(config.environment)
|
33
|
+
config.logger && config.logger.info(
|
34
|
+
format('Not tracking anything in "%s" env', config.environment)
|
35
|
+
)
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
29
39
|
LOCK.synchronize do
|
30
40
|
return @instance if @instance
|
31
41
|
|
32
42
|
@instance = new(config.freeze).start
|
33
43
|
end
|
34
44
|
end
|
45
|
+
# rubocop:enable Metrics/MethodLength
|
35
46
|
|
36
47
|
def self.stop
|
37
48
|
LOCK.synchronize do
|
@@ -46,10 +57,7 @@ module ElasticAPM
|
|
46
57
|
!!@instance
|
47
58
|
end
|
48
59
|
|
49
|
-
# rubocop:disable Metrics/MethodLength
|
50
60
|
def initialize(config)
|
51
|
-
config = Config.new(config) if config.is_a?(Hash)
|
52
|
-
|
53
61
|
@config = config
|
54
62
|
|
55
63
|
@http = Http.new(config)
|
@@ -64,17 +72,14 @@ module ElasticAPM
|
|
64
72
|
Serializers::Errors.new(config)
|
65
73
|
)
|
66
74
|
end
|
67
|
-
# rubocop:enable Metrics/MethodLength
|
68
75
|
|
69
76
|
attr_reader :config, :queue, :instrumenter, :context_builder, :http
|
70
77
|
|
71
78
|
def start
|
72
|
-
debug 'Starting agent reporting to %s', config.server_url
|
79
|
+
debug '[%s] Starting agent, reporting to %s', VERSION, config.server_url
|
73
80
|
|
74
81
|
@instrumenter.start
|
75
82
|
|
76
|
-
boot_worker
|
77
|
-
|
78
83
|
config.enabled_injectors.each do |lib|
|
79
84
|
require "elastic_apm/injectors/#{lib}"
|
80
85
|
end
|
@@ -83,8 +88,6 @@ module ElasticAPM
|
|
83
88
|
end
|
84
89
|
|
85
90
|
def stop
|
86
|
-
debug 'Stopping agent'
|
87
|
-
|
88
91
|
@instrumenter.stop
|
89
92
|
|
90
93
|
kill_worker
|
@@ -97,12 +100,16 @@ module ElasticAPM
|
|
97
100
|
end
|
98
101
|
|
99
102
|
def enqueue_transactions(transactions)
|
103
|
+
boot_worker unless worker_running?
|
104
|
+
|
100
105
|
data = @serializers.transactions.build_all(transactions)
|
101
106
|
@queue << Worker::Request.new('/v1/transactions', data)
|
102
107
|
transactions
|
103
108
|
end
|
104
109
|
|
105
110
|
def enqueue_errors(errors)
|
111
|
+
boot_worker unless worker_running?
|
112
|
+
|
106
113
|
data = @serializers.errors.build_all(errors)
|
107
114
|
@queue << Worker::Request.new('/v1/errors', data)
|
108
115
|
errors
|
@@ -129,6 +136,8 @@ module ElasticAPM
|
|
129
136
|
# errors
|
130
137
|
|
131
138
|
def report(exception, handled: true)
|
139
|
+
return if config.filter_exception_types.include?(exception.class.to_s)
|
140
|
+
|
132
141
|
error = @error_builder.build_exception(
|
133
142
|
exception,
|
134
143
|
handled: handled
|
@@ -170,7 +179,7 @@ module ElasticAPM
|
|
170
179
|
private
|
171
180
|
|
172
181
|
def boot_worker
|
173
|
-
debug 'Booting worker
|
182
|
+
debug 'Booting worker'
|
174
183
|
|
175
184
|
@worker_thread = Thread.new do
|
176
185
|
Worker.new(@config, @queue, @http).run_forever
|
@@ -180,13 +189,15 @@ module ElasticAPM
|
|
180
189
|
def kill_worker
|
181
190
|
@queue << Worker::StopMessage.new
|
182
191
|
|
183
|
-
|
192
|
+
if @worker_thread && !@worker_thread.join(5) # 5 secs
|
184
193
|
raise 'Failed to wait for worker, not all messages sent'
|
185
194
|
end
|
186
195
|
|
187
196
|
@worker_thread = nil
|
197
|
+
end
|
188
198
|
|
189
|
-
|
199
|
+
def worker_running?
|
200
|
+
@worker_thread && @worker_thread.alive?
|
190
201
|
end
|
191
202
|
end
|
192
203
|
# rubocop:enable Metrics/ClassLength
|
data/lib/elastic_apm/config.rb
CHANGED
@@ -13,6 +13,7 @@ module ElasticAPM
|
|
13
13
|
service_name: nil,
|
14
14
|
service_version: nil,
|
15
15
|
environment: ENV['RAILS_ENV'] || ENV['RACK_ENV'],
|
16
|
+
enabled_environments: %w[production],
|
16
17
|
framework_name: nil,
|
17
18
|
framework_version: nil,
|
18
19
|
hostname: nil,
|
@@ -25,6 +26,7 @@ module ElasticAPM
|
|
25
26
|
flush_interval: 10,
|
26
27
|
transaction_sample_rate: 1.0,
|
27
28
|
transaction_max_spans: 500,
|
29
|
+
filter_exception_types: [],
|
28
30
|
|
29
31
|
http_timeout: 10,
|
30
32
|
http_open_timeout: 10,
|
@@ -54,6 +56,7 @@ module ElasticAPM
|
|
54
56
|
'ELASTIC_APM_SERVICE_NAME' => 'service_name',
|
55
57
|
'ELASTIC_APM_SERVICE_VERSION' => 'service_version',
|
56
58
|
'ELASTIC_APM_ENVIRONMENT' => 'environment',
|
59
|
+
'ELASTIC_APM_ENABLED_ENVIRONMENTS' => [:list, 'enabled_environments'],
|
57
60
|
'ELASTIC_APM_FRAMEWORK_NAME' => 'framework_name',
|
58
61
|
'ELASTIC_APM_FRAMEWORK_VERSION' => 'framework_version',
|
59
62
|
'ELASTIC_APM_HOSTNAME' => 'hostname',
|
@@ -94,6 +97,7 @@ module ElasticAPM
|
|
94
97
|
attr_accessor :framework_name
|
95
98
|
attr_accessor :framework_version
|
96
99
|
attr_accessor :hostname
|
100
|
+
attr_accessor :enabled_environments
|
97
101
|
|
98
102
|
attr_accessor :log_path
|
99
103
|
attr_accessor :log_level
|
@@ -103,6 +107,7 @@ module ElasticAPM
|
|
103
107
|
attr_accessor :transaction_sample_rate
|
104
108
|
attr_accessor :transaction_max_spans
|
105
109
|
attr_accessor :verify_server_cert
|
110
|
+
attr_accessor :filter_exception_types
|
106
111
|
|
107
112
|
attr_accessor :http_timeout
|
108
113
|
attr_accessor :http_open_timeout
|
@@ -168,7 +173,7 @@ module ElasticAPM
|
|
168
173
|
end
|
169
174
|
end
|
170
175
|
|
171
|
-
# rubocop:disable Metrics/MethodLength
|
176
|
+
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
172
177
|
def set_from_env
|
173
178
|
ENV_TO_KEY.each do |env_key, key|
|
174
179
|
next unless (value = ENV[env_key])
|
@@ -180,13 +185,14 @@ module ElasticAPM
|
|
180
185
|
when :int then value.to_i
|
181
186
|
when :float then value.to_f
|
182
187
|
when :bool then !%w[0 false].include?(value.strip.downcase)
|
188
|
+
when :list then value.split(/[ ,]/)
|
183
189
|
else value
|
184
190
|
end
|
185
191
|
|
186
192
|
send("#{key}=", value)
|
187
193
|
end
|
188
194
|
end
|
189
|
-
# rubocop:enable Metrics/MethodLength
|
195
|
+
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
190
196
|
|
191
197
|
def set_from_args(options)
|
192
198
|
options.each do |key, value|
|
@@ -127,7 +127,7 @@ module ElasticAPM
|
|
127
127
|
def flush_transactions
|
128
128
|
return if @pending_transactions.empty?
|
129
129
|
|
130
|
-
debug '
|
130
|
+
debug 'Sending %i transactions', @pending_transactions.length
|
131
131
|
|
132
132
|
@agent.enqueue_transactions @pending_transactions
|
133
133
|
|
data/lib/elastic_apm/log.rb
CHANGED
data/lib/elastic_apm/railtie.rb
CHANGED
@@ -4,7 +4,6 @@ module ElasticAPM
|
|
4
4
|
# @api private
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
config.elastic_apm = ActiveSupport::OrderedOptions.new
|
7
|
-
Config::DEFAULTS.each { |option, value| config.elastic_apm[option] = value }
|
8
7
|
|
9
8
|
initializer 'elastic_apm.initialize' do |app|
|
10
9
|
config = Config.new app.config.elastic_apm do |c|
|
@@ -18,7 +17,6 @@ module ElasticAPM
|
|
18
17
|
|
19
18
|
begin
|
20
19
|
ElasticAPM.start config
|
21
|
-
Rails.logger.info "#{Log::PREFIX}Running"
|
22
20
|
|
23
21
|
app.middleware.insert 0, Middleware
|
24
22
|
rescue StandardError => e
|
data/lib/elastic_apm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|