elastic-apm 2.11.0 → 2.12.0
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/CHANGELOG.md +16 -0
- data/docs/api.asciidoc +30 -1
- data/docs/configuration.asciidoc +21 -7
- data/lib/elastic_apm.rb +24 -2
- data/lib/elastic_apm/agent.rb +3 -3
- data/lib/elastic_apm/config.rb +68 -16
- data/lib/elastic_apm/context.rb +4 -4
- data/lib/elastic_apm/error_builder.rb +3 -3
- data/lib/elastic_apm/instrumenter.rb +3 -3
- data/lib/elastic_apm/metrics.rb +4 -4
- data/lib/elastic_apm/metricset.rb +3 -3
- data/lib/elastic_apm/opentracing.rb +8 -8
- data/lib/elastic_apm/rails.rb +3 -1
- data/lib/elastic_apm/span/context.rb +3 -3
- data/lib/elastic_apm/spies/sidekiq.rb +2 -1
- data/lib/elastic_apm/stacktrace_builder.rb +6 -0
- data/lib/elastic_apm/transaction.rb +2 -2
- data/lib/elastic_apm/transport/serializers.rb +10 -0
- data/lib/elastic_apm/transport/serializers/context_serializer.rb +1 -1
- data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +1 -1
- 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: 7d21cbf7caa8a07dc2b34131917e7b635b45c21284fade6a1755235b440bef98
|
4
|
+
data.tar.gz: '0778604992d95bff8e6790cd0e8ce0bc10dd44ea1b07ef0098a87e58efd8eaa4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a2fd0b89e884d3214bef3ab402d311f76ce2a9263a197bb9b90621ddea93acbfce565672d1b91f4eec5db13e0b67e9633b9ae909c4851e581dd180a76b1738
|
7
|
+
data.tar.gz: 8ecf3bce6665417caa94fd2ca3d88c519843cfc62e2649df9e8f5f96b9bff655a0ebdf4b84ceb340cadf4ce792ed12923b86777e66b37761a21ff241456f2a90
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 2.12.0 (2019-10-01)
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- `disabled_spies` renamed to `disabled_instrumentations` with fallback ([#539](https://github.com/elastic/apm-agent-ruby/pull/539))
|
12
|
+
- Rename `set_tag` to `set_label` and deprecate `set_tag` ([#543](https://github.com/elastic/apm-agent-ruby/pull/543))
|
13
|
+
- Allow non-String label values ([#543](https://github.com/elastic/apm-agent-ruby/pull/543))
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Handles a case where stacktrace frames are empty ([#538](https://github.com/elastic/apm-agent-ruby/pull/538))
|
18
|
+
|
19
|
+
### Deprecated
|
20
|
+
|
21
|
+
- Deprecate `set_tag` ([#543](https://github.com/elastic/apm-agent-ruby/pull/543))
|
22
|
+
|
7
23
|
## 2.11.0 (2019-09-23)
|
8
24
|
|
9
25
|
### Added
|
data/docs/api.asciidoc
CHANGED
@@ -260,7 +260,7 @@ Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
|
|
260
260
|
|
261
261
|
Add a tag to the current transaction.
|
262
262
|
Tags are basic key-value pairs that are indexed in your Elasticsearch database
|
263
|
-
and therefore searchable.
|
263
|
+
and therefore searchable. The value will always be converted to a String.
|
264
264
|
|
265
265
|
TIP: Before using custom tags, ensure you understand the different types of
|
266
266
|
{apm-overview-ref-v}/metadata.html[metadata] that are available.
|
@@ -281,6 +281,35 @@ Returns the set `value`.
|
|
281
281
|
|
282
282
|
WARNING: Be aware that tags are indexed in Elasticsearch. Using too many unique keys will result in *https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion[Mapping explosion]*.
|
283
283
|
|
284
|
+
NOTE: This method has been deprecated in favor of `set_label`, which does not convert values to Strings.
|
285
|
+
|
286
|
+
[float]
|
287
|
+
[[api-agent-set-label]]
|
288
|
+
==== `ElasticAPM.set_label`
|
289
|
+
|
290
|
+
Add a label to the current transaction.
|
291
|
+
Labels are basic key-value pairs that are indexed in your Elasticsearch database and therefore searchable.
|
292
|
+
The value can be a string, nil, numeric or boolean.
|
293
|
+
|
294
|
+
TIP: Before using custom labels, ensure you understand the different types of
|
295
|
+
{apm-overview-ref-v}/metadata.html[metadata] that are available.
|
296
|
+
|
297
|
+
[source,ruby]
|
298
|
+
----
|
299
|
+
before_action do
|
300
|
+
ElasticAPM.set_label(:company_id, current_user.company.id)
|
301
|
+
end
|
302
|
+
----
|
303
|
+
|
304
|
+
Arguments:
|
305
|
+
|
306
|
+
* `key`: A string key. Note that `.`, `*` or `"` will be converted to `_`.
|
307
|
+
* `value`: A value.
|
308
|
+
|
309
|
+
Returns the set `value`.
|
310
|
+
|
311
|
+
WARNING: Be aware that labels are indexed in Elasticsearch. Using too many unique keys will result in *https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion[Mapping explosion]*.
|
312
|
+
|
284
313
|
[float]
|
285
314
|
[[api-agent-set-custom-context]]
|
286
315
|
==== `ElasticAPM.set_custom_context`
|
data/docs/configuration.asciidoc
CHANGED
@@ -249,17 +249,31 @@ Eg. `ELASTIC_APM_CUSTOM_KEY_FILTERS="a,b" # => [/a/, /b/]`
|
|
249
249
|
[[config-default-tags]]
|
250
250
|
==== `default_tags`
|
251
251
|
|
252
|
+
[options="header"]
|
253
|
+
|============
|
254
|
+
| Environment | `Config` key | Default | Example
|
255
|
+
| `ELASTIC_APM_DEFAULT_LABELS` | `default_labels` | `{}` | `region=us1`
|
256
|
+
|============
|
257
|
+
|
258
|
+
Add default labels to every transaction. Note that this will eventually be deprecated in favor of `global_labels`.
|
259
|
+
|
260
|
+
WARNING: Be aware that labels are indexed in Elasticsearch. Using too many unique keys will result in *https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion[Mapping explosion]*.
|
261
|
+
|
262
|
+
NOTE: `global_labels` are supported as of APM server version 7.2. `default_tags` and `default_labels` will eventually be
|
263
|
+
deprecated so please transition to using `global_labels` instead. In the meantime, any `default_labels`
|
264
|
+
that are set will override `global_labels`.
|
265
|
+
|
252
266
|
[options="header"]
|
253
267
|
|============
|
254
268
|
| Environment | `Config` key | Default | Example
|
255
269
|
| `ELASTIC_APM_DEFAULT_TAGS` | `default_tags` | `{}` | `region=us1`
|
256
270
|
|============
|
257
271
|
|
258
|
-
Add default tags to add to every transaction.
|
272
|
+
Add default tags to add to every transaction. Note that this option has been deprecated in favor of `default_labels`.
|
259
273
|
|
260
274
|
WARNING: Be aware that tags are indexed in Elasticsearch. Using too many unique keys will result in *https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion[Mapping explosion]*.
|
261
275
|
|
262
|
-
NOTE: `global_labels` are supported as of APM server version 7.2. `default_tags` will eventually be
|
276
|
+
NOTE: `global_labels` are supported as of APM server version 7.2. `default_tags` and `default_labels` will eventually be
|
263
277
|
deprecated so please transition to using `global_labels` instead. In the meantime, any `default_tags`
|
264
278
|
that are set will override `global_labels`.
|
265
279
|
|
@@ -284,19 +298,19 @@ Disables sending payloads to APM Server.
|
|
284
298
|
Disables the agent's startup message announcing itself.
|
285
299
|
|
286
300
|
[float]
|
287
|
-
[[config-disabled-
|
288
|
-
==== `
|
301
|
+
[[config-disabled-instrumentations]]
|
302
|
+
==== `disabled_instrumentations`
|
289
303
|
|
290
304
|
[options="header"]
|
291
305
|
|============
|
292
|
-
| Environment
|
293
|
-
| `
|
306
|
+
| Environment | `Config` key | Default
|
307
|
+
| `ELASTIC_APM_DISABLED_INSTRUMENTATIONS` | `disabled_instrumentations` | `['json']`
|
294
308
|
|============
|
295
309
|
|
296
310
|
Elastic APM automatically instruments select third party libraries.
|
297
311
|
Use this option to disable any of these.
|
298
312
|
|
299
|
-
Get an array of enabled
|
313
|
+
Get an array of enabled instrumentations with `ElasticAPM.agent.config.enabled_instrumentations`.
|
300
314
|
|
301
315
|
[float]
|
302
316
|
[[config-environment]]
|
data/lib/elastic_apm.rb
CHANGED
@@ -66,7 +66,8 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
66
66
|
# Get a formatted string containing transaction, span, and trace ids.
|
67
67
|
# If a block is provided, the ids are yielded.
|
68
68
|
#
|
69
|
-
# @yield [String|nil, String|nil, String|nil] The transaction, span,
|
69
|
+
# @yield [String|nil, String|nil, String|nil] The transaction, span,
|
70
|
+
# and trace ids.
|
70
71
|
# @return [String] Unless block given
|
71
72
|
def log_ids
|
72
73
|
trace_id = (current_transaction || current_span)&.trace_id
|
@@ -363,8 +364,29 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
363
364
|
# @param key [String,Symbol] A key
|
364
365
|
# @param value [Object] A value (will be converted to string)
|
365
366
|
# @return [Object] The given value
|
367
|
+
# @deprecated See `set_label` instead
|
366
368
|
def set_tag(key, value)
|
367
|
-
|
369
|
+
set_label(key, value.to_s)
|
370
|
+
end
|
371
|
+
|
372
|
+
deprecate :set_tag, :set_label
|
373
|
+
|
374
|
+
# Set a _label_ value for the current transaction
|
375
|
+
#
|
376
|
+
# @param key [String,Symbol] A key
|
377
|
+
# @param value [Object] A value
|
378
|
+
# @return [Object] The given value
|
379
|
+
def set_label(key, value)
|
380
|
+
case value
|
381
|
+
when TrueClass,
|
382
|
+
FalseClass,
|
383
|
+
Numeric,
|
384
|
+
NilClass,
|
385
|
+
String
|
386
|
+
agent&.set_label(key, value)
|
387
|
+
else
|
388
|
+
agent&.set_label(key, value.to_s)
|
389
|
+
end
|
368
390
|
end
|
369
391
|
|
370
392
|
# Provide further context for the current transaction
|
data/lib/elastic_apm/agent.rb
CHANGED
@@ -101,7 +101,7 @@ module ElasticAPM
|
|
101
101
|
instrumenter.start
|
102
102
|
metrics.start
|
103
103
|
|
104
|
-
config.
|
104
|
+
config.enabled_instrumentations.each do |lib|
|
105
105
|
debug "Requiring spy: #{lib}"
|
106
106
|
require "elastic_apm/spies/#{lib}"
|
107
107
|
end
|
@@ -185,8 +185,8 @@ module ElasticAPM
|
|
185
185
|
instrumenter.end_span
|
186
186
|
end
|
187
187
|
|
188
|
-
def
|
189
|
-
instrumenter.
|
188
|
+
def set_label(key, value)
|
189
|
+
instrumenter.set_label(key, value)
|
190
190
|
end
|
191
191
|
|
192
192
|
def set_custom_context(context)
|
data/lib/elastic_apm/config.rb
CHANGED
@@ -16,6 +16,7 @@ module ElasticAPM
|
|
16
16
|
# @api private
|
17
17
|
class Config
|
18
18
|
extend Options
|
19
|
+
extend Deprecations
|
19
20
|
|
20
21
|
DEPRECATED_OPTIONS = %i[
|
21
22
|
compression_level=
|
@@ -47,9 +48,11 @@ module ElasticAPM
|
|
47
48
|
option :current_user_username_method, type: :string, default: 'username'
|
48
49
|
option :custom_key_filters, type: :list, default: [], converter: RegexpList.new
|
49
50
|
option :default_tags, type: :dict, default: {}
|
51
|
+
option :default_labels, type: :dict, default: {}
|
50
52
|
option :disable_send, type: :bool, default: false
|
51
53
|
option :disable_start_message, type: :bool, default: false
|
52
|
-
option :
|
54
|
+
option :disabled_instrumentations, type: :list, default: %w[json]
|
55
|
+
option :disabled_spies, type: :list, default: []
|
53
56
|
option :environment, type: :string, default: ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
54
57
|
option :framework_name, type: :string
|
55
58
|
option :framework_version, type: :string
|
@@ -121,7 +124,7 @@ module ElasticAPM
|
|
121
124
|
end
|
122
125
|
|
123
126
|
# rubocop:disable Metrics/MethodLength
|
124
|
-
def
|
127
|
+
def available_instrumentations
|
125
128
|
%w[
|
126
129
|
delayed_job
|
127
130
|
elasticsearch
|
@@ -140,8 +143,8 @@ module ElasticAPM
|
|
140
143
|
end
|
141
144
|
# rubocop:enable Metrics/MethodLength
|
142
145
|
|
143
|
-
def
|
144
|
-
|
146
|
+
def enabled_instrumentations
|
147
|
+
available_instrumentations - disabled_instrumentations
|
145
148
|
end
|
146
149
|
|
147
150
|
def method_missing(name, *args)
|
@@ -160,6 +163,32 @@ module ElasticAPM
|
|
160
163
|
end
|
161
164
|
end
|
162
165
|
|
166
|
+
def use_ssl?
|
167
|
+
server_url.start_with?('https')
|
168
|
+
end
|
169
|
+
|
170
|
+
def collect_metrics?
|
171
|
+
metrics_interval > 0
|
172
|
+
end
|
173
|
+
|
174
|
+
def span_frames_min_duration?
|
175
|
+
span_frames_min_duration != 0
|
176
|
+
end
|
177
|
+
|
178
|
+
def span_frames_min_duration=(value)
|
179
|
+
super
|
180
|
+
@span_frames_min_duration_us = nil
|
181
|
+
end
|
182
|
+
|
183
|
+
def span_frames_min_duration_us
|
184
|
+
@span_frames_min_duration_us ||= span_frames_min_duration * 1_000_000
|
185
|
+
end
|
186
|
+
|
187
|
+
def inspect
|
188
|
+
super.split.first + '>'
|
189
|
+
end
|
190
|
+
|
191
|
+
# DEPRECATED
|
163
192
|
# rubocop:disable Metrics/MethodLength
|
164
193
|
def capture_body=(value)
|
165
194
|
if value =~ /(all|transactions|errors|off)/
|
@@ -185,31 +214,54 @@ module ElasticAPM
|
|
185
214
|
end
|
186
215
|
# rubocop:enable Metrics/MethodLength
|
187
216
|
|
188
|
-
|
189
|
-
|
217
|
+
# DEPRECATED
|
218
|
+
# The spies methods are only somewhat public and only mentioned briefly in
|
219
|
+
# the docs.
|
220
|
+
|
221
|
+
def disabled_spies=(list)
|
222
|
+
self.disabled_instrumentations = list
|
190
223
|
end
|
191
224
|
|
192
|
-
def
|
193
|
-
|
225
|
+
def disabled_spies
|
226
|
+
disabled_instrumentations
|
194
227
|
end
|
195
228
|
|
196
|
-
def
|
197
|
-
|
229
|
+
def enabled_spies
|
230
|
+
enabled_instrumentations
|
198
231
|
end
|
199
232
|
|
200
|
-
def
|
233
|
+
def available_spies
|
234
|
+
available_instrumentations
|
235
|
+
end
|
236
|
+
|
237
|
+
deprecate :disabled_spies=, :disabled_instrumentations=
|
238
|
+
deprecate :disabled_spies, :disabled_instrumentations
|
239
|
+
deprecate :enabled_spies, :enabled_instrumentations
|
240
|
+
deprecate :available_spies, :available_instrumentations
|
241
|
+
|
242
|
+
LABELS_AND_TAGS_CONFLICT = 'You have both \'default_labels\' and ' \
|
243
|
+
'\'default_tags\' set. \'default_tags\' has been deprecated in favor '\
|
244
|
+
'of \'default_labels\'. Please consider upgrading.'.freeze
|
245
|
+
|
246
|
+
def default_labels=(labels)
|
247
|
+
@options[:default_tags].value.empty? || (raise LABELS_AND_TAGS_CONFLICT)
|
201
248
|
super
|
202
|
-
@span_frames_min_duration_us = nil
|
203
249
|
end
|
204
250
|
|
205
|
-
|
206
|
-
|
251
|
+
# DEPRECATED
|
252
|
+
|
253
|
+
def default_tags=(tags)
|
254
|
+
@options[:default_labels].value.empty? || (raise LABELS_AND_TAGS_CONFLICT)
|
255
|
+
super
|
256
|
+
@options[:default_labels].set(tags)
|
207
257
|
end
|
208
258
|
|
209
|
-
def
|
210
|
-
|
259
|
+
def default_tags
|
260
|
+
default_labels
|
211
261
|
end
|
212
262
|
|
263
|
+
deprecate :default_tags=, :default_labels=
|
264
|
+
|
213
265
|
private
|
214
266
|
|
215
267
|
def load_config_file
|
data/lib/elastic_apm/context.rb
CHANGED
@@ -9,9 +9,9 @@ require 'elastic_apm/context/user'
|
|
9
9
|
module ElasticAPM
|
10
10
|
# @api private
|
11
11
|
class Context
|
12
|
-
def initialize(custom: {},
|
12
|
+
def initialize(custom: {}, labels: {}, user: nil)
|
13
13
|
@custom = custom
|
14
|
-
@
|
14
|
+
@labels = labels
|
15
15
|
@user = user || User.new
|
16
16
|
end
|
17
17
|
|
@@ -19,10 +19,10 @@ module ElasticAPM
|
|
19
19
|
attr_accessor :response
|
20
20
|
attr_accessor :user
|
21
21
|
attr_reader :custom
|
22
|
-
attr_reader :
|
22
|
+
attr_reader :labels
|
23
23
|
|
24
24
|
def empty?
|
25
|
-
return false if
|
25
|
+
return false if labels.any?
|
26
26
|
return false if custom.any?
|
27
27
|
return false if user.any?
|
28
28
|
return false if request || response
|
@@ -11,7 +11,7 @@ module ElasticAPM
|
|
11
11
|
error = Error.new context: context || Context.new
|
12
12
|
error.exception = Error::Exception.new(exception, handled: handled)
|
13
13
|
|
14
|
-
Util.reverse_merge!(error.context.
|
14
|
+
Util.reverse_merge!(error.context.labels, @agent.config.default_labels)
|
15
15
|
|
16
16
|
if exception.backtrace
|
17
17
|
add_stacktrace error, :exception, exception.backtrace
|
@@ -49,7 +49,7 @@ module ElasticAPM
|
|
49
49
|
error.log.stacktrace = stacktrace
|
50
50
|
end
|
51
51
|
|
52
|
-
error.culprit = stacktrace.frames.first
|
52
|
+
error.culprit = stacktrace.frames.first&.function
|
53
53
|
end
|
54
54
|
|
55
55
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
@@ -66,7 +66,7 @@ module ElasticAPM
|
|
66
66
|
|
67
67
|
return unless transaction.context
|
68
68
|
|
69
|
-
Util.reverse_merge!(error.context.
|
69
|
+
Util.reverse_merge!(error.context.labels, transaction.context.labels)
|
70
70
|
Util.reverse_merge!(error.context.custom, transaction.context.custom)
|
71
71
|
end
|
72
72
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
@@ -101,7 +101,7 @@ module ElasticAPM
|
|
101
101
|
context: context,
|
102
102
|
trace_context: trace_context,
|
103
103
|
sampled: sampled,
|
104
|
-
|
104
|
+
labels: config.default_labels
|
105
105
|
)
|
106
106
|
|
107
107
|
transaction.start
|
@@ -191,11 +191,11 @@ module ElasticAPM
|
|
191
191
|
|
192
192
|
# metadata
|
193
193
|
|
194
|
-
def
|
194
|
+
def set_label(key, value)
|
195
195
|
return unless current_transaction
|
196
196
|
|
197
197
|
key = key.to_s.gsub(/[\."\*]/, '_').to_sym
|
198
|
-
current_transaction.context.
|
198
|
+
current_transaction.context.labels[key] = value
|
199
199
|
end
|
200
200
|
|
201
201
|
def set_custom_context(context)
|
data/lib/elastic_apm/metrics.rb
CHANGED
@@ -21,9 +21,9 @@ module ElasticAPM
|
|
21
21
|
|
22
22
|
TIMEOUT_INTERVAL = 5 # seconds
|
23
23
|
|
24
|
-
def initialize(config,
|
24
|
+
def initialize(config, labels: nil, &block)
|
25
25
|
@config = config
|
26
|
-
@
|
26
|
+
@labels = labels
|
27
27
|
@samplers = [CpuMem, VM].map do |kls|
|
28
28
|
debug "Adding metrics collector '#{kls}'"
|
29
29
|
kls.new(config)
|
@@ -31,7 +31,7 @@ module ElasticAPM
|
|
31
31
|
@callback = block
|
32
32
|
end
|
33
33
|
|
34
|
-
attr_reader :config, :samplers, :callback, :
|
34
|
+
attr_reader :config, :samplers, :callback, :labels
|
35
35
|
|
36
36
|
# rubocop:disable Metrics/MethodLength
|
37
37
|
def start
|
@@ -76,7 +76,7 @@ module ElasticAPM
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def collect_and_send
|
79
|
-
metricset = Metricset.new(
|
79
|
+
metricset = Metricset.new(labels: labels, **collect)
|
80
80
|
return if metricset.empty?
|
81
81
|
|
82
82
|
callback.call(metricset)
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module ElasticAPM
|
4
4
|
# @api private
|
5
5
|
class Metricset
|
6
|
-
def initialize(timestamp: Util.micros,
|
6
|
+
def initialize(timestamp: Util.micros, labels: nil, **samples)
|
7
7
|
@timestamp = timestamp
|
8
|
-
@
|
8
|
+
@labels = labels
|
9
9
|
@samples = samples
|
10
10
|
end
|
11
11
|
|
12
12
|
attr_accessor :timestamp
|
13
|
-
attr_reader :samples, :
|
13
|
+
attr_reader :samples, :labels
|
14
14
|
|
15
15
|
def empty?
|
16
16
|
samples.empty?
|
@@ -23,7 +23,7 @@ module ElasticAPM
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# rubocop:disable Metrics/MethodLength
|
26
|
-
def
|
26
|
+
def set_label(key, val)
|
27
27
|
if elastic_span.is_a?(Transaction)
|
28
28
|
case key.to_s
|
29
29
|
when 'type'
|
@@ -33,10 +33,10 @@ module ElasticAPM
|
|
33
33
|
when /user\.(\w+)/
|
34
34
|
set_user_value($1, val)
|
35
35
|
else
|
36
|
-
elastic_span.context.
|
36
|
+
elastic_span.context.labels[key] = val
|
37
37
|
end
|
38
38
|
else
|
39
|
-
elastic_span.context.
|
39
|
+
elastic_span.context.labels[key] = val
|
40
40
|
end
|
41
41
|
end
|
42
42
|
# rubocop:enable Metrics/MethodLength
|
@@ -191,7 +191,7 @@ module ElasticAPM
|
|
191
191
|
child_of: nil,
|
192
192
|
references: nil,
|
193
193
|
start_time: Time.now,
|
194
|
-
|
194
|
+
labels: {},
|
195
195
|
ignore_active_scope: false,
|
196
196
|
finish_on_close: true,
|
197
197
|
**
|
@@ -201,7 +201,7 @@ module ElasticAPM
|
|
201
201
|
child_of: child_of,
|
202
202
|
references: references,
|
203
203
|
start_time: start_time,
|
204
|
-
|
204
|
+
labels: labels,
|
205
205
|
ignore_active_scope: ignore_active_scope
|
206
206
|
)
|
207
207
|
scope = scope_manager.activate(span, finish_on_close: finish_on_close)
|
@@ -225,7 +225,7 @@ module ElasticAPM
|
|
225
225
|
child_of: nil,
|
226
226
|
references: nil,
|
227
227
|
start_time: Time.now,
|
228
|
-
|
228
|
+
labels: {},
|
229
229
|
ignore_active_scope: false,
|
230
230
|
**
|
231
231
|
)
|
@@ -263,8 +263,8 @@ module ElasticAPM
|
|
263
263
|
span_context ||=
|
264
264
|
SpanContext.from_trace_context(elastic_span.trace_context)
|
265
265
|
|
266
|
-
|
267
|
-
elastic_span.context.
|
266
|
+
labels.each do |key, value|
|
267
|
+
elastic_span.context.labels[key] = value
|
268
268
|
end
|
269
269
|
|
270
270
|
elastic_span.start Util.micros(start_time)
|
data/lib/elastic_apm/rails.rb
CHANGED
@@ -29,7 +29,9 @@ module ElasticAPM
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if ElasticAPM.running? &&
|
32
|
-
!ElasticAPM.agent.config.
|
32
|
+
!ElasticAPM.agent.config.disabled_instrumentations.include?(
|
33
|
+
'action_dispatch'
|
34
|
+
)
|
33
35
|
require 'elastic_apm/spies/action_dispatch'
|
34
36
|
end
|
35
37
|
ElasticAPM.running?
|
@@ -4,14 +4,14 @@ module ElasticAPM
|
|
4
4
|
class Span
|
5
5
|
# @api private
|
6
6
|
class Context
|
7
|
-
def initialize(db: nil, http: nil,
|
7
|
+
def initialize(db: nil, http: nil, labels: {})
|
8
8
|
@sync = true
|
9
9
|
@db = db && Db.new(db)
|
10
10
|
@http = http && Http.new(http)
|
11
|
-
@
|
11
|
+
@labels = labels
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_accessor :sync, :db, :http, :
|
14
|
+
attr_accessor :sync, :db, :http, :labels
|
15
15
|
|
16
16
|
# @api private
|
17
17
|
class Db
|
@@ -14,7 +14,8 @@ module ElasticAPM
|
|
14
14
|
def call(_worker, job, queue)
|
15
15
|
name = SidekiqSpy.name_for(job)
|
16
16
|
transaction = ElasticAPM.start_transaction(name, 'Sidekiq')
|
17
|
-
|
17
|
+
# TODO: Remove #to_s when #set_tag is removed in v3.0
|
18
|
+
ElasticAPM.set_label(:queue, queue.to_s)
|
18
19
|
|
19
20
|
yield
|
20
21
|
|
@@ -12,6 +12,8 @@ module ElasticAPM
|
|
12
12
|
RUBY_VERS_REGEX = %r{ruby(/gems)?[-/](\d+\.)+\d}.freeze
|
13
13
|
JRUBY_ORG_REGEX = %r{org/jruby}.freeze
|
14
14
|
|
15
|
+
GEMS_PATH = defined?(Bundler) ? Bundler.bundle_path.to_s : Gem.dir
|
16
|
+
|
15
17
|
def initialize(config)
|
16
18
|
@config = config
|
17
19
|
@cache = Util::LruCache.new(2048, &method(:build_frame))
|
@@ -64,9 +66,12 @@ module ElasticAPM
|
|
64
66
|
[file, number, method, module_name]
|
65
67
|
end
|
66
68
|
|
69
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
67
70
|
def library_frame?(config, abs_path)
|
68
71
|
return false unless abs_path
|
69
72
|
|
73
|
+
return true if abs_path.start_with?(GEMS_PATH)
|
74
|
+
|
70
75
|
if abs_path.start_with?(config.__root_path)
|
71
76
|
return true if abs_path.start_with?(config.__root_path + '/vendor')
|
72
77
|
return false
|
@@ -77,6 +82,7 @@ module ElasticAPM
|
|
77
82
|
|
78
83
|
false
|
79
84
|
end
|
85
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
80
86
|
|
81
87
|
def strip_load_path(path)
|
82
88
|
return nil if path.nil?
|
@@ -20,7 +20,7 @@ module ElasticAPM
|
|
20
20
|
type = nil,
|
21
21
|
sampled: true,
|
22
22
|
context: nil,
|
23
|
-
|
23
|
+
labels: nil,
|
24
24
|
trace_context: nil
|
25
25
|
)
|
26
26
|
@name = name
|
@@ -29,7 +29,7 @@ module ElasticAPM
|
|
29
29
|
@sampled = sampled
|
30
30
|
|
31
31
|
@context = context || Context.new # TODO: Lazy generate this?
|
32
|
-
Util.reverse_merge!(@context.
|
32
|
+
Util.reverse_merge!(@context.labels, labels) if labels
|
33
33
|
|
34
34
|
@trace_context = trace_context || TraceContext.new(recorded: sampled)
|
35
35
|
|
@@ -34,6 +34,16 @@ module ElasticAPM
|
|
34
34
|
h.each { |k, v| hash[k] = keyword_field(v) }
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def mixed_object(hash)
|
39
|
+
return unless hash
|
40
|
+
|
41
|
+
hash.tap do |h|
|
42
|
+
h.each do |k, v|
|
43
|
+
hash[k] = v.is_a?(String) ? keyword_field(v) : v
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
49
|
# @api private
|
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: 2.
|
4
|
+
version: 2.12.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: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|