elastic-apm 0.7.1 → 0.7.2
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.
Potentially problematic release.
This version of elastic-apm might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +19 -3
- data/bin/build_docs +5 -0
- data/docs/api.asciidoc +100 -34
- data/docs/configuration.asciidoc +349 -9
- data/docs/custom-instrumentation.asciidoc +85 -6
- data/docs/getting-started-rack.asciidoc +43 -4
- data/docs/getting-started-rails.asciidoc +8 -0
- data/docs/index.asciidoc +3 -3
- data/lib/elastic_apm.rb +1 -0
- data/lib/elastic_apm/agent.rb +7 -4
- data/lib/elastic_apm/config.rb +32 -13
- data/lib/elastic_apm/filters/secrets_filter.rb +2 -1
- data/lib/elastic_apm/http.rb +1 -0
- data/lib/elastic_apm/serializers.rb +2 -0
- data/lib/elastic_apm/span.rb +26 -1
- data/lib/elastic_apm/span_helpers.rb +8 -1
- data/lib/elastic_apm/stacktrace/frame.rb +1 -0
- data/lib/elastic_apm/transaction.rb +9 -4
- data/lib/elastic_apm/util/dig.rb +1 -1
- 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: be39e840d3e28c527b2aa20b19e0c81820c9a7660977179439d19ce92cfd7903
|
4
|
+
data.tar.gz: 10fe2ea416b4ade09b0fdb5b76d7609135c0bae3c5ba855cf8dffccf110f4d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3d2e587d199b774c3d647a6790215866641c36305241870b5843d11af5d80a926a6326f9aa6b6f5112419184660cfb8c5ec7dc637ce364a5ed1eb04d1f32a6b
|
7
|
+
data.tar.gz: 9780322c3de755f2db259de818df6bfb2339c37ec24038412a378ec42a85991edbe4a0f7271c2a48ce6cc5246a73d17aabe081867517171c7e25de8bce5d0643
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
# elastic-apm
|
1
|
+
# elastic-apm
|
2
|
+
## Elastic APM agent for ♦️Ruby (🚧 BETA)
|
2
3
|
|
3
4
|
[](https://apm-ci.elastic.co/job/elastic+apm-agent-ruby+master/)
|
4
5
|
|
5
|
-
This is the official Rubygem for
|
6
|
+
This is the official Rubygem for [Elastic][] [APM][].
|
7
|
+
|
8
|
+
💡 We'd love to get feedback and information about you setup – please answer this [☑ short survey](https://goo.gl/forms/LQktvn4rkLWBNSWy1).
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
## Documentation
|
13
|
+
|
14
|
+
[Full documentation at Elasti.co](https://www.elastic.co/guide/en/apm/agent/ruby/index.html).
|
6
15
|
|
7
16
|
<div>
|
8
17
|
<ul>
|
@@ -21,7 +30,14 @@ This is the official Rubygem for adding [Elastic][]'s [APM][] to your Ruby app.
|
|
21
30
|
</ul>
|
22
31
|
</div>
|
23
32
|
|
24
|
-
|
33
|
+
---
|
34
|
+
|
35
|
+
## Getting help
|
36
|
+
|
37
|
+
If you find a bug, please [report an issue](https://github.com/elastic/apm-agent-ruby/issues).
|
38
|
+
For any other assistance, please open or add to a topic on the [APM discuss forum](https://discuss.elastic.co/c/apm).
|
39
|
+
|
40
|
+
## License
|
25
41
|
|
26
42
|
Apache 2.0
|
27
43
|
|
data/bin/build_docs
ADDED
data/docs/api.asciidoc
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
[[api]]
|
2
2
|
== Public API
|
3
3
|
|
4
|
-
Although most usage is covered automatically
|
4
|
+
Although most usage is covered automatically, Elastic APM also has a public API that
|
5
|
+
allows custom usage.
|
5
6
|
|
6
7
|
[float]
|
7
8
|
[[agent-life-cycle]]
|
@@ -10,7 +11,7 @@ Although most usage is covered automatically when using the APM Agent it also ha
|
|
10
11
|
Controlling when the agent starts and stops.
|
11
12
|
|
12
13
|
[float]
|
13
|
-
[[api-start]]
|
14
|
+
[[api-agent-start]]
|
14
15
|
==== `ElasticAPM.start`
|
15
16
|
|
16
17
|
To create and start an ElasticAPM agent use `ElasticAPM.start`:
|
@@ -20,26 +21,27 @@ To create and start an ElasticAPM agent use `ElasticAPM.start`:
|
|
20
21
|
ElasticAPM.start(server_url: 'http://localhost:8200')
|
21
22
|
----
|
22
23
|
|
23
|
-
* `config`:
|
24
|
+
* `config`: An optional hash or `ElasticAPM::Config` instance with configuration
|
25
|
+
options. See <<configuration,Configuration>>.
|
24
26
|
|
25
|
-
If you are using Rails this is done automatically for you.
|
26
|
-
|
27
|
-
**ElasticAPM expects a single instance of the Agent.**
|
27
|
+
If you are using <<getting-started-rails,Ruby on Rails>> this is done automatically for you.
|
28
|
+
If not see <<getting-started-rack,Getting started with Rack>>.
|
28
29
|
|
29
30
|
[float]
|
30
|
-
[[api-stop]]
|
31
|
+
[[api-agent-stop]]
|
31
32
|
==== `ElasticAPM.stop`
|
32
33
|
|
33
|
-
Stop the currently running agent. Use this inside `at_exit` in your
|
34
|
+
Stop the currently running agent. Use this inside `at_exit` in your
|
35
|
+
<<getting-started-rack,Rack app>> to gracefully shut down.
|
34
36
|
|
35
37
|
[float]
|
36
|
-
[[api-running]]
|
38
|
+
[[api-agent-running]]
|
37
39
|
==== `ElasticAPM.running?`
|
38
40
|
|
39
41
|
Returns whether the ElasticAPM Agent is currently running.
|
40
42
|
|
41
43
|
[float]
|
42
|
-
[[api-agent]]
|
44
|
+
[[api-agent-agent]]
|
43
45
|
==== `ElasticAPM.agent`
|
44
46
|
|
45
47
|
Returns the currently running agent or nil.
|
@@ -48,45 +50,57 @@ Returns the currently running agent or nil.
|
|
48
50
|
=== Instrumentation
|
49
51
|
|
50
52
|
[float]
|
51
|
-
[[api-current-transaction]]
|
53
|
+
[[api-agent-current-transaction]]
|
52
54
|
==== `ElasticAPM.current_transaction`
|
53
55
|
|
54
56
|
Returns the current `ElasticAPM::Transaction` or nil.
|
55
57
|
|
56
58
|
[float]
|
57
|
-
[[api-transaction]]
|
59
|
+
[[api-agent-transaction]]
|
58
60
|
==== `ElasticAPM.transaction`
|
59
61
|
|
60
62
|
Start a _transaction_ eg. a web request or background job.
|
61
63
|
|
62
|
-
If called without a block you are expected to end
|
63
|
-
If given a block, the code inside will be wrapped in a transaction.
|
64
|
+
If called without a block you are expected to end the transaction yourself.
|
65
|
+
If given a block, the code inside will be wrapped in a transaction.
|
66
|
+
|
67
|
+
You need to submit it yourself with `transaction.submit(status)`.
|
64
68
|
|
65
69
|
[source,ruby]
|
66
70
|
----
|
71
|
+
# call with block
|
67
72
|
transaction = ElasticAPM.transaction('Do things') do
|
68
|
-
# ...
|
69
|
-
end
|
73
|
+
do_work # ...
|
74
|
+
end # .done is called when block ends
|
70
75
|
|
71
76
|
transaction.submit(200)
|
77
|
+
|
78
|
+
# without block
|
79
|
+
transaction = ElasticAPM.transaction('Do things')
|
80
|
+
do_work
|
81
|
+
transaction.submit(200) # .submit(result) will also .done(result)
|
72
82
|
----
|
73
83
|
|
74
84
|
Arguments:
|
75
85
|
|
76
86
|
* `name`: A name for your transaction. Transactions are grouped by name. **Required**.
|
77
87
|
* `type`: A `type` for your transaction eg. `db.postgresql.sql`.
|
78
|
-
* `
|
79
|
-
|
88
|
+
* `context:`: An optional <<api-context,Context>> used to enrich the transaction with
|
89
|
+
information about the current request.
|
90
|
+
* `&block`: An optional block to wrap with the transaction. The block is passed the
|
91
|
+
transaction as an optional argument.
|
80
92
|
|
81
93
|
Returns the transaction.
|
82
94
|
|
83
95
|
[float]
|
84
|
-
[[api-span]]
|
96
|
+
[[api-agent-span]]
|
85
97
|
==== `ElasticAPM.span`
|
86
98
|
|
87
|
-
Most transactions have nested spans signifying work of a specific sort eg. database
|
99
|
+
Most transactions have nested spans signifying work of a specific sort eg. database
|
100
|
+
queries or external web requests.
|
88
101
|
|
89
|
-
If given a block, wrap the code inside in a span.
|
102
|
+
If given a block, wrap the code inside in a span.
|
103
|
+
If not you are expected to close the span yourself with `span.done(result)`.
|
90
104
|
|
91
105
|
[source,ruby]
|
92
106
|
----
|
@@ -102,12 +116,14 @@ Arguments:
|
|
102
116
|
* `name`: A name for your span. **Required**.
|
103
117
|
* `type`: The type of work eg. `db.postgresql.query`.
|
104
118
|
* `context`: An instance of `Span::Context`.
|
105
|
-
*
|
119
|
+
* `include_stacktrace`: Whether or not to collect a Stacktrace.
|
120
|
+
* `&block`: An optional block to wrap with the span.
|
121
|
+
The block is passed the span as an optional argument.
|
106
122
|
|
107
123
|
Return the span or the return value of the given block.
|
108
124
|
|
109
125
|
[float]
|
110
|
-
[[api-build-context]]
|
126
|
+
[[api-agent-build-context]]
|
111
127
|
==== `ElasticAPM.build_context`
|
112
128
|
|
113
129
|
Build a new _Context_ from a Rack `env`.
|
@@ -124,7 +140,7 @@ Returns the built context.
|
|
124
140
|
=== Errors
|
125
141
|
|
126
142
|
[float]
|
127
|
-
[[api-report]]
|
143
|
+
[[api-agent-report]]
|
128
144
|
==== `ElasticAPM.report`
|
129
145
|
|
130
146
|
Send an `Exception` to Elastic APM.
|
@@ -143,12 +159,13 @@ end
|
|
143
159
|
Arguments:
|
144
160
|
|
145
161
|
* `exception`: An instance of `Exception`. **Required**.
|
146
|
-
* `handled`: Whether the error was _handled_ eg. wasn't rescued and was represented
|
162
|
+
* `handled`: Whether the error was _handled_ eg. wasn't rescued and was represented
|
163
|
+
to the user. Default: `true`.
|
147
164
|
|
148
165
|
Returns `[ElasticAPM::Error]`.
|
149
166
|
|
150
167
|
[float]
|
151
|
-
[[api-report-message]]
|
168
|
+
[[api-agent-report-message]]
|
152
169
|
==== `ElasticAPM.report_message`
|
153
170
|
|
154
171
|
Send a custom message to Elastic APM.
|
@@ -163,7 +180,6 @@ ElasticAPM.report_message('This should probably never happen?!')
|
|
163
180
|
Arguments:
|
164
181
|
|
165
182
|
* `message`: A custom error string. **Required**.
|
166
|
-
* `handled`: Whether the error was _handled_ eg. wasn't rescued and was represented to the user. Default: `true`.
|
167
183
|
|
168
184
|
Returns `[ElasticAPM::Error]`.
|
169
185
|
|
@@ -171,15 +187,17 @@ Returns `[ElasticAPM::Error]`.
|
|
171
187
|
=== Context
|
172
188
|
|
173
189
|
[float]
|
174
|
-
[[api-set-tag]]
|
190
|
+
[[api-agent-set-tag]]
|
175
191
|
==== `ElasticAPM.set_tag`
|
176
192
|
|
177
|
-
Add a tag to the current transaction.
|
193
|
+
Add a tag to the current transaction.
|
194
|
+
Tags are basic key-value pairs that are indexed in your Elasticsearch database and
|
195
|
+
therefore searchable.
|
178
196
|
|
179
197
|
[source,ruby]
|
180
198
|
----
|
181
199
|
before_action do
|
182
|
-
ElasticAPM.set_tag(company_id
|
200
|
+
ElasticAPM.set_tag(:company_id, current_user.company.id)
|
183
201
|
end
|
184
202
|
----
|
185
203
|
|
@@ -191,12 +209,15 @@ Arguments:
|
|
191
209
|
Returns the set `value`.
|
192
210
|
|
193
211
|
[float]
|
194
|
-
[[api-set-custom-context]]
|
212
|
+
[[api-agent-set-custom-context]]
|
195
213
|
==== `ElasticAPM.set_custom_context`
|
196
214
|
|
197
|
-
Add custom context to the current transaction.
|
215
|
+
Add custom context to the current transaction.
|
216
|
+
Use this to further specify a context that will help you track or diagnose what's
|
217
|
+
going on inside your app.
|
198
218
|
|
199
|
-
If called several times during a transaction the custom context will be destructively
|
219
|
+
If called several times during a transaction the custom context will be destructively
|
220
|
+
merged with `merge!`.
|
200
221
|
|
201
222
|
[source,ruby]
|
202
223
|
----
|
@@ -212,7 +233,7 @@ Arguments:
|
|
212
233
|
Returns current custom context.
|
213
234
|
|
214
235
|
[float]
|
215
|
-
[[api-set-user]]
|
236
|
+
[[api-agent-set-user]]
|
216
237
|
==== `ElasticAPM.set_user`
|
217
238
|
|
218
239
|
Add the current user to the current transaction's context.
|
@@ -223,3 +244,48 @@ Arguments:
|
|
223
244
|
|
224
245
|
Returns the given user
|
225
246
|
|
247
|
+
[float]
|
248
|
+
=== Data
|
249
|
+
|
250
|
+
[float]
|
251
|
+
[[api-agent-add-filter]]
|
252
|
+
==== `ElasticAPM.add_filter`
|
253
|
+
|
254
|
+
Provide a filter to transform payloads before sending.
|
255
|
+
|
256
|
+
Arguments:
|
257
|
+
|
258
|
+
* `key`: A unique key identifying the filter
|
259
|
+
* `callable`: An object or proc (responds to `.call(payload)`)
|
260
|
+
|
261
|
+
Return the altered payload.
|
262
|
+
|
263
|
+
Example:
|
264
|
+
|
265
|
+
[source,ruby]
|
266
|
+
----
|
267
|
+
ElasticAPM.add_filter(:filter_pings) do |payload|
|
268
|
+
payload['transactions']&.reject! do |t|
|
269
|
+
t['name'] == 'PingsController#index'
|
270
|
+
end
|
271
|
+
end
|
272
|
+
----
|
273
|
+
|
274
|
+
[float]
|
275
|
+
[[api-transaction]]
|
276
|
+
=== Transaction
|
277
|
+
|
278
|
+
Things
|
279
|
+
|
280
|
+
[float]
|
281
|
+
[[api-span]]
|
282
|
+
=== Span
|
283
|
+
|
284
|
+
Things
|
285
|
+
|
286
|
+
[float]
|
287
|
+
[[api-context]]
|
288
|
+
=== Context
|
289
|
+
|
290
|
+
Things
|
291
|
+
|
data/docs/configuration.asciidoc
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
[[configuration]]
|
2
2
|
== Configuration
|
3
3
|
|
4
|
-
There are several ways to
|
4
|
+
There are several ways to configure how Elastic APM behaves.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
The recommended way to configure Elastic APM for Rails is to create a file `config/elastic_apm.yml` and specify options in there:
|
6
|
+
The recommended way to configure Elastic APM is to create a file
|
7
|
+
`config/elastic_apm.yml` and specify options in there:
|
10
8
|
|
11
9
|
[source,yaml]
|
12
10
|
----
|
@@ -15,20 +13,362 @@ server_url: 'http://localhost:8200'
|
|
15
13
|
secret_token: 'very_very_secret'
|
16
14
|
----
|
17
15
|
|
16
|
+
Options are applied in the following order (last one wins):
|
17
|
+
|
18
|
+
1. Defaults
|
19
|
+
2. Arguments to `ElasticAPM.start` / `Config.new`
|
20
|
+
3. Config file eg. `config/elastic_apm.yml`
|
21
|
+
4. Environment variables
|
22
|
+
|
23
|
+
[float]
|
24
|
+
=== Ruby on Rails
|
25
|
+
|
26
|
+
When using Rails it's also possible to specify options inside
|
27
|
+
`config/application.rb`:
|
28
|
+
|
29
|
+
[source,ruby]
|
30
|
+
----
|
31
|
+
# config/application.rb
|
32
|
+
config.elastic_apm.service_name = 'MyApp'
|
33
|
+
----
|
34
|
+
|
18
35
|
[float]
|
19
36
|
=== Sinatra and Rack
|
20
37
|
|
21
|
-
When using APM with Sinatra and Rack
|
38
|
+
When using APM with Sinatra and Rack you can configure it when starting
|
39
|
+
the agent:
|
22
40
|
|
23
41
|
[source,ruby]
|
24
42
|
----
|
43
|
+
# config.ru or similar
|
25
44
|
ElasticAPM.start(
|
26
|
-
|
27
|
-
|
45
|
+
app: MyApp,
|
46
|
+
service_name: 'SomeOtherName'
|
28
47
|
)
|
29
48
|
----
|
30
49
|
|
31
50
|
See <<getting-started-rack>>.
|
32
51
|
|
33
|
-
|
52
|
+
[float]
|
53
|
+
=== Options
|
54
|
+
|
55
|
+
Some options can be set with `ENV` variables and all of them may be set in
|
56
|
+
your source code.
|
57
|
+
|
58
|
+
When setting values for lists using `ENV` variables, strings are split by comma
|
59
|
+
eg `ELASTIC_APM_ENBALED_ENVIRONMENTS=development,production`.
|
60
|
+
|
61
|
+
[float]
|
62
|
+
[[config-config-file]]
|
63
|
+
==== `config_file`
|
64
|
+
|
65
|
+
[options="header"]
|
66
|
+
|============
|
67
|
+
| Environment | `Config` key | Default
|
68
|
+
| `ELASTIC_APM_CONFIG_FILE` | `config_file` | `config/elastic_apm.yml`
|
69
|
+
|============
|
70
|
+
|
71
|
+
Path to the configuration Yaml-file.
|
72
|
+
Elastic APM will load config options from this if the file exists.
|
73
|
+
|
74
|
+
[float]
|
75
|
+
[[config-server-url]]
|
76
|
+
==== `server_url`
|
77
|
+
|
78
|
+
[options="header"]
|
79
|
+
|============
|
80
|
+
| Environment | `Config` key | Default
|
81
|
+
| `ELASTIC_APM_SERVER_URL` | `server_url` | `'http://localhost:8200'`
|
82
|
+
|============
|
83
|
+
|
84
|
+
The URL for your APM Server.
|
85
|
+
The URL must be fully qualified, including protocol (`http` or `https`)
|
86
|
+
and port.
|
87
|
+
|
88
|
+
[float]
|
89
|
+
[[config-secret-token]]
|
90
|
+
==== `secret_token`
|
91
|
+
|
92
|
+
[options="header"]
|
93
|
+
|============
|
94
|
+
| Environment | `Config` key | Default | Example
|
95
|
+
| `ELASTIC_APM_SECRET_TOKEN` | `secret_token` | `nil` | A random string
|
96
|
+
|============
|
97
|
+
|
98
|
+
This string is used to ensure that only your agents can send data to your APM server.
|
99
|
+
Both the agents and the APM server have to be configured with the same secret token.
|
100
|
+
One example to generate a secure secret token is:
|
101
|
+
|
102
|
+
[source,bash]
|
103
|
+
----
|
104
|
+
ruby -r securerandom -e 'print SecureRandom.uuid'
|
105
|
+
----
|
106
|
+
|
107
|
+
WARNING: Secret tokens only provide any real security if your APM server use TLS.
|
108
|
+
|
109
|
+
[float]
|
110
|
+
[[config-service-name]]
|
111
|
+
==== `service_name`
|
112
|
+
|
113
|
+
[options="header"]
|
114
|
+
|============
|
115
|
+
| Environment | `Config` key | Default | Example
|
116
|
+
| `ELASTIC_APM_SERVICE_NAME` | `service_name` | App's name | `MyApp`
|
117
|
+
|============
|
118
|
+
|
119
|
+
The name of your service.
|
120
|
+
This is used to keep all the errors and transactions of your service together and is
|
121
|
+
the primary filter in the Elastic APM user interface.
|
122
|
+
|
123
|
+
If you're using Ruby on Rails this will default to your app's name.
|
124
|
+
If you're using Sinatra it will default to the name of your app's class.
|
125
|
+
|
126
|
+
NOTE: The service name must conform to this regular expression: `^[a-zA-Z0-9 _-]+$`.
|
127
|
+
In less regexy terms: Your service name must only contain characters from the ASCII
|
128
|
+
alphabet, numbers, dashes, underscores and spaces.
|
129
|
+
|
130
|
+
[float]
|
131
|
+
[[config-service-version]]
|
132
|
+
==== `service_version`
|
133
|
+
[options="header"]
|
134
|
+
|============
|
135
|
+
| Environment | `Config` key | Default | Example
|
136
|
+
| `ELASTIC_APM_SERVICE_VERSION` | `service_version` | `git` sha | A string indicating the version of the deployed service
|
137
|
+
|============
|
138
|
+
|
139
|
+
Deployed version of your service.
|
140
|
+
Defaults to `git rev-parse --verify HEAD`.
|
141
|
+
|
142
|
+
[float]
|
143
|
+
[[config-environment]]
|
144
|
+
==== `environment`
|
145
|
+
|
146
|
+
[options="header"]
|
147
|
+
|============
|
148
|
+
| Environment | `Config` key | Default | Example
|
149
|
+
| `ELASTIC_APM_ENVIRONMENT` | `environment` | From `ENV` | `"production"`
|
150
|
+
|============
|
151
|
+
|
152
|
+
The name of the environment this service is deployed in,
|
153
|
+
e.g. "production" or "staging".
|
154
|
+
|
155
|
+
Defaults to `ENV['RAILS_ENV'] || ENV['RACK_ENV']`.
|
156
|
+
|
157
|
+
[float]
|
158
|
+
[[config-enabled-environments]]
|
159
|
+
==== `enabled-environments`
|
160
|
+
|
161
|
+
[options="header"]
|
162
|
+
|============
|
163
|
+
| Environment | `Config` key | Default
|
164
|
+
| `ELASTIC_APM_ENABLED_ENVIRONMENTS` | `enabled_environments` | `['production']`
|
165
|
+
|============
|
166
|
+
|
167
|
+
Specify which environments to enable APM in.
|
168
|
+
|
169
|
+
If the current envrironment isn't included, the agent will effectively be a _noop_
|
170
|
+
and do nothing.
|
171
|
+
So you can keep in your custom instrumentation code without the agent sending
|
172
|
+
anything nor complain.
|
173
|
+
|
174
|
+
[float]
|
175
|
+
[[config-framework-name]]
|
176
|
+
==== `framework_name`
|
177
|
+
[options="header"]
|
178
|
+
|============
|
179
|
+
| Environment | `Config` key | Default
|
180
|
+
| `ELASTIC_APM_FRAMEWORK_NAME` | `framework_name` | Depending on framework
|
181
|
+
|============
|
182
|
+
|
183
|
+
Name of the used framework.
|
184
|
+
For Rails or Sinatra, this defaults to `Ruby on Rails` and `Sinatra` respectively,
|
185
|
+
otherwise defaults to `nil`.
|
186
|
+
|
187
|
+
[float]
|
188
|
+
[[config-framework-version]]
|
189
|
+
==== `framework_version`
|
190
|
+
[options="header"]
|
191
|
+
|============
|
192
|
+
| Environment | `Config` key | Default
|
193
|
+
| `ELASTIC_APM_FRAMEWORK_VERSION` | `framework_version` | Depending on framework
|
194
|
+
|============
|
195
|
+
|
196
|
+
Version number of the used framework.
|
197
|
+
For Ruby on Rails and Sinatra, this defaults to the used version of the framework,
|
198
|
+
otherwise, the default is `nil`.
|
199
|
+
|
200
|
+
[float]
|
201
|
+
[[config-hostname]]
|
202
|
+
==== `hostname`
|
203
|
+
|
204
|
+
[options="header"]
|
205
|
+
|============
|
206
|
+
| Environment | `Config` key | Default | Example
|
207
|
+
| `ELASTIC_APM_HOSTNAME` | `hostname` | `hostname` | `app-server01.example.com`
|
208
|
+
|============
|
209
|
+
|
210
|
+
The host name to use when sending error and transaction data to the APM server.
|
211
|
+
|
212
|
+
[float]
|
213
|
+
[[config-source-lines-error-app-frames]]
|
214
|
+
==== `source_lines_error_app_frames`
|
215
|
+
[float]
|
216
|
+
[[config-source-lines-error-library-frames]]
|
217
|
+
==== `source_lines_error_library_frames`
|
218
|
+
[float]
|
219
|
+
[[config-source-lines-span-app-frames]]
|
220
|
+
==== `source_lines_span_app_frames`
|
221
|
+
[float]
|
222
|
+
[[config-source-lines-span-library-frames]]
|
223
|
+
==== `source_lines_span_library_frames`
|
224
|
+
|
225
|
+
|============
|
226
|
+
| Environment | `Config` key | Default
|
227
|
+
| `ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES` | `source_lines_error_app_frames` | `5`
|
228
|
+
| `ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES` | `source_lines_error_library_frames` | `5`
|
229
|
+
| `ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES` | `source_lines_span_app_frames` | `0`
|
230
|
+
| `ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES` | `source_lines_span_library_frames` | `0`
|
231
|
+
|============
|
232
|
+
|
233
|
+
By default, the APM agent collects source code snippets for errors.
|
234
|
+
With the above settings, you can modify how many lines of source code is collected.
|
235
|
+
|
236
|
+
We differ between errors and spans, as well as library frames and app frames.
|
237
|
+
|
238
|
+
WARNING: Especially for spans, collecting source code can have a large impact on
|
239
|
+
storage use in your Elasticsearch cluster.
|
240
|
+
|
241
|
+
[float]
|
242
|
+
[[config-span-frames-min-duration-ms]]
|
243
|
+
==== `span_frames_min_duration`
|
244
|
+
|
245
|
+
| ============
|
246
|
+
| Environment | `Config` keys | Default
|
247
|
+
| `ELASTIC_APM_SPAN_FRAMES_MIN_DURATION` | `span_frames_min_duration` | `-1`
|
248
|
+
| ============
|
249
|
+
|
250
|
+
In its default settings, the APM agent will collect a stack trace with every recorded span.
|
251
|
+
While this is very helpful to find the exact place in your code that causes the span,
|
252
|
+
collecting this stack trace does have some overhead.
|
253
|
+
|
254
|
+
With the default setting, `-1`, stack traces will be collected for all spans.
|
255
|
+
Setting it to a positive value, e.g. `5`, will limit stack trace collection to spans
|
256
|
+
with durations equal or longer than the given value in milliseconds, e.g. 5 milliseconds.
|
257
|
+
|
258
|
+
To disable stack trace collection for spans completely, set the value to 0.
|
259
|
+
|
260
|
+
[float]
|
261
|
+
[[config-max-queue-size]]
|
262
|
+
==== `max_queue_size`
|
263
|
+
|
264
|
+
|============
|
265
|
+
| Environment | `Config` key | Default
|
266
|
+
| `ELASTIC_APM_MAX_QUEUE_SIZE` | `max_queue_size` | `500`
|
267
|
+
|============
|
268
|
+
|
269
|
+
Maximum queue length of transactions before sending transactions to the APM server.
|
270
|
+
A lower value will increase the load on your APM server,
|
271
|
+
while a higher value can increase the memory pressure of your app.
|
272
|
+
A higher value also impacts the time until transactions are indexed and searchable
|
273
|
+
in Elasticsearch.
|
274
|
+
|
275
|
+
This setting is useful to limit memory consumption if you experience a sudden spike
|
276
|
+
of traffic.
|
277
|
+
|
278
|
+
[float]
|
279
|
+
[[config-flush-interval]]
|
280
|
+
==== `flush_interval`
|
281
|
+
|
282
|
+
|============
|
283
|
+
| Environment | `Config` key | Default
|
284
|
+
| `ELASTIC_APM_FLUSH_INTERVAL` | `flush_interval` | `10`
|
285
|
+
|============
|
286
|
+
|
287
|
+
Interval with which transactions should be sent to the APM server, in seconds.
|
288
|
+
A lower value will increase the load on your APM server,
|
289
|
+
while a higher value can increase the memory pressure on your app.
|
290
|
+
A higher value also impacts the time until transactions are indexed and searchable
|
291
|
+
in Elasticsearch.
|
292
|
+
|
293
|
+
[float]
|
294
|
+
[[config-transaction-sample-rate]]
|
295
|
+
==== `transaction_sample_rate`
|
296
|
+
|
297
|
+
|============
|
298
|
+
| Environment | `Config` key | Default
|
299
|
+
| `ELASTIC_APM_TRANSACTION_SAMPLE_RATE` | `transaction_sample_rate` | `1.0`
|
300
|
+
|============
|
301
|
+
|
302
|
+
By default, the agent will sample every transaction (e.g. request to your service).
|
303
|
+
To reduce overhead and storage requirements, you can set the sample rate to a value
|
304
|
+
between `0.0` and `1.0`.
|
305
|
+
We still record overall time and the result for unsampled transactions, but no
|
306
|
+
context information, tags, or spans.
|
307
|
+
|
308
|
+
[float]
|
309
|
+
[[config-transaction-max-spans]]
|
310
|
+
==== `transaction_max_spans`
|
311
|
+
|
312
|
+
|============
|
313
|
+
| Environment | `Config` key | Default
|
314
|
+
| `ELASTIC_APM_TRANSACTION_MAX_SPANS` | `transaction_max_spans` | `500`
|
315
|
+
|============
|
316
|
+
|
317
|
+
Limits the amount of spans that are recorded per transaction.
|
318
|
+
This is helpful in cases where a transaction creates a very high amount of spans
|
319
|
+
(e.g. thousands of SQL queries).
|
320
|
+
Setting an upper limit will prevent overloading the agent and the APM server with
|
321
|
+
too much work for such edge cases.
|
322
|
+
|
323
|
+
[float]
|
324
|
+
[[config-verify-server-cert]]
|
325
|
+
==== `verify_server_cert`
|
326
|
+
|============
|
327
|
+
| Environment | `Config` key | Default
|
328
|
+
| `ELASTIC_APM_VERIFY_SERVER_CERT` | `verify_server_cert` | `true`
|
329
|
+
|============
|
330
|
+
|
331
|
+
By default, the agent verifies the SSL certificate if you use an HTTPS connection to
|
332
|
+
the APM server.
|
333
|
+
Verification can be disabled by changing this setting to `false`.
|
334
|
+
|
335
|
+
[float]
|
336
|
+
[[config-disabled-spies]]
|
337
|
+
==== `disabled_spies`
|
338
|
+
|
339
|
+
[options="header"]
|
340
|
+
|============
|
341
|
+
| Environment | `Config` key | Default
|
342
|
+
| `ELASTIC_APM_DISABLED_SPIES` | `disabled_spies` | `['json']`
|
343
|
+
|============
|
344
|
+
|
345
|
+
Elastic APM automatically instruments select third party libraries.
|
346
|
+
Use this option to disable any of these.
|
347
|
+
|
348
|
+
Get an array of enabled spies with `ElasticAPM.agent.config.enabled_spies`.
|
349
|
+
|
350
|
+
[float]
|
351
|
+
[[config-custom-key-filters]]
|
352
|
+
==== `custom_key_filters`
|
353
|
+
[options="header"]
|
354
|
+
|============
|
355
|
+
| Environment | `Config` key | Default | Example
|
356
|
+
| `ELASTIC_APM_CUSTOM_KEY_FILTERS` | `custom_key_filters` | `[]` | `['MyAuthHeader']`
|
357
|
+
|============
|
358
|
+
|
359
|
+
Elastic APM strips
|
360
|
+
https://github.com/elastic/apm-agent-ruby/blob/1.x/lib/elastic_apm/filters/secrets_filter.rb[
|
361
|
+
what looks like confidential information] from the request/response headers.
|
362
|
+
Use this option to add your own custom header keys to the list of filtered keys.
|
363
|
+
|
364
|
+
|
365
|
+
[float]
|
366
|
+
[[config-filter-exception-types]]
|
367
|
+
==== `filter_exception_types`
|
368
|
+
|============
|
369
|
+
| Environment | `Config` key | Default | Example
|
370
|
+
| N/A | `filter_exception_types` | `[]` | `[MyApp::Errors::IgnoredError]`
|
371
|
+
|============
|
372
|
+
|
373
|
+
Use this to filter error tracking for specific error constants.
|
34
374
|
|
@@ -1,14 +1,93 @@
|
|
1
1
|
[[custom-instrumentation]]
|
2
2
|
=== Custom instrumentation
|
3
3
|
|
4
|
-
When installed ElasticAPM will automatically wrap your app's request/responses in
|
4
|
+
When <<introduction,installed>> and <<configuration,properly configured>> ElasticAPM will automatically wrap your app's request/responses in
|
5
|
+
transactions and report its errors.
|
6
|
+
It also wraps each background job if you use Sidekiq or DelayedJob.
|
5
7
|
|
6
|
-
But it is possible to create your own transactions as well as provide spans for any
|
8
|
+
But it is possible to create your own transactions as well as provide spans for any
|
9
|
+
automatic or custom transaction.
|
7
10
|
|
8
|
-
See <<api-transaction,`ElasticAPM.transaction`>> and <<api-span,`ElasticAPM.span`>>.
|
11
|
+
See <<api-transaction,`ElasticAPM.transaction`>> and <<api-agent-span,`ElasticAPM.span`>>.
|
9
12
|
|
10
|
-
[
|
11
|
-
|
13
|
+
[float]
|
14
|
+
==== Helpers
|
12
15
|
|
13
|
-
ElasticAPM
|
16
|
+
ElasticAPM includes some nifty helpers if you just want to instrument a regular method.
|
17
|
+
|
18
|
+
[source,ruby]
|
19
|
+
----
|
20
|
+
class ThingsController < ApplicationController
|
21
|
+
include SpanHelpers
|
22
|
+
|
23
|
+
def index
|
24
|
+
@result = do_hard_work
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def do_hard_work
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
|
33
|
+
span_method :do_hard_work # takes optional `name` and `type`
|
34
|
+
end
|
35
|
+
----
|
36
|
+
|
37
|
+
[float]
|
38
|
+
==== Custom span example
|
39
|
+
|
40
|
+
If you are already inside a Transaction (most likely) and you want to intrument
|
41
|
+
some work inside it, add a custom span:
|
42
|
+
|
43
|
+
[source,ruby]
|
44
|
+
----
|
45
|
+
class ThingsController < ApplicationController
|
46
|
+
def index
|
47
|
+
@result_of_work = ElasticAPM.span "Heavy work" do
|
48
|
+
do_the_heavy_work
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
----
|
53
|
+
|
54
|
+
[float]
|
55
|
+
==== Custom transaction example
|
56
|
+
|
57
|
+
If you are **not** inside a Transaction already (eg. outside of your common web application)
|
58
|
+
start and manage your own transactions like so:
|
59
|
+
|
60
|
+
[source,ruby]
|
61
|
+
----
|
62
|
+
class Something
|
63
|
+
def do_work
|
64
|
+
transaction = ElasticAPM.transaction 'Something#do_work'
|
65
|
+
|
66
|
+
begin
|
67
|
+
Sequel[:users] # many third party libs will be automatically instrumented
|
68
|
+
transaction.submit('success') if transaction
|
69
|
+
rescue Exception => e
|
70
|
+
ElasticAPM.report(e)
|
71
|
+
transaction.submit('error') if transaction
|
72
|
+
raise
|
73
|
+
ensure
|
74
|
+
transaction.release
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
----
|
79
|
+
|
80
|
+
**Note:** If the agent isn't started beforehand this will do nothing. See <<api-agent-start,ElasticAPM.start>>.
|
81
|
+
|
82
|
+
[[spies]]
|
83
|
+
=== Spies
|
84
|
+
|
85
|
+
[float]
|
86
|
+
==== Automatic integrations with third-party libraries
|
87
|
+
|
88
|
+
ElasticAPM has built-in integrations for some popular libraries.
|
89
|
+
Use `config.disabled_spies` to disable specific integrations.
|
90
|
+
|
91
|
+
For a list of available spies, see
|
92
|
+
https://github.com/elastic/apm-agent-ruby/blob/1.x/lib/elastic_apm/config.rb#L174-L188[config.rb].
|
14
93
|
|
@@ -1,10 +1,52 @@
|
|
1
1
|
[[getting-started-rack]]
|
2
2
|
== Getting started with Rack
|
3
3
|
|
4
|
+
Add the gem to your `Gemfile`:
|
5
|
+
|
6
|
+
[source,ruby]
|
7
|
+
----
|
8
|
+
gem 'elastic-apm'
|
9
|
+
----
|
10
|
+
|
11
|
+
Create a file `config/elastic_apm.yml`:
|
12
|
+
|
13
|
+
[source,yaml]
|
14
|
+
----
|
15
|
+
server_url: http://localhost:8100
|
16
|
+
secret_token: ''
|
17
|
+
----
|
18
|
+
|
19
|
+
Include the middleware, start (and stop) Elastic APM when booting your app:
|
20
|
+
|
4
21
|
[source,ruby]
|
5
22
|
----
|
6
23
|
# config.ru
|
7
24
|
|
25
|
+
app = lambda do |env|
|
26
|
+
[200, {'Content-Type' => 'text/plain'}, ['ok']]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Wraps all requests in transactions and reports exceptions
|
30
|
+
use ElasticAPM::Middleware
|
31
|
+
|
32
|
+
# Start an instance of the Agent
|
33
|
+
ElasticAPM.start(service_name: 'NothingButRack')
|
34
|
+
|
35
|
+
run app
|
36
|
+
|
37
|
+
# Gracefully stop the agent when process exits.
|
38
|
+
# Makes sure any pending transactions are sent.
|
39
|
+
at_exit { ElasticAPM.stop }
|
40
|
+
----
|
41
|
+
|
42
|
+
[float]
|
43
|
+
[[getting-started-sinatra]]
|
44
|
+
==== Sinatra example
|
45
|
+
|
46
|
+
[source,ruby]
|
47
|
+
----
|
48
|
+
# Example config.ru
|
49
|
+
|
8
50
|
require 'sinatra/base'
|
9
51
|
|
10
52
|
class MySinatraApp < Sinatra::Base
|
@@ -14,10 +56,7 @@ class MySinatraApp < Sinatra::Base
|
|
14
56
|
end
|
15
57
|
|
16
58
|
# Takes optional ElasticAPM::Config values
|
17
|
-
ElasticAPM.start(
|
18
|
-
app: MySinatraApp, # required
|
19
|
-
server_url: 'http://localhost:8200'
|
20
|
-
)
|
59
|
+
ElasticAPM.start(app: MySinatraApp, ...)
|
21
60
|
|
22
61
|
run MySinatraApp
|
23
62
|
|
@@ -11,4 +11,12 @@ Add the gem to your `Gemfile`:
|
|
11
11
|
gem 'elastic-apm'
|
12
12
|
----
|
13
13
|
|
14
|
+
Create a file `config/elastic_apm.yml`:
|
15
|
+
|
16
|
+
[source,yaml]
|
17
|
+
----
|
18
|
+
server_url: http://localhost:8100
|
19
|
+
secret_token: ''
|
20
|
+
----
|
21
|
+
|
14
22
|
This automatically sets up error logging and performance tracking but of course there are knobs to turn if you'd like to. See <<configuration>>.
|
data/docs/index.asciidoc
CHANGED
@@ -4,19 +4,19 @@ endif::[]
|
|
4
4
|
|
5
5
|
= APM Ruby Agent Reference (Beta)
|
6
6
|
|
7
|
+
[[introduction]]
|
7
8
|
== Introduction
|
8
9
|
|
9
10
|
The Elastic APM Ruby Agent sends performance metrics and error logs to an Elastic APM Server.
|
10
11
|
|
11
|
-
It has built-in support for <<getting-started-rails,Rails>> and other <<getting-started-rack,Rack-compatible>> applications.
|
12
|
+
It has built-in support for <<getting-started-rails,Ruby on Rails>> and other <<getting-started-rack,Rack-compatible>> applications.
|
12
13
|
|
13
14
|
This agent is one of several components you need to get started collecting APM data. See also:
|
14
15
|
|
15
16
|
* https://www.elastic.co/guide/en/apm/server/current/index.html[APM Server]
|
16
|
-
* https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html[Elasticsearch]
|
17
17
|
|
18
18
|
[[framework-support]]
|
19
|
-
The Elastic APM Ruby Agent officially supports <<getting-started-rails,Rails>> versions 4.x on onwards.
|
19
|
+
The Elastic APM Ruby Agent officially supports <<getting-started-rails,Ruby on Rails>> versions 4.x on onwards.
|
20
20
|
|
21
21
|
For Sinatra and other Rack compatible frameworks, see <<getting-started-rack,Getting started with Rack>>.
|
22
22
|
|
data/lib/elastic_apm.rb
CHANGED
data/lib/elastic_apm/agent.rb
CHANGED
@@ -30,10 +30,13 @@ module ElasticAPM
|
|
30
30
|
config = Config.new(config) unless config.is_a?(Config)
|
31
31
|
|
32
32
|
unless config.enabled_environments.include?(config.environment)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
unless config.disable_environment_warning?
|
34
|
+
puts format(
|
35
|
+
'%sNot tracking anything in "%s" env',
|
36
|
+
Log::PREFIX, config.environment
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
37
40
|
return
|
38
41
|
end
|
39
42
|
|
data/lib/elastic_apm/config.rb
CHANGED
@@ -13,9 +13,10 @@ module ElasticAPM
|
|
13
13
|
|
14
14
|
environment: ENV['RAILS_ENV'] || ENV['RACK_ENV'],
|
15
15
|
enabled_environments: %w[production],
|
16
|
+
disable_environment_warning: false,
|
16
17
|
|
17
|
-
log_path:
|
18
|
-
log_level: Logger::
|
18
|
+
log_path: nil,
|
19
|
+
log_level: Logger::DEBUG,
|
19
20
|
|
20
21
|
max_queue_size: 500,
|
21
22
|
flush_interval: 10,
|
@@ -36,6 +37,7 @@ module ElasticAPM
|
|
36
37
|
source_lines_span_app_frames: 5,
|
37
38
|
source_lines_error_library_frames: 0,
|
38
39
|
source_lines_span_library_frames: 0,
|
40
|
+
span_frames_min_duration: -1,
|
39
41
|
|
40
42
|
disabled_spies: %w[json],
|
41
43
|
|
@@ -43,6 +45,8 @@ module ElasticAPM
|
|
43
45
|
current_user_email_method: :email,
|
44
46
|
current_user_username_method: :username,
|
45
47
|
|
48
|
+
custom_key_filters: [],
|
49
|
+
|
46
50
|
view_paths: [],
|
47
51
|
root_path: Dir.pwd
|
48
52
|
}.freeze
|
@@ -51,10 +55,13 @@ module ElasticAPM
|
|
51
55
|
'ELASTIC_APM_SERVER_URL' => 'server_url',
|
52
56
|
'ELASTIC_APM_SECRET_TOKEN' => 'secret_token',
|
53
57
|
|
54
|
-
'ELASTIC_APM_SERVICE_NAME' => 'service_name',
|
55
|
-
'ELASTIC_APM_SERVICE_VERSION' => 'service_version',
|
56
58
|
'ELASTIC_APM_ENVIRONMENT' => 'environment',
|
57
59
|
'ELASTIC_APM_ENABLED_ENVIRONMENTS' => [:list, 'enabled_environments'],
|
60
|
+
'ELASTIC_APM_DISABLE_ENVIRONMENT_WARNING' =>
|
61
|
+
[:bool, 'disable_environment_warning'],
|
62
|
+
|
63
|
+
'ELASTIC_APM_SERVICE_NAME' => 'service_name',
|
64
|
+
'ELASTIC_APM_SERVICE_VERSION' => 'service_version',
|
58
65
|
'ELASTIC_APM_FRAMEWORK_NAME' => 'framework_name',
|
59
66
|
'ELASTIC_APM_FRAMEWORK_VERSION' => 'framework_version',
|
60
67
|
'ELASTIC_APM_HOSTNAME' => 'hostname',
|
@@ -67,6 +74,10 @@ module ElasticAPM
|
|
67
74
|
[:int, 'source_lines_error_library_frames'],
|
68
75
|
'ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES' =>
|
69
76
|
[:int, 'source_lines_span_library_frames'],
|
77
|
+
'ELASTIC_APM_SPAN_FRAMES_MIN_DURATION' =>
|
78
|
+
[:int, 'span_frames_min_duration'],
|
79
|
+
|
80
|
+
'ELASTIC_APM_CUSTOM_KEY_FILTERS' => [:list, 'custom_key_filters'],
|
70
81
|
|
71
82
|
'ELASTIC_APM_MAX_QUEUE_SIZE' => [:int, 'max_queue_size'],
|
72
83
|
'ELASTIC_APM_FLUSH_INTERVAL' => 'flush_interval',
|
@@ -86,6 +97,8 @@ module ElasticAPM
|
|
86
97
|
set_from_env
|
87
98
|
|
88
99
|
yield self if block_given?
|
100
|
+
|
101
|
+
build_logger unless logger
|
89
102
|
end
|
90
103
|
|
91
104
|
attr_accessor :config_file
|
@@ -93,16 +106,19 @@ module ElasticAPM
|
|
93
106
|
attr_accessor :server_url
|
94
107
|
attr_accessor :secret_token
|
95
108
|
|
109
|
+
attr_accessor :environment
|
110
|
+
attr_accessor :enabled_environments
|
111
|
+
attr_accessor :disable_environment_warning
|
112
|
+
|
96
113
|
attr_accessor :service_name
|
97
114
|
attr_accessor :service_version
|
98
|
-
attr_accessor :environment
|
99
115
|
attr_accessor :framework_name
|
100
116
|
attr_accessor :framework_version
|
101
117
|
attr_accessor :hostname
|
102
|
-
attr_accessor :enabled_environments
|
103
118
|
|
104
119
|
attr_accessor :log_path
|
105
120
|
attr_accessor :log_level
|
121
|
+
attr_accessor :logger
|
106
122
|
|
107
123
|
attr_accessor :max_queue_size
|
108
124
|
attr_accessor :flush_interval
|
@@ -123,6 +139,7 @@ module ElasticAPM
|
|
123
139
|
attr_accessor :source_lines_span_app_frames
|
124
140
|
attr_accessor :source_lines_error_library_frames
|
125
141
|
attr_accessor :source_lines_span_library_frames
|
142
|
+
attr_accessor :span_frames_min_duration
|
126
143
|
|
127
144
|
attr_accessor :disabled_spies
|
128
145
|
|
@@ -134,8 +151,9 @@ module ElasticAPM
|
|
134
151
|
attr_accessor :current_user_email_method
|
135
152
|
attr_accessor :current_user_username_method
|
136
153
|
|
137
|
-
attr_reader :
|
154
|
+
attr_reader :custom_key_filters
|
138
155
|
|
156
|
+
alias :disable_environment_warning? :disable_environment_warning
|
139
157
|
alias :verify_server_cert? :verify_server_cert
|
140
158
|
|
141
159
|
def app=(app)
|
@@ -166,8 +184,8 @@ module ElasticAPM
|
|
166
184
|
server_url.start_with?('https')
|
167
185
|
end
|
168
186
|
|
169
|
-
def
|
170
|
-
@
|
187
|
+
def custom_key_filters=(filters)
|
188
|
+
@custom_key_filters = Array(filters).map(&Regexp.method(:new))
|
171
189
|
end
|
172
190
|
|
173
191
|
# rubocop:disable Metrics/MethodLength
|
@@ -251,10 +269,11 @@ module ElasticAPM
|
|
251
269
|
self.view_paths = app.config.paths['app/views'].existent
|
252
270
|
end
|
253
271
|
|
254
|
-
def build_logger
|
255
|
-
logger = Logger.new(
|
256
|
-
logger.level =
|
257
|
-
|
272
|
+
def build_logger
|
273
|
+
logger = Logger.new(log_path == '-' ? $stdout : log_path)
|
274
|
+
logger.level = log_level
|
275
|
+
|
276
|
+
self.logger = logger
|
258
277
|
end
|
259
278
|
|
260
279
|
def format_name(str)
|
@@ -21,6 +21,7 @@ module ElasticAPM
|
|
21
21
|
|
22
22
|
def initialize(config)
|
23
23
|
@config = config
|
24
|
+
@key_filters = KEY_FILTERS + config.custom_key_filters
|
24
25
|
end
|
25
26
|
|
26
27
|
def call(payload)
|
@@ -47,7 +48,7 @@ module ElasticAPM
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def filter_key?(key)
|
50
|
-
|
51
|
+
@key_filters.any? { |regex| key =~ regex }
|
51
52
|
end
|
52
53
|
|
53
54
|
def filter_value?(value)
|
data/lib/elastic_apm/http.rb
CHANGED
data/lib/elastic_apm/span.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
require 'elastic_apm/span/context'
|
4
6
|
|
5
7
|
module ElasticAPM
|
@@ -22,11 +24,13 @@ module ElasticAPM
|
|
22
24
|
@type = type || DEFAULT_TYPE
|
23
25
|
@parent = parent
|
24
26
|
@context = context
|
27
|
+
|
25
28
|
@stacktrace = nil
|
29
|
+
@original_backtrace = nil
|
26
30
|
end
|
27
31
|
# rubocop:enable Metrics/ParameterLists
|
28
32
|
|
29
|
-
attr_accessor :name, :context, :type, :stacktrace
|
33
|
+
attr_accessor :name, :context, :type, :stacktrace, :original_backtrace
|
30
34
|
attr_reader :id, :duration, :parent, :relative_start
|
31
35
|
|
32
36
|
def start
|
@@ -38,6 +42,15 @@ module ElasticAPM
|
|
38
42
|
def done
|
39
43
|
@duration = Util.micros - @transaction.timestamp - relative_start
|
40
44
|
|
45
|
+
if original_backtrace && long_enough_for_stacktrace?
|
46
|
+
self.stacktrace =
|
47
|
+
@transaction.instrumenter.agent.stacktrace_builder.build(
|
48
|
+
original_backtrace, type: :span
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
self.original_backtrace = nil # release it
|
53
|
+
|
41
54
|
self
|
42
55
|
end
|
43
56
|
|
@@ -55,5 +68,17 @@ module ElasticAPM
|
|
55
68
|
" type:#{type.inspect}" \
|
56
69
|
'>'
|
57
70
|
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def long_enough_for_stacktrace?
|
75
|
+
min_duration = @transaction.instrumenter.config.span_frames_min_duration
|
76
|
+
|
77
|
+
case min_duration
|
78
|
+
when -1 then true
|
79
|
+
when 0 then false
|
80
|
+
else duration / 1000 >= min_duration
|
81
|
+
end
|
82
|
+
end
|
58
83
|
end
|
59
84
|
end
|
@@ -9,9 +9,16 @@ module ElasticAPM
|
|
9
9
|
__span_method_on(singleton_class, method, name, type)
|
10
10
|
end
|
11
11
|
|
12
|
+
def span_method(method, name, type)
|
13
|
+
__span_method_on(self, method, name, type)
|
14
|
+
end
|
15
|
+
|
12
16
|
private
|
13
17
|
|
14
|
-
def __span_method_on(klass, method, name, type)
|
18
|
+
def __span_method_on(klass, method, name = nil, type = nil)
|
19
|
+
name ||= method.to_s
|
20
|
+
type ||= Span::DEFAULT_TYPE
|
21
|
+
|
15
22
|
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
16
23
|
alias :"__without_apm_#{method}" :"#{method}"
|
17
24
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
module ElasticAPM
|
4
6
|
# rubocop:disable Metrics/ClassLength
|
5
7
|
# @api private
|
@@ -55,7 +57,7 @@ module ElasticAPM
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def submit(result = nil, status: nil, headers: {})
|
58
|
-
done result
|
60
|
+
done result unless duration
|
59
61
|
|
60
62
|
if status
|
61
63
|
context.response = Context::Response.new(status, headers: headers)
|
@@ -104,9 +106,8 @@ module ElasticAPM
|
|
104
106
|
span = next_span(name, type, context)
|
105
107
|
spans << span
|
106
108
|
|
107
|
-
if backtrace
|
108
|
-
span.
|
109
|
-
@instrumenter.agent.stacktrace_builder.build(backtrace, type: :span)
|
109
|
+
if backtrace && span_frames_min_duration?
|
110
|
+
span.original_backtrace = backtrace
|
110
111
|
end
|
111
112
|
|
112
113
|
span.start
|
@@ -143,6 +144,10 @@ module ElasticAPM
|
|
143
144
|
context: context
|
144
145
|
)
|
145
146
|
end
|
147
|
+
|
148
|
+
def span_frames_min_duration?
|
149
|
+
@instrumenter.agent.config.span_frames_min_duration != 0
|
150
|
+
end
|
146
151
|
end
|
147
152
|
# rubocop:enable Metrics/ClassLength
|
148
153
|
end
|
data/lib/elastic_apm/util/dig.rb
CHANGED
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.7.
|
4
|
+
version: 0.7.2
|
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-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- LICENSE
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
+
- bin/build_docs
|
30
31
|
- bin/console
|
31
32
|
- bin/setup
|
32
33
|
- bin/with_framework
|