elastic-apm 0.3.0 → 0.4.0
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/.hound.yml +2 -0
- data/docs/index.asciidoc +1 -1
- data/lib/elastic_apm.rb +7 -15
- data/lib/elastic_apm/agent.rb +1 -0
- data/lib/elastic_apm/config.rb +111 -43
- data/lib/elastic_apm/error_builder.rb +1 -1
- data/lib/elastic_apm/http.rb +9 -0
- data/lib/elastic_apm/instrumenter.rb +13 -1
- data/lib/elastic_apm/process_info.rb +3 -1
- data/lib/elastic_apm/serializers/transactions.rb +7 -1
- data/lib/elastic_apm/service_info.rb +2 -9
- data/lib/elastic_apm/stacktrace.rb +17 -8
- data/lib/elastic_apm/stacktrace/frame.rb +9 -6
- data/lib/elastic_apm/system_info.rb +4 -2
- data/lib/elastic_apm/transaction.rb +36 -10
- data/lib/elastic_apm/util.rb +5 -0
- data/lib/elastic_apm/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c00a8dd4ed640c7c98fa3b32f0a252920237e549a10d6592de58d6d4b281ab48
|
4
|
+
data.tar.gz: 3fc4f34aab25ace89c0b689747316245b667bc77b348c4d9d2b08605681179ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6062baf5ed08855d53781d589ff7266b784af1b231511327b527619229743d570868e319be7cb060770bd436a92df24955807e6c8cfcbdb80151d29ac7e7b9fb
|
7
|
+
data.tar.gz: 9516bd876fbfd8c6061b189b603923bb37f740492904d40c10180603f09b0d86a0f97e198962a66570b59851c1fa8e666066f3e4cf51a469ccaa04dfbf5e6955
|
data/.hound.yml
ADDED
data/docs/index.asciidoc
CHANGED
data/lib/elastic_apm.rb
CHANGED
@@ -12,7 +12,6 @@ require 'elastic_apm/instrumenter'
|
|
12
12
|
require 'elastic_apm/internal_error'
|
13
13
|
require 'elastic_apm/util'
|
14
14
|
|
15
|
-
# Metrics
|
16
15
|
require 'elastic_apm/middleware'
|
17
16
|
|
18
17
|
require 'elastic_apm/railtie' if defined?(::Rails::Railtie)
|
@@ -63,7 +62,10 @@ module ElasticAPM
|
|
63
62
|
# @yield [Transaction] Optional block encapsulating transaction
|
64
63
|
# @return [Transaction] Unless block given
|
65
64
|
def self.transaction(name, type = nil, context: nil, &block)
|
66
|
-
|
65
|
+
unless agent
|
66
|
+
return block_given? ? yield : nil
|
67
|
+
end
|
68
|
+
|
67
69
|
agent.transaction(name, type, context: context, &block)
|
68
70
|
end
|
69
71
|
|
@@ -76,7 +78,9 @@ module ElasticAPM
|
|
76
78
|
# @return [Span] Unless block given
|
77
79
|
def self.span(name, type = nil, context: nil, include_stacktrace: true,
|
78
80
|
&block)
|
79
|
-
|
81
|
+
unless agent
|
82
|
+
return block_given? ? yield : nil
|
83
|
+
end
|
80
84
|
|
81
85
|
agent.span(
|
82
86
|
name,
|
@@ -155,16 +159,4 @@ module ElasticAPM
|
|
155
159
|
|
156
160
|
agent && agent.add_filter(key, block || callback)
|
157
161
|
end
|
158
|
-
|
159
|
-
class << self
|
160
|
-
private
|
161
|
-
|
162
|
-
def call_through
|
163
|
-
unless agent
|
164
|
-
return yield if block_given?
|
165
|
-
end
|
166
|
-
|
167
|
-
nil
|
168
|
-
end
|
169
|
-
end
|
170
162
|
end
|
data/lib/elastic_apm/agent.rb
CHANGED
data/lib/elastic_apm/config.rb
CHANGED
@@ -10,20 +10,32 @@ module ElasticAPM
|
|
10
10
|
server_url: 'http://localhost:8200',
|
11
11
|
secret_token: nil,
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
service_name: nil,
|
14
|
+
service_version: nil,
|
15
|
+
environment: ENV['RAILS_ENV'] || ENV['RACK_ENV'],
|
15
16
|
framework_name: nil,
|
16
17
|
framework_version: nil,
|
18
|
+
hostname: nil,
|
17
19
|
|
18
20
|
log_path: '-',
|
19
21
|
log_level: Logger::INFO,
|
20
22
|
logger: nil,
|
21
23
|
|
24
|
+
max_queue_size: 500,
|
25
|
+
flush_interval: 10,
|
26
|
+
transaction_sample_rate: 1.0,
|
27
|
+
transaction_max_spans: 500,
|
28
|
+
|
22
29
|
http_timeout: 10,
|
23
30
|
http_open_timeout: 10,
|
24
|
-
transaction_send_interval: 10,
|
25
31
|
debug_transactions: false,
|
26
32
|
debug_http: false,
|
33
|
+
verify_server_cert: true,
|
34
|
+
|
35
|
+
source_lines_error_app_frames: 5,
|
36
|
+
source_lines_span_app_frames: 5,
|
37
|
+
source_lines_error_library_frames: 0,
|
38
|
+
source_lines_span_library_frames: 0,
|
27
39
|
|
28
40
|
enabled_injectors: %w[net_http json],
|
29
41
|
|
@@ -36,52 +48,72 @@ module ElasticAPM
|
|
36
48
|
}.freeze
|
37
49
|
|
38
50
|
ENV_TO_KEY = {
|
39
|
-
'ELASTIC_APM_APP_NAME' => 'app_name',
|
40
51
|
'ELASTIC_APM_SERVER_URL' => 'server_url',
|
41
|
-
'ELASTIC_APM_SECRET_TOKEN' => 'secret_token'
|
52
|
+
'ELASTIC_APM_SECRET_TOKEN' => 'secret_token',
|
53
|
+
|
54
|
+
'ELASTIC_APM_SERVICE_NAME' => 'service_name',
|
55
|
+
'ELASTIC_APM_SERVICE_VERSION' => 'service_version',
|
56
|
+
'ELASTIC_APM_ENVIRONMENT' => 'environment',
|
57
|
+
'ELASTIC_APM_FRAMEWORK_NAME' => 'framework_name',
|
58
|
+
'ELASTIC_APM_FRAMEWORK_VERSION' => 'framework_version',
|
59
|
+
'ELASTIC_APM_HOSTNAME' => 'hostname',
|
60
|
+
|
61
|
+
'ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES' =>
|
62
|
+
[:int, 'source_lines_error_app_frames'],
|
63
|
+
'ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES' =>
|
64
|
+
[:int, 'source_lines_span_app_frames'],
|
65
|
+
'ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES' =>
|
66
|
+
[:int, 'source_lines_error_library_frames'],
|
67
|
+
'ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES' =>
|
68
|
+
[:int, 'source_lines_span_library_frames'],
|
69
|
+
|
70
|
+
'ELASTIC_APM_MAX_QUEUE_SIZE' => [:int, 'max_queue_size'],
|
71
|
+
'ELASTIC_APM_FLUSH_INTERVAL' => 'flush_interval',
|
72
|
+
'ELASTIC_APM_TRANSACTION_SAMPLE_RATE' =>
|
73
|
+
[:float, 'transaction_sample_rate'],
|
74
|
+
'ELASTIC_APM_VERIFY_SERVER_CERT' => [:bool, 'verify_server_cert'],
|
75
|
+
'ELASTIC_APM_TRANSACTION_MAX_SPANS' => [:int, 'transaction_max_spans']
|
42
76
|
}.freeze
|
43
77
|
|
44
|
-
# rubocop:disable Metrics/MethodLength
|
45
78
|
def initialize(options = nil)
|
46
79
|
options = {} if options.nil?
|
47
80
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
# Set options from ENV
|
54
|
-
ENV_TO_KEY.each do |env_key, key|
|
55
|
-
next unless (value = ENV[env_key])
|
56
|
-
send("#{key}=", value)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Set options from arguments
|
60
|
-
options.each do |key, value|
|
61
|
-
send("#{key}=", value)
|
62
|
-
end
|
81
|
+
set_defaults
|
82
|
+
set_from_env
|
83
|
+
set_from_args(options)
|
63
84
|
|
64
85
|
yield self if block_given?
|
65
86
|
end
|
66
|
-
# rubocop:enable Metrics/MethodLength
|
67
87
|
|
68
88
|
attr_accessor :server_url
|
69
89
|
attr_accessor :secret_token
|
70
90
|
|
71
|
-
attr_accessor :
|
72
|
-
|
91
|
+
attr_accessor :service_name
|
92
|
+
attr_accessor :service_version
|
93
|
+
attr_accessor :environment
|
73
94
|
attr_accessor :framework_name
|
74
95
|
attr_accessor :framework_version
|
96
|
+
attr_accessor :hostname
|
75
97
|
|
76
98
|
attr_accessor :log_path
|
77
99
|
attr_accessor :log_level
|
78
100
|
|
101
|
+
attr_accessor :max_queue_size
|
102
|
+
attr_accessor :flush_interval
|
103
|
+
attr_accessor :transaction_sample_rate
|
104
|
+
attr_accessor :transaction_max_spans
|
105
|
+
attr_accessor :verify_server_cert
|
106
|
+
|
79
107
|
attr_accessor :http_timeout
|
80
108
|
attr_accessor :http_open_timeout
|
81
|
-
attr_accessor :transaction_send_interval
|
82
109
|
attr_accessor :debug_transactions
|
83
110
|
attr_accessor :debug_http
|
84
111
|
|
112
|
+
attr_accessor :source_lines_error_app_frames
|
113
|
+
attr_accessor :source_lines_span_app_frames
|
114
|
+
attr_accessor :source_lines_error_library_frames
|
115
|
+
attr_accessor :source_lines_span_library_frames
|
116
|
+
|
85
117
|
attr_accessor :enabled_injectors
|
86
118
|
|
87
119
|
attr_accessor :view_paths
|
@@ -94,28 +126,19 @@ module ElasticAPM
|
|
94
126
|
|
95
127
|
attr_reader :logger
|
96
128
|
|
97
|
-
|
129
|
+
alias :verify_server_cert? :verify_server_cert
|
130
|
+
|
98
131
|
def app=(app)
|
99
132
|
case app_type?(app)
|
100
133
|
when :sinatra
|
101
|
-
|
102
|
-
self.framework_name = 'Sinatra'
|
103
|
-
self.framework_version = Sinatra::VERSION
|
104
|
-
self.enabled_injectors += %w[sinatra]
|
105
|
-
self.root_path = Dir.pwd
|
134
|
+
set_sinatra(app)
|
106
135
|
when :rails
|
107
|
-
|
108
|
-
self.framework_name = 'Ruby on Rails'
|
109
|
-
self.framework_version = Rails::VERSION::STRING
|
110
|
-
self.logger = Rails.logger
|
111
|
-
self.root_path = Rails.root.to_s
|
112
|
-
self.view_paths = app.config.paths['app/views'].existent
|
136
|
+
set_rails(app)
|
113
137
|
else
|
114
138
|
# TODO: define custom?
|
115
|
-
self.
|
139
|
+
self.service_name = 'ruby'
|
116
140
|
end
|
117
141
|
end
|
118
|
-
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
119
142
|
|
120
143
|
def app_type?(app)
|
121
144
|
if defined?(::Rails) && app.is_a?(Rails::Application)
|
@@ -133,16 +156,61 @@ module ElasticAPM
|
|
133
156
|
server_url.start_with?('https')
|
134
157
|
end
|
135
158
|
|
136
|
-
def environment=(env)
|
137
|
-
@environment = env || ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
138
|
-
end
|
139
|
-
|
140
159
|
def logger=(logger)
|
141
160
|
@logger = logger || build_logger(log_path, log_level)
|
142
161
|
end
|
143
162
|
|
144
163
|
private
|
145
164
|
|
165
|
+
def set_defaults
|
166
|
+
DEFAULTS.each do |key, value|
|
167
|
+
send("#{key}=", value)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# rubocop:disable Metrics/MethodLength
|
172
|
+
def set_from_env
|
173
|
+
ENV_TO_KEY.each do |env_key, key|
|
174
|
+
next unless (value = ENV[env_key])
|
175
|
+
|
176
|
+
type, key = key if key.is_a? Array
|
177
|
+
|
178
|
+
value =
|
179
|
+
case type
|
180
|
+
when :int then value.to_i
|
181
|
+
when :float then value.to_f
|
182
|
+
when :bool then !%w[0 false].include?(value.strip.downcase)
|
183
|
+
else value
|
184
|
+
end
|
185
|
+
|
186
|
+
send("#{key}=", value)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
# rubocop:enable Metrics/MethodLength
|
190
|
+
|
191
|
+
def set_from_args(options)
|
192
|
+
options.each do |key, value|
|
193
|
+
send("#{key}=", value)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def set_sinatra(app)
|
198
|
+
self.service_name = format_name(service_name || app.to_s)
|
199
|
+
self.framework_name = framework_name || 'Sinatra'
|
200
|
+
self.framework_version = framework_version || Sinatra::VERSION
|
201
|
+
self.enabled_injectors += %w[sinatra]
|
202
|
+
self.root_path = Dir.pwd
|
203
|
+
end
|
204
|
+
|
205
|
+
def set_rails(app)
|
206
|
+
self.service_name = format_name(service_name || app.class.parent_name)
|
207
|
+
self.framework_name = 'Ruby on Rails'
|
208
|
+
self.framework_version = Rails::VERSION::STRING
|
209
|
+
self.logger = Rails.logger
|
210
|
+
self.root_path = Rails.root.to_s
|
211
|
+
self.view_paths = app.config.paths['app/views'].existent
|
212
|
+
end
|
213
|
+
|
146
214
|
def build_logger(path, level)
|
147
215
|
logger = Logger.new(path == '-' ? STDOUT : path)
|
148
216
|
logger.level = level
|
data/lib/elastic_apm/http.rb
CHANGED
@@ -91,6 +91,7 @@ module ElasticAPM
|
|
91
91
|
|
92
92
|
http = Net::HTTP.new server_uri.host, server_uri.port
|
93
93
|
http.use_ssl = @config.use_ssl?
|
94
|
+
http.verify_mode = verify_mode
|
94
95
|
http.read_timeout = @config.http_timeout
|
95
96
|
http.open_timeout = @config.http_open_timeout
|
96
97
|
|
@@ -104,5 +105,13 @@ module ElasticAPM
|
|
104
105
|
def server_uri
|
105
106
|
@uri ||= URI(@config.server_url)
|
106
107
|
end
|
108
|
+
|
109
|
+
def verify_mode
|
110
|
+
if @config.use_ssl? && @config.verify_server_cert?
|
111
|
+
OpenSSL::SSL::VERIFY_PEER
|
112
|
+
else
|
113
|
+
OpenSSL::SSL::VERIFY_NONE
|
114
|
+
end
|
115
|
+
end
|
107
116
|
end
|
108
117
|
end
|
@@ -64,6 +64,14 @@ module ElasticAPM
|
|
64
64
|
return transaction
|
65
65
|
end
|
66
66
|
|
67
|
+
sample = rand <= config.transaction_sample_rate
|
68
|
+
|
69
|
+
if args.last.is_a? Hash
|
70
|
+
args.last[:sampled] = sample
|
71
|
+
else
|
72
|
+
args.push(sampled: sample)
|
73
|
+
end
|
74
|
+
|
67
75
|
transaction = Transaction.new self, *args
|
68
76
|
|
69
77
|
self.current_transaction = transaction
|
@@ -108,7 +116,11 @@ module ElasticAPM
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def should_flush_transactions?
|
111
|
-
|
119
|
+
interval = config.flush_interval
|
120
|
+
|
121
|
+
return true if interval.nil?
|
122
|
+
return true if @pending_transactions.length >= config.max_queue_size
|
123
|
+
|
112
124
|
Time.now.utc - @last_sent_transactions >= interval
|
113
125
|
end
|
114
126
|
|
@@ -6,7 +6,7 @@ module ElasticAPM
|
|
6
6
|
class Transactions < Serializer
|
7
7
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
8
8
|
def build(transaction)
|
9
|
-
{
|
9
|
+
base = {
|
10
10
|
id: transaction.id,
|
11
11
|
name: transaction.name,
|
12
12
|
type: transaction.type,
|
@@ -17,6 +17,12 @@ module ElasticAPM
|
|
17
17
|
sampled: transaction.sampled,
|
18
18
|
context: transaction.context.to_h
|
19
19
|
}
|
20
|
+
|
21
|
+
if transaction.dropped_spans > 0
|
22
|
+
base[:span_count] = { dropped: { total: transaction.dropped_spans } }
|
23
|
+
end
|
24
|
+
|
25
|
+
base
|
20
26
|
end
|
21
27
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
22
28
|
|
@@ -10,7 +10,7 @@ module ElasticAPM
|
|
10
10
|
# rubocop:disable Metrics/MethodLength
|
11
11
|
def build
|
12
12
|
base = {
|
13
|
-
name: @config.
|
13
|
+
name: @config.service_name,
|
14
14
|
environment: @config.environment,
|
15
15
|
agent: {
|
16
16
|
name: 'ruby',
|
@@ -22,7 +22,7 @@ module ElasticAPM
|
|
22
22
|
version: RUBY_VERSION
|
23
23
|
},
|
24
24
|
runtime: runtime,
|
25
|
-
version: git_sha
|
25
|
+
version: @config.service_version || Util.git_sha
|
26
26
|
}
|
27
27
|
|
28
28
|
if @config.framework_name
|
@@ -42,13 +42,6 @@ module ElasticAPM
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
def git_sha
|
46
|
-
sha = `git rev-parse --verify HEAD 2>&1`.chomp
|
47
|
-
return sha if $?.success? # rubocop:disable Style/SpecialGlobalVars
|
48
|
-
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
|
52
45
|
def runtime
|
53
46
|
case RUBY_ENGINE
|
54
47
|
when 'ruby'
|
@@ -14,17 +14,17 @@ module ElasticAPM
|
|
14
14
|
|
15
15
|
attr_reader :frames
|
16
16
|
|
17
|
-
def self.build(config, backtrace)
|
17
|
+
def self.build(config, backtrace, type)
|
18
18
|
return nil unless backtrace
|
19
19
|
|
20
20
|
stack = new(backtrace)
|
21
|
-
stack.build_frames(config)
|
21
|
+
stack.build_frames(config, type)
|
22
22
|
stack
|
23
23
|
end
|
24
24
|
|
25
|
-
def build_frames(config)
|
25
|
+
def build_frames(config, type)
|
26
26
|
@frames = @backtrace.map do |line|
|
27
|
-
build_frame(config, line)
|
27
|
+
build_frame(config, line, type)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -56,20 +56,24 @@ module ElasticAPM
|
|
56
56
|
[file, number, method, module_name]
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
60
|
+
def build_frame(config, line, type)
|
60
61
|
abs_path, lineno, function, _module_name = parse_line(line)
|
62
|
+
library_frame = !(abs_path && abs_path.start_with?(config.root_path))
|
61
63
|
|
62
64
|
frame = Frame.new
|
63
65
|
frame.abs_path = abs_path
|
64
66
|
frame.filename = strip_load_path(abs_path)
|
65
67
|
frame.function = function
|
66
68
|
frame.lineno = lineno.to_i
|
67
|
-
frame.
|
68
|
-
|
69
|
-
|
69
|
+
frame.library_frame = library_frame
|
70
|
+
|
71
|
+
line_count = context_lines_for(config, type, library_frame: library_frame)
|
72
|
+
frame.build_context line_count
|
70
73
|
|
71
74
|
frame
|
72
75
|
end
|
76
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
73
77
|
|
74
78
|
def strip_load_path(path)
|
75
79
|
return nil unless path
|
@@ -85,5 +89,10 @@ module ElasticAPM
|
|
85
89
|
|
86
90
|
path[prefix.chomp(File::SEPARATOR).length + 1..-1]
|
87
91
|
end
|
92
|
+
|
93
|
+
def context_lines_for(config, type, library_frame:)
|
94
|
+
key = "source_lines_#{type}_#{library_frame ? 'library' : 'app'}_frames"
|
95
|
+
config.send(key.to_sym)
|
96
|
+
end
|
88
97
|
end
|
89
98
|
end
|
@@ -20,17 +20,20 @@ module ElasticAPM
|
|
20
20
|
:colno
|
21
21
|
)
|
22
22
|
|
23
|
+
# rubocop:disable Metrics/AbcSize
|
23
24
|
def build_context(context_line_count)
|
24
|
-
return unless abs_path
|
25
|
+
return unless abs_path && context_line_count > 0
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
padding = (context_line_count - 1) / 2
|
28
|
+
from = lineno - padding - 1
|
29
|
+
to = lineno + padding - 1
|
28
30
|
file_lines = read_lines(abs_path, from..to)
|
29
31
|
|
30
|
-
self.context_line = file_lines[
|
31
|
-
self.pre_context = file_lines.first(
|
32
|
-
self.post_context = file_lines.last(
|
32
|
+
self.context_line = file_lines[padding]
|
33
|
+
self.pre_context = file_lines.first(padding)
|
34
|
+
self.post_context = file_lines.last(padding)
|
33
35
|
end
|
36
|
+
# rubocop:enable Metrics/AbcSize
|
34
37
|
|
35
38
|
private
|
36
39
|
|
@@ -3,11 +3,13 @@
|
|
3
3
|
module ElasticAPM
|
4
4
|
# @api private
|
5
5
|
class SystemInfo
|
6
|
-
def initialize(
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
7
9
|
|
8
10
|
def build
|
9
11
|
{
|
10
|
-
hostname: `hostname`,
|
12
|
+
hostname: @config.hostname || `hostname`,
|
11
13
|
architecture: platform.cpu,
|
12
14
|
platform: platform.os
|
13
15
|
}
|
@@ -4,7 +4,13 @@ module ElasticAPM
|
|
4
4
|
# @api private
|
5
5
|
class Transaction
|
6
6
|
# rubocop:disable Metrics/MethodLength
|
7
|
-
def initialize(
|
7
|
+
def initialize(
|
8
|
+
instrumenter,
|
9
|
+
name,
|
10
|
+
type = 'custom',
|
11
|
+
context: nil,
|
12
|
+
sampled: true
|
13
|
+
)
|
8
14
|
@id = SecureRandom.uuid
|
9
15
|
@instrumenter = instrumenter
|
10
16
|
@name = name
|
@@ -13,22 +19,22 @@ module ElasticAPM
|
|
13
19
|
@timestamp = Util.micros
|
14
20
|
|
15
21
|
@spans = []
|
16
|
-
@notifications = []
|
17
22
|
@span_id_ticker = -1
|
23
|
+
@dropped_spans = 0
|
18
24
|
|
19
25
|
@notifications = [] # for AS::Notifications
|
20
26
|
|
21
27
|
@context = context || Context.new
|
22
28
|
|
23
|
-
@sampled =
|
29
|
+
@sampled = sampled
|
24
30
|
|
25
31
|
yield self if block_given?
|
26
32
|
end
|
27
33
|
# rubocop:enable Metrics/MethodLength
|
28
34
|
|
29
35
|
attr_accessor :id, :name, :result, :type
|
30
|
-
attr_reader :context, :duration, :
|
31
|
-
:notifications, :sampled, :instrumenter
|
36
|
+
attr_reader :context, :duration, :dropped_spans, :root_span, :timestamp,
|
37
|
+
:spans, :notifications, :sampled, :instrumenter
|
32
38
|
|
33
39
|
def release
|
34
40
|
@instrumenter.current_transaction = nil
|
@@ -63,13 +69,19 @@ module ElasticAPM
|
|
63
69
|
|
64
70
|
# rubocop:disable Metrics/MethodLength
|
65
71
|
def span(name, type = nil, backtrace: nil, context: nil)
|
66
|
-
|
67
|
-
|
72
|
+
unless sampled?
|
73
|
+
return yield if block_given?
|
74
|
+
return
|
75
|
+
end
|
68
76
|
|
69
|
-
|
70
|
-
|
77
|
+
if spans.length >= instrumenter.config.transaction_max_spans
|
78
|
+
@dropped_spans += 1
|
71
79
|
|
72
|
-
|
80
|
+
return yield if block_given?
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
span = build_and_start_span(name, type, context, backtrace)
|
73
85
|
|
74
86
|
return span unless block_given?
|
75
87
|
|
@@ -83,10 +95,24 @@ module ElasticAPM
|
|
83
95
|
end
|
84
96
|
# rubocop:enable Metrics/MethodLength
|
85
97
|
|
98
|
+
def build_and_start_span(name, type, context, backtrace)
|
99
|
+
span = next_span(name, type, context)
|
100
|
+
spans << span
|
101
|
+
|
102
|
+
span.stacktrace =
|
103
|
+
backtrace && Stacktrace.build(@instrumenter.config, backtrace, :span)
|
104
|
+
|
105
|
+
span.start
|
106
|
+
end
|
107
|
+
|
86
108
|
def current_span
|
87
109
|
spans.reverse.lazy.find(&:running?)
|
88
110
|
end
|
89
111
|
|
112
|
+
def sampled?
|
113
|
+
!!sampled
|
114
|
+
end
|
115
|
+
|
90
116
|
def inspect
|
91
117
|
"<ElasticAPM::Transaction id:#{id}>"
|
92
118
|
end
|
data/lib/elastic_apm/util.rb
CHANGED
@@ -14,6 +14,11 @@ module ElasticAPM
|
|
14
14
|
def self.inspect_transaction(transaction)
|
15
15
|
Inspector.new.transaction transaction
|
16
16
|
end
|
17
|
+
|
18
|
+
def self.git_sha
|
19
|
+
sha = `git rev-parse --verify HEAD 2>&1`.chomp
|
20
|
+
$? && $?.success? ? sha : nil # rubocop:disable Style/SpecialGlobalVars
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
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
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
|
+
- ".hound.yml"
|
35
36
|
- ".rspec"
|
36
37
|
- ".rubocop.yml"
|
37
38
|
- ".travis.yml"
|