elastic-apm 2.8.1 → 2.11.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/.ci/.jenkins_codecov.yml +5 -0
- data/.ci/.jenkins_exclude.yml +63 -0
- data/.ci/.jenkins_framework.yml +9 -0
- data/.ci/.jenkins_master_framework.yml +3 -0
- data/.ci/.jenkins_ruby.yml +11 -0
- data/.ci/Jenkinsfile +268 -0
- data/.ci/bin/check_paths_for_matches.py +80 -0
- data/.ci/downstreamTests.groovy +188 -0
- data/.ci/jobs/apm-agent-ruby-downstream.yml +37 -0
- data/.ci/jobs/apm-agent-ruby-linting-mbp.yml +38 -0
- data/.ci/jobs/apm-agent-ruby-mbp.yml +41 -0
- data/.ci/jobs/apm-agent-ruby.yml +4 -0
- data/.ci/jobs/defaults.yml +24 -0
- data/.ci/linting.groovy +32 -0
- data/.ci/prepare-git-context.sh +23 -0
- data/.pre-commit-config.yaml +22 -0
- data/.rspec +0 -1
- data/.rubocop.yml +3 -3
- data/CHANGELOG.md +59 -2
- data/docs/api.asciidoc +24 -7
- data/docs/configuration.asciidoc +43 -4
- data/docs/index.asciidoc +2 -0
- data/docs/log-correlation.asciidoc +96 -0
- data/docs/metrics.asciidoc +77 -6
- data/lib/elastic_apm.rb +37 -5
- data/lib/elastic_apm/agent.rb +29 -4
- data/lib/elastic_apm/central_config.rb +141 -0
- data/lib/elastic_apm/central_config/cache_control.rb +34 -0
- data/lib/elastic_apm/config.rb +165 -340
- data/lib/elastic_apm/config/bytes.rb +25 -0
- data/lib/elastic_apm/config/duration.rb +6 -8
- data/lib/elastic_apm/config/options.rb +134 -0
- data/lib/elastic_apm/config/regexp_list.rb +13 -0
- data/lib/elastic_apm/context_builder.rb +2 -0
- data/lib/elastic_apm/error/exception.rb +3 -1
- data/lib/elastic_apm/error_builder.rb +6 -3
- data/lib/elastic_apm/instrumenter.rb +6 -0
- data/lib/elastic_apm/metadata.rb +2 -1
- data/lib/elastic_apm/metrics.rb +2 -1
- data/lib/elastic_apm/metrics/vm.rb +60 -0
- data/lib/elastic_apm/normalizers/action_controller.rb +5 -2
- data/lib/elastic_apm/normalizers/action_mailer.rb +5 -2
- data/lib/elastic_apm/normalizers/action_view.rb +14 -9
- data/lib/elastic_apm/normalizers/active_record.rb +5 -2
- data/lib/elastic_apm/rails.rb +59 -0
- data/lib/elastic_apm/railtie.rb +11 -48
- data/lib/elastic_apm/span.rb +29 -7
- data/lib/elastic_apm/spies/faraday.rb +9 -2
- data/lib/elastic_apm/spies/http.rb +9 -2
- data/lib/elastic_apm/spies/mongo.rb +18 -3
- data/lib/elastic_apm/spies/net_http.rb +8 -2
- data/lib/elastic_apm/stacktrace/frame.rb +3 -1
- data/lib/elastic_apm/stacktrace_builder.rb +2 -2
- data/lib/elastic_apm/subscriber.rb +11 -3
- data/lib/elastic_apm/transport/connection.rb +17 -3
- data/lib/elastic_apm/transport/connection/proxy_pipe.rb +8 -1
- data/lib/elastic_apm/transport/filters/secrets_filter.rb +3 -1
- data/lib/elastic_apm/transport/serializers/error_serializer.rb +12 -2
- data/lib/elastic_apm/transport/serializers/metadata_serializer.rb +6 -1
- data/lib/elastic_apm/transport/serializers/span_serializer.rb +11 -3
- data/lib/elastic_apm/version.rb +1 -1
- metadata +26 -4
- data/Jenkinsfile +0 -280
- data/lib/elastic_apm/config/size.rb +0 -28
data/docs/api.asciidoc
CHANGED
@@ -30,9 +30,10 @@ ElasticAPM.start(server_url: 'http://localhost:8200')
|
|
30
30
|
* `config`: An optional hash or `ElasticAPM::Config` instance with configuration
|
31
31
|
options. See <<configuration,Configuration>>.
|
32
32
|
|
33
|
-
If you are using <<getting-started-rails,Ruby on Rails>> this is done
|
34
|
-
|
35
|
-
|
33
|
+
If you are using <<getting-started-rails,Ruby on Rails>> this is done automatically for you.
|
34
|
+
If you choose not to require the `elastic_apm` gem and instead want to start the
|
35
|
+
agent and hook into Rails manually, see <<rails-start,hooking into Rails explicitly>>.
|
36
|
+
If you're not using Rails, see <<getting-started-rack,Getting started with Rack>>.
|
36
37
|
|
37
38
|
[float]
|
38
39
|
[[api-agent-stop]]
|
@@ -140,7 +141,9 @@ end
|
|
140
141
|
Arguments:
|
141
142
|
|
142
143
|
* `name`: A name for your span. **Required**.
|
143
|
-
* `type`: The type of
|
144
|
+
* `type`: The type of span eg. `db`.
|
145
|
+
* `subtype`: The subtype of span eg. `postgresql`.
|
146
|
+
* `action`: The action type of span eg. `connect` or `query`.
|
144
147
|
* `context`: An instance of `Span::Context`.
|
145
148
|
* `include_stacktrace`: Whether or not to collect a Stacktrace.
|
146
149
|
* `&block`: An optional block to wrap with the span.
|
@@ -163,7 +166,9 @@ Wraps a block in a Span.
|
|
163
166
|
Arguments:
|
164
167
|
|
165
168
|
* `name`: A name for your span. **Required**.
|
166
|
-
* `type`: The type of
|
169
|
+
* `type`: The type of span eg. `db`.
|
170
|
+
* `subtype`: The subtype of span eg. `postgresql`.
|
171
|
+
* `action`: The action type of span eg. `connect` or `query`.
|
167
172
|
* `context`: An instance of `Span::Context`.
|
168
173
|
* `include_stacktrace`: Whether or not to collect a Stacktrace.
|
169
174
|
* `&block`: An optional block to wrap with the span.
|
@@ -186,6 +191,18 @@ Arguments:
|
|
186
191
|
|
187
192
|
Returns the built context.
|
188
193
|
|
194
|
+
[float]
|
195
|
+
[[rails-start]]
|
196
|
+
=== Manually hooking into Rails
|
197
|
+
|
198
|
+
Start the agent and hook into Rails explicitly. This is useful if you skip requiring
|
199
|
+
the gem and using the `Railtie`.
|
200
|
+
|
201
|
+
[source,ruby]
|
202
|
+
----
|
203
|
+
ElasticAPM::Rails.start(server_url: 'http://localhost:8200')
|
204
|
+
----
|
205
|
+
|
189
206
|
[float]
|
190
207
|
=== Errors
|
191
208
|
|
@@ -212,7 +229,7 @@ Arguments:
|
|
212
229
|
* `handled`: Whether the error was _handled_ eg. wasn't rescued and was represented
|
213
230
|
to the user. Default: `true`.
|
214
231
|
|
215
|
-
Returns `[ElasticAPM::Error]
|
232
|
+
Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
|
216
233
|
|
217
234
|
[float]
|
218
235
|
[[api-agent-report-message]]
|
@@ -231,7 +248,7 @@ Arguments:
|
|
231
248
|
|
232
249
|
* `message`: A custom error string. **Required**.
|
233
250
|
|
234
|
-
Returns `[ElasticAPM::Error]
|
251
|
+
Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
|
235
252
|
|
236
253
|
[float]
|
237
254
|
[[api-context]]
|
data/docs/configuration.asciidoc
CHANGED
@@ -62,7 +62,7 @@ Some options can be set with `ENV` variables and all of them may be set in
|
|
62
62
|
your source code.
|
63
63
|
|
64
64
|
When setting values for lists using `ENV` variables, strings are split by comma
|
65
|
-
eg `
|
65
|
+
eg `ELASTIC_APM_CUSTOM_KEY_FILTERS="a,b" # => [/a/, /b/]`.
|
66
66
|
|
67
67
|
[float]
|
68
68
|
[[config-config-file]]
|
@@ -213,6 +213,21 @@ Whether or not to attach the request headers to transactions and errors.
|
|
213
213
|
|
214
214
|
Whether or not to attach `ENV` from Rack to transactions and errors.
|
215
215
|
|
216
|
+
[float]
|
217
|
+
[[config-central-config]]
|
218
|
+
==== `central_config`
|
219
|
+
|============
|
220
|
+
| Environment | `Config` key | Default
|
221
|
+
| `ELASTIC_APM_CENTRAL_CONFIG` | `central_config` | `true`
|
222
|
+
|============
|
223
|
+
|
224
|
+
Enable {kibana-ref}/agent-configuration.html[APM Agent Configuration via Kibana].
|
225
|
+
If set to `true`, the client will poll the APM Server regularly for new agent configuration.
|
226
|
+
|
227
|
+
Usually APM Server determines how often to poll, but if not the default interval is 5 minutes.
|
228
|
+
|
229
|
+
NOTE: This feature requires APM Server v7.3 or later and that the APM Server is configured with `kibana.enabled: true`.
|
230
|
+
|
216
231
|
[float]
|
217
232
|
[[config-custom-key-filters]]
|
218
233
|
==== `custom_key_filters`
|
@@ -244,6 +259,10 @@ Add default tags to add to every transaction.
|
|
244
259
|
|
245
260
|
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]*.
|
246
261
|
|
262
|
+
NOTE: `global_labels` are supported as of APM server version 7.2. `default_tags` will eventually be
|
263
|
+
deprecated so please transition to using `global_labels` instead. In the meantime, any `default_tags`
|
264
|
+
that are set will override `global_labels`.
|
265
|
+
|
247
266
|
[float]
|
248
267
|
[[config-disable-send]]
|
249
268
|
==== `disable_send`
|
@@ -292,11 +311,14 @@ Get an array of enabled spies with `ElasticAPM.agent.config.enabled_spies`.
|
|
292
311
|
The name of the environment this service is deployed in,
|
293
312
|
e.g. "production" or "staging".
|
294
313
|
|
314
|
+
Environments allow you to easily filter data on a global level in the APM UI.
|
315
|
+
It's important to be consistent when naming environments across agents.
|
316
|
+
See {kibana-ref}/filters.html#environment-selector[environment selector] in the Kibana UI for more information.
|
317
|
+
|
295
318
|
Defaults to `ENV['RAILS_ENV'] || ENV['RACK_ENV']`.
|
296
319
|
|
297
|
-
NOTE:
|
298
|
-
|
299
|
-
`service_name`.
|
320
|
+
NOTE: This feature is fully supported in the APM UI in Kibana versions >= 7.2.
|
321
|
+
You must use the query bar to filter for a specific environment in versions prior to 7.2.
|
300
322
|
|
301
323
|
[float]
|
302
324
|
[[config-filter-exception-types]]
|
@@ -334,6 +356,23 @@ Version number of the used framework.
|
|
334
356
|
For Ruby on Rails and Sinatra, this defaults to the used version of the framework,
|
335
357
|
otherwise, the default is `nil`.
|
336
358
|
|
359
|
+
[float]
|
360
|
+
[[config-global-labels]]
|
361
|
+
==== `global_labels`
|
362
|
+
|
363
|
+
[options="header"]
|
364
|
+
|============
|
365
|
+
| Environment | `Config` key | Default | Example
|
366
|
+
| `ELASTIC_APM_GLOBAL_LABELS` | `global_labels` | `nil` | `dept=engineering,rack=number8`
|
367
|
+
|============
|
368
|
+
|
369
|
+
Labels added to all events, with the format key=value[,key=value[,...]].
|
370
|
+
|
371
|
+
NOTE: This option requires APM Server 7.2 or greater, and will have no effect when using older
|
372
|
+
server versions. `default_tags` will eventually be deprecated but in the meantime, their value
|
373
|
+
will override any `global_labels`. Please transition to using `global_labels` instead of
|
374
|
+
`default_tags` in light of this deprecation.
|
375
|
+
|
337
376
|
[float]
|
338
377
|
[[config-hostname]]
|
339
378
|
==== `hostname`
|
data/docs/index.asciidoc
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
ifdef::env-github[]
|
2
|
+
NOTE: For the best reading experience,
|
3
|
+
please view this documentation at https://www.elastic.co/guide/en/apm/agent/ruby[elastic.co]
|
4
|
+
endif::[]
|
5
|
+
|
6
|
+
[[log-correlation]]
|
7
|
+
== Log correlation
|
8
|
+
|
9
|
+
Trace/log correlation can be set up in three different ways.
|
10
|
+
|
11
|
+
[float]
|
12
|
+
[[rails-tagged-logging]]
|
13
|
+
==== Rails TaggedLogging
|
14
|
+
|
15
|
+
Rails applications configured with an `ActiveSupport::TaggedLogging` logger can append the correlation IDs to log output.
|
16
|
+
For example in your `config/environments/production.rb` file, add the following:
|
17
|
+
|
18
|
+
[source,ruby]
|
19
|
+
----
|
20
|
+
config.log_tags = [ :request_id, proc { ElasticAPM.log_ids } ]
|
21
|
+
|
22
|
+
# Logs will then include the correlation IDs:
|
23
|
+
#
|
24
|
+
# [transaction.id=c1ae84c8642891eb trace.id=b899fc7915e801b7558e336e4952bafe] Started GET "/" for 127.0.0.1 at 2019-09-16 11:28:46 +0200
|
25
|
+
# [transaction.id=c1ae84c8642891eb trace.id=b899fc7915e801b7558e336e4952bafe] Processing by ApplicationController#index as HTML
|
26
|
+
# [transaction.id=c1ae84c8642891eb trace.id=b899fc7915e801b7558e336e4952bafe] Rendering text template
|
27
|
+
# [transaction.id=c1ae84c8642891eb trace.id=b899fc7915e801b7558e336e4952bafe] Rendered text template (Duration: 0.1ms | Allocations: 17)
|
28
|
+
# [transaction.id=c1ae84c8642891eb trace.id=b899fc7915e801b7558e336e4952bafe] Completed 200 OK in 1ms (Views: 0.4ms | Allocations: 171)
|
29
|
+
----
|
30
|
+
**Note:** Because of the order in which Rails computes the tags for logs and executes the request, the span id might not be included.
|
31
|
+
Consider using `Lograge` instead, as the timing of its hooks allow the span id to be captured in logs.
|
32
|
+
|
33
|
+
[float]
|
34
|
+
[[lograge]]
|
35
|
+
==== Lograge
|
36
|
+
|
37
|
+
With `lograge` enabled and set up in your Rails application, modify the `custom_options` block in the Rails environment
|
38
|
+
configuration file. The returned `Hash` will be included in the structured Lograge logs.
|
39
|
+
|
40
|
+
[source,ruby]
|
41
|
+
----
|
42
|
+
config.lograge.custom_options = lambda do |event|
|
43
|
+
ElasticAPM.log_ids do |transaction_id, span_id, trace_id|
|
44
|
+
{ :'transaction.id' => transaction_id,
|
45
|
+
:'span.id' => span_id,
|
46
|
+
:'trace.id' => trace_id }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Logs will then include the correlation IDs:
|
51
|
+
#
|
52
|
+
# I, [2019-09-16T11:59:05.439602 #8674] INFO -- : method=GET path=/ format=html controller=ApplicationController action=index status=200 duration=0.36 view=0.20 transaction.id=56a9186a9257aa08 span.id=8e84a786ab0abbb2 trace.id=1bbab8ac4c7c9584f53eb882ff0dfdd8
|
53
|
+
----
|
54
|
+
|
55
|
+
You can also nest the ids in a separate document as in the following example:
|
56
|
+
|
57
|
+
[source,ruby]
|
58
|
+
----
|
59
|
+
config.lograge.custom_options = lambda do |event|
|
60
|
+
ElasticAPM.log_ids do |transaction_id, span_id, trace_id|
|
61
|
+
{ elastic_apm: { :'transaction.id' => transaction_id,
|
62
|
+
:'span.id' => span_id,
|
63
|
+
:'trace.id' => trace_id } }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Logs will then include the correlation IDs in a separate document:
|
68
|
+
#
|
69
|
+
# I, [2019-09-16T13:39:35.962603 #9327] INFO -- : method=GET path=/ format=html controller=ApplicationController action=index status=200 duration=0.37 view=0.20 elastic_apm={:transaction_id=>"2fb84f5d0c48a296", :span_id=>"2e5c5a7c85f83be7", :trace_id=>"43e1941c4a6fff343a4e018ff7b92000"}
|
70
|
+
----
|
71
|
+
|
72
|
+
[float]
|
73
|
+
[[manually-formatting-logs]]
|
74
|
+
==== Manually formatting logs
|
75
|
+
|
76
|
+
You can access the correlation ids directly and add them through the log formatter.
|
77
|
+
|
78
|
+
[source,ruby]
|
79
|
+
----
|
80
|
+
require 'elastic_apm'
|
81
|
+
require 'logger'
|
82
|
+
|
83
|
+
logger = Logger.new(STDOUT)
|
84
|
+
logger.progname = 'TestRubyApp'
|
85
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
86
|
+
"[#{datetime}][#{progname}][#{severity}][#{ElasticAPM.log_ids}] #{msg}\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
# Logs will then include the correlation IDs:
|
90
|
+
#
|
91
|
+
# [2019-09-16 11:54:59 +0200][RailsTestApp][INFO][transaction.id=3b92edcccc0a6d1e trace.id=1275686e35de91f776557637e799651e] Started GET "/" for 127.0.0.1 at 2019-09-16 11:54:59 +0200
|
92
|
+
# [2019-09-16 11:54:59 +0200][RailsTestApp][INFO][transaction.id=3b92edcccc0a6d1e trace.id=1275686e35de91f776557637e799651e] Processing by ApplicationController#index as HTML
|
93
|
+
# [2019-09-16 11:54:59 +0200][RailsTestApp][INFO][transaction.id=3b92edcccc0a6d1e span.id=3bde4e9c85ab359c trace.id=1275686e35de91f776557637e799651e] Rendering text template
|
94
|
+
# [2019-09-16 11:54:59 +0200][RailsTestApp][INFO][transaction.id=3b92edcccc0a6d1e span.id=f3d7e32f176d4c93 trace.id=1275686e35de91f776557637e799651e] Rendered text template (Duration: 0.1ms | Allocations: 17)
|
95
|
+
# [2019-09-16 11:54:59 +0200][RailsTestApp][INFO][transaction.id=3b92edcccc0a6d1e span.id=3bde4e9c85ab359c trace.id=1275686e35de91f776557637e799651e] Completed 200 OK in 1ms (Views: 0.3ms | Allocations: 187)
|
96
|
+
----
|
data/docs/metrics.asciidoc
CHANGED
@@ -12,11 +12,15 @@ You can adjust the interval by setting <<config-metrics-interval,`metrics_interv
|
|
12
12
|
|
13
13
|
The metrics will be stored in the `apm-*` index and have the `processor.event` property set to `metric`.
|
14
14
|
|
15
|
+
[float]
|
16
|
+
[[metrics-system]]
|
17
|
+
=== System metrics
|
18
|
+
|
15
19
|
**Note:** Metrics from the Ruby agent are Linux only for now.
|
16
20
|
|
17
21
|
[float]
|
18
22
|
[[metric-system.cpu.total.norm.pct]]
|
19
|
-
|
23
|
+
==== `system.cpu.total.norm.pct`
|
20
24
|
|
21
25
|
* *Type:* Float
|
22
26
|
* *Format:* Percent
|
@@ -26,7 +30,7 @@ normalised by the number of cores.
|
|
26
30
|
|
27
31
|
[float]
|
28
32
|
[[metric-system.memory.total]]
|
29
|
-
|
33
|
+
==== `system.memory.total`
|
30
34
|
|
31
35
|
* *Type:* Long
|
32
36
|
* *Format:* Bytes
|
@@ -35,7 +39,7 @@ The total memory of the system in bytes.
|
|
35
39
|
|
36
40
|
[float]
|
37
41
|
[[metric-system.memory.actual.free]]
|
38
|
-
|
42
|
+
==== `system.memory.actual.free`
|
39
43
|
|
40
44
|
* *Type:* Long
|
41
45
|
* *Format:* Bytes
|
@@ -44,7 +48,7 @@ Free memory of the system in bytes.
|
|
44
48
|
|
45
49
|
[float]
|
46
50
|
[[metric-system.process.cpu.total.norm.pct]]
|
47
|
-
|
51
|
+
==== `system.process.cpu.total.norm.pct`
|
48
52
|
|
49
53
|
* *Type:* Float
|
50
54
|
* *Format:* Percent
|
@@ -54,7 +58,7 @@ This value is normalized by the number of CPU cores and it ranges from 0 to 100%
|
|
54
58
|
|
55
59
|
[float]
|
56
60
|
[[metric-system.process.memory.size]]
|
57
|
-
|
61
|
+
==== `system.process.memory.size`
|
58
62
|
|
59
63
|
* *Type:* Long
|
60
64
|
* *Format:* Bytes
|
@@ -63,10 +67,77 @@ The total virtual memory the process has.
|
|
63
67
|
|
64
68
|
[float]
|
65
69
|
[[metric-system.process.memory.rss.bytes]]
|
66
|
-
|
70
|
+
==== `system.process.memory.rss.bytes`
|
67
71
|
|
68
72
|
* *Type:* Long
|
69
73
|
* *Format:* Bytes
|
70
74
|
|
71
75
|
The Resident Set Size,
|
72
76
|
the amount of memory the process occupies in main memory (RAM).
|
77
|
+
|
78
|
+
[float]
|
79
|
+
[[metrics-ruby]]
|
80
|
+
=== Ruby Metrics
|
81
|
+
|
82
|
+
[float]
|
83
|
+
[[metric-ruby.gc.counts]]
|
84
|
+
==== `ruby.gc.count`
|
85
|
+
|
86
|
+
* *Type:* Integer
|
87
|
+
* *Format:* Count
|
88
|
+
|
89
|
+
The number of Garbage Collection runs since the process started.
|
90
|
+
|
91
|
+
[float]
|
92
|
+
[[metric-ruby.threads]]
|
93
|
+
==== `ruby.threads`
|
94
|
+
|
95
|
+
* *Type:* Integer
|
96
|
+
* *Format:* Count
|
97
|
+
|
98
|
+
The number of threads belonging to the current process.
|
99
|
+
|
100
|
+
[float]
|
101
|
+
[[metric-ruby.heap.slots.live]]
|
102
|
+
==== `ruby.heap.slots.live`
|
103
|
+
|
104
|
+
* *Type:* Integer
|
105
|
+
* *Format:* Slots
|
106
|
+
|
107
|
+
Current amount of heap slots that are live.
|
108
|
+
|
109
|
+
**NB:** Not currently supported on JRuby.
|
110
|
+
|
111
|
+
[float]
|
112
|
+
[[metric-ruby.heap.slots.free]]
|
113
|
+
==== `ruby.heap.slots.free`
|
114
|
+
|
115
|
+
* *Type:* Integer
|
116
|
+
* *Format:* Slots
|
117
|
+
|
118
|
+
Current amount of heap slots that are free.
|
119
|
+
|
120
|
+
**NB:** Not currently supported on JRuby.
|
121
|
+
|
122
|
+
[float]
|
123
|
+
[[metrics-ruby.heap.allocations.total]]
|
124
|
+
==== `ruby.heap.allocations.total`
|
125
|
+
|
126
|
+
* *Type:* Integer
|
127
|
+
* *Format:* Objects
|
128
|
+
|
129
|
+
Current amount of allocated objects on the heap.
|
130
|
+
|
131
|
+
**NB:** Not currently supported on JRuby.
|
132
|
+
|
133
|
+
[float]
|
134
|
+
[[metrics-ruby.gc.time]]
|
135
|
+
==== `ruby.gc.time`
|
136
|
+
|
137
|
+
* *Type:* Float
|
138
|
+
* *Format:* Seconds
|
139
|
+
|
140
|
+
The total time spent in garbage collection.
|
141
|
+
|
142
|
+
**NB:** You need to enable Ruby's GC Profiler for this to get reported.
|
143
|
+
You can do this at any time when your application boots by calling `GC::Profiler.enable`.
|
data/lib/elastic_apm.rb
CHANGED
@@ -62,6 +62,26 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
62
62
|
agent&.current_span
|
63
63
|
end
|
64
64
|
|
65
|
+
# rubocop:disable Metrics/AbcSize
|
66
|
+
# Get a formatted string containing transaction, span, and trace ids.
|
67
|
+
# If a block is provided, the ids are yielded.
|
68
|
+
#
|
69
|
+
# @yield [String|nil, String|nil, String|nil] The transaction, span, and trace ids.
|
70
|
+
# @return [String] Unless block given
|
71
|
+
def log_ids
|
72
|
+
trace_id = (current_transaction || current_span)&.trace_id
|
73
|
+
if block_given?
|
74
|
+
return yield(current_transaction&.id, current_span&.id, trace_id)
|
75
|
+
end
|
76
|
+
|
77
|
+
ids = []
|
78
|
+
ids << "transaction.id=#{current_transaction.id}" if current_transaction
|
79
|
+
ids << "span.id=#{current_span.id}" if current_span
|
80
|
+
ids << "trace.id=#{trace_id}" if trace_id
|
81
|
+
ids.join(' ')
|
82
|
+
end
|
83
|
+
# rubocop:enable Metrics/AbcSize
|
84
|
+
|
65
85
|
# Start a new transaction or return the currently running
|
66
86
|
#
|
67
87
|
# @param name [String] A description of the transaction, eg
|
@@ -207,16 +227,21 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
207
227
|
|
208
228
|
deprecate :span, :with_span
|
209
229
|
|
230
|
+
# rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
|
210
231
|
# Start a new span
|
211
232
|
#
|
212
233
|
# @param name [String] A description of the span, eq `SELECT FROM "users"`
|
213
|
-
# @param type [String] The
|
234
|
+
# @param type [String] The span type, eq `db`
|
235
|
+
# @param subtype [String] The span subtype, eq `postgresql`
|
236
|
+
# @param action [String] The span action type, eq `connect` or `query`
|
214
237
|
# @param context [Span::Context] Context information about the span
|
215
238
|
# @param include_stacktrace [Boolean] Whether or not to capture a stacktrace
|
216
239
|
# @return [Span]
|
217
240
|
def start_span(
|
218
241
|
name,
|
219
242
|
type = nil,
|
243
|
+
subtype: nil,
|
244
|
+
action: nil,
|
220
245
|
context: nil,
|
221
246
|
include_stacktrace: true,
|
222
247
|
trace_context: nil
|
@@ -224,6 +249,8 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
224
249
|
agent&.start_span(
|
225
250
|
name,
|
226
251
|
type,
|
252
|
+
subtype: subtype,
|
253
|
+
action: action,
|
227
254
|
context: context,
|
228
255
|
trace_context: trace_context
|
229
256
|
).tap do |span|
|
@@ -233,6 +260,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
233
260
|
span.original_backtrace ||= caller
|
234
261
|
end
|
235
262
|
end
|
263
|
+
# rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
|
236
264
|
|
237
265
|
# Ends the current span
|
238
266
|
#
|
@@ -241,7 +269,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
241
269
|
agent&.end_span
|
242
270
|
end
|
243
271
|
|
244
|
-
# rubocop:disable Metrics/MethodLength
|
272
|
+
# rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
|
245
273
|
# Wrap a block in a Span, ending it after the block
|
246
274
|
#
|
247
275
|
# @param name [String] A description of the span, eq `SELECT FROM "users"`
|
@@ -253,6 +281,8 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
253
281
|
def with_span(
|
254
282
|
name,
|
255
283
|
type = nil,
|
284
|
+
subtype: nil,
|
285
|
+
action: nil,
|
256
286
|
context: nil,
|
257
287
|
include_stacktrace: true,
|
258
288
|
trace_context: nil
|
@@ -269,6 +299,8 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
269
299
|
start_span(
|
270
300
|
name,
|
271
301
|
type,
|
302
|
+
subtype: subtype,
|
303
|
+
action: action,
|
272
304
|
context: context,
|
273
305
|
include_stacktrace: include_stacktrace,
|
274
306
|
trace_context: trace_context
|
@@ -278,7 +310,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
278
310
|
end_span
|
279
311
|
end
|
280
312
|
end
|
281
|
-
# rubocop:enable Metrics/MethodLength
|
313
|
+
# rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
|
282
314
|
|
283
315
|
# Build a [Context] from a Rack `env`. The context may include information
|
284
316
|
# about the request, response, current user and more
|
@@ -305,7 +337,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
305
337
|
# @param exception [Exception] The exception
|
306
338
|
# @param context [Context] An optional [Context]
|
307
339
|
# @param handled [Boolean] Whether the exception was rescued
|
308
|
-
# @return [
|
340
|
+
# @return [String] ID of the generated [Error]
|
309
341
|
def report(exception, context: nil, handled: true)
|
310
342
|
agent&.report(exception, context: context, handled: handled)
|
311
343
|
end
|
@@ -314,7 +346,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
|
|
314
346
|
#
|
315
347
|
# @param message [String] The message
|
316
348
|
# @param context [Context] An optional [Context]
|
317
|
-
# @return [
|
349
|
+
# @return [String] ID of the generated [Error]
|
318
350
|
def report_message(message, context: nil, **attrs)
|
319
351
|
agent&.report_message(
|
320
352
|
message,
|