elastic-apm 4.7.3 → 4.9.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.exclude.yml +27 -82
  3. data/.ci/.framework.yml +1 -4
  4. data/.ci/.ruby.yml +1 -1
  5. data/.ci/updatecli/values.d/apm-data-spec.yml +1 -0
  6. data/.ci/updatecli/values.d/apm-gherkin.yml +1 -0
  7. data/.ci/updatecli/values.d/apm-json-specs.yml +1 -0
  8. data/.ci/updatecli/values.d/scm.yml +10 -0
  9. data/.ci/updatecli/values.d/update-compose.yml +3 -0
  10. data/.github/CODEOWNERS +1 -0
  11. data/.github/PULL_REQUEST_TEMPLATE.md +2 -2
  12. data/.github/dependabot.yml +22 -19
  13. data/.github/workflows/README.md +1 -2
  14. data/.github/workflows/addToProject.yml +43 -12
  15. data/.github/workflows/ci.yml +6 -6
  16. data/.github/workflows/docs-build.yml +16 -0
  17. data/.github/workflows/docs-deploy.yml +16 -0
  18. data/.github/workflows/docs-preview-cleanup.yml +12 -0
  19. data/.github/workflows/github-commands-comment.yml +18 -0
  20. data/.github/workflows/microbenchmark.yml +7 -24
  21. data/.github/workflows/release.yml +40 -24
  22. data/.github/workflows/run-matrix.yml +21 -12
  23. data/.github/workflows/test-reporter.yml +4 -3
  24. data/.github/workflows/updatecli.yml +45 -13
  25. data/Dockerfile +38 -12
  26. data/Gemfile +38 -3
  27. data/bin/dev +16 -4
  28. data/bin/run-bdd +2 -2
  29. data/docker-compose.yml +12 -5
  30. data/docs/docset.yml +11 -0
  31. data/docs/reference/advanced-topics.md +18 -0
  32. data/docs/reference/api-reference.md +428 -0
  33. data/docs/reference/configuration.md +751 -0
  34. data/docs/{context.asciidoc → reference/context.md} +27 -21
  35. data/docs/reference/custom-instrumentation.md +78 -0
  36. data/docs/{getting-started-rack.asciidoc → reference/getting-started-rack.md} +27 -30
  37. data/docs/reference/getting-started-rails.md +33 -0
  38. data/docs/reference/graphql.md +27 -0
  39. data/docs/reference/index.md +33 -0
  40. data/docs/{logs.asciidoc → reference/logs.md} +45 -57
  41. data/docs/reference/metrics.md +205 -0
  42. data/docs/reference/opentracing-api.md +76 -0
  43. data/docs/reference/performance-tuning.md +77 -0
  44. data/docs/reference/set-up-apm-ruby-agent.md +22 -0
  45. data/docs/reference/supported-technologies.md +134 -0
  46. data/docs/reference/toc.yml +24 -0
  47. data/docs/reference/upgrading.md +25 -0
  48. data/docs/release-notes/index.md +182 -0
  49. data/docs/release-notes/known-issues.md +29 -0
  50. data/docs/release-notes/toc.yml +3 -0
  51. data/elastic-apm.gemspec +2 -2
  52. data/lib/elastic_apm/central_config.rb +1 -1
  53. data/lib/elastic_apm/config/round_float_hash_value.rb +35 -0
  54. data/lib/elastic_apm/config.rb +2 -0
  55. data/lib/elastic_apm/context_builder.rb +5 -2
  56. data/lib/elastic_apm/instrumenter.rb +23 -3
  57. data/lib/elastic_apm/spies/http.rb +1 -1
  58. data/lib/elastic_apm/spies/sidekiq.rb +2 -1
  59. data/lib/elastic_apm/stacktrace_builder.rb +3 -3
  60. data/lib/elastic_apm/transaction.rb +11 -4
  61. data/lib/elastic_apm/version.rb +1 -1
  62. data/updatecli-compose.yaml +23 -0
  63. metadata +49 -37
  64. data/.ci/snapshoty.yml +0 -33
  65. data/.ci/updatecli/updatecli.d/update-gherkin-specs.yml +0 -84
  66. data/.ci/updatecli/updatecli.d/update-json-specs.yml +0 -84
  67. data/.ci/updatecli/updatecli.d/update-specs.yml +0 -86
  68. data/.ci/updatecli/values.yml +0 -14
  69. data/.github/workflows/coverage-reporter.yml +0 -34
  70. data/.github/workflows/opentelemetry.yml +0 -22
  71. data/.github/workflows/snapshoty.yml +0 -35
  72. data/CHANGELOG.asciidoc +0 -990
  73. data/SECURITY.md +0 -7
  74. data/docs/advanced.asciidoc +0 -14
  75. data/docs/api.asciidoc +0 -487
  76. data/docs/configuration.asciidoc +0 -889
  77. data/docs/custom-instrumentation.asciidoc +0 -80
  78. data/docs/debugging.asciidoc +0 -44
  79. data/docs/getting-started-rails.asciidoc +0 -30
  80. data/docs/graphql.asciidoc +0 -23
  81. data/docs/index.asciidoc +0 -38
  82. data/docs/introduction.asciidoc +0 -36
  83. data/docs/metrics.asciidoc +0 -235
  84. data/docs/opentracing.asciidoc +0 -94
  85. data/docs/performance-tuning.asciidoc +0 -106
  86. data/docs/redirects.asciidoc +0 -9
  87. data/docs/release-notes.asciidoc +0 -15
  88. data/docs/set-up.asciidoc +0 -19
  89. data/docs/supported-technologies.asciidoc +0 -157
  90. data/docs/upgrading.asciidoc +0 -18
  91. /data/docs/{images → reference/images}/dynamic-config.svg +0 -0
@@ -0,0 +1,428 @@
1
+ ---
2
+ mapped_pages:
3
+ - https://www.elastic.co/guide/en/apm/agent/ruby/current/api.html
4
+ applies_to:
5
+ stack:
6
+ serverless:
7
+ observability:
8
+ product:
9
+ apm_agent_ruby: ga
10
+ ---
11
+
12
+ # API reference [api]
13
+
14
+ Although most usage is covered automatically, Elastic APM also has a public API that allows custom usage.
15
+
16
+
17
+ ## Agent life cycle [agent-life-cycle]
18
+
19
+ Controlling when the agent starts and stops.
20
+
21
+
22
+ ### `ElasticAPM.start` [api-agent-start]
23
+
24
+ To create and start an ElasticAPM agent use `ElasticAPM.start`:
25
+
26
+ ```ruby
27
+ ElasticAPM.start(server_url: 'http://localhost:8200')
28
+ ```
29
+
30
+ * `config`: An optional hash or `ElasticAPM::Config` instance with configuration options. See [Configuration](/reference/configuration.md).
31
+
32
+ If you are using [Ruby on Rails](/reference/getting-started-rails.md) this is done automatically for you. If you choose not to require the `elastic_apm` gem and instead want to start the agent and hook into Rails manually, see [hooking into Rails explicitly](#rails-start). If you’re not using Rails, see [Getting started with Rack](/reference/getting-started-rack.md).
33
+
34
+
35
+ ### `ElasticAPM.stop` [api-agent-stop]
36
+
37
+ Stop the currently running agent. Use this inside `at_exit` in your [Rack app](/reference/getting-started-rack.md) to gracefully shut down.
38
+
39
+
40
+ ### `ElasticAPM.restart` [api-agent-restart]
41
+
42
+ If the agent is already running, this method will stop and start the agent.
43
+
44
+ If the agent is not already running, this method will start the agent.
45
+
46
+ A config can be passed to the method that will be used to start the agent. If the agent is already running and no config is passed to the `#restart` method, the running agent’s config will be used.
47
+
48
+
49
+ ### `ElasticAPM.running?` [api-agent-running]
50
+
51
+ Returns whether the ElasticAPM Agent is currently running.
52
+
53
+
54
+ ### `ElasticAPM.agent` [api-agent-agent]
55
+
56
+ Returns the currently running agent or nil.
57
+
58
+
59
+ ## Instrumentation [_instrumentation]
60
+
61
+
62
+ ### `ElasticAPM.current_transaction` [api-agent-current-transaction]
63
+
64
+ Returns the current `ElasticAPM::Transaction` or nil.
65
+
66
+
67
+ ### `ElasticAPM.start_transaction` [api-agent-start_transaction]
68
+
69
+ Start a *transaction* eg. an incoming web request or a background job.
70
+
71
+ ```ruby
72
+ # call with block
73
+ ElasticAPM.start_transaction('Name')
74
+ do_work # ...
75
+ ElasticAPM.end_transaction('result')
76
+ ```
77
+
78
+ Arguments:
79
+
80
+ * `name`: A name for your transaction. Transactions are grouped by name. **Required**.
81
+ * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
82
+ * `context:`: An optional [Context](#api-context) used to enrich the transaction with information about the current request.
83
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
84
+
85
+ Returns the transaction.
86
+
87
+
88
+ ### `ElasticAPM.end_transaction` [api-agent-end_transaction]
89
+
90
+ Ends the currently running transaction.
91
+
92
+ Arguments:
93
+
94
+ * `result`: A `String` result of the transaction, eg. `'success'`.
95
+
96
+
97
+ ### `ElasticAPM.with_transaction` [api-agent-with_transaction]
98
+
99
+ Wrap a block in a Transaction, starting and ending around the block
100
+
101
+ ```ruby
102
+ ElasticAPM.with_transaction 'Do things' do |transaction|
103
+ do_work # ...
104
+
105
+ transaction.result = 'success'
106
+ end
107
+ ```
108
+
109
+ Arguments:
110
+
111
+ * `name`: A name for your transaction. Transactions are grouped by name. **Required**.
112
+ * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
113
+ * `context:`: An optional [Context](#api-context) used to enrich the transaction with information about the current request.
114
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
115
+ * `&block`: A block to wrap. Optionally yields the transaction.
116
+
117
+ Returns the return value of the given block.
118
+
119
+
120
+ ### `ElasticAPM.start_span` [api-agent-start_span]
121
+
122
+ Start a new span.
123
+
124
+ ```ruby
125
+ ElasticAPM.with_transaction 'Do things' do
126
+ ElasticAPM.start_span 'Do one of the things'
127
+ Database.query # ...
128
+ ElasticAPM.end_span
129
+ end
130
+ ```
131
+
132
+ Arguments:
133
+
134
+ * `name`: A name for your span. **Required**.
135
+ * `type`: The type of span eg. `db`.
136
+ * `subtype`: The subtype of span eg. `postgresql`.
137
+ * `action`: The action type of span eg. `connect` or `query`.
138
+ * `context`: An instance of `Span::Context`.
139
+ * `include_stacktrace`: Whether or not to collect a Stacktrace.
140
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
141
+ * `parent:`: An optional parent transaction or span. Relevant when the span is created in another thread.
142
+ * `sync:`: An boolean to indicate whether the span is created synchronously or not.
143
+ * `&block`: An optional block to wrap with the span. The block is passed the span as an optional argument.
144
+
145
+ Returns the created span.
146
+
147
+ If you’d like to create an asynchronous span, you have to pass the parent `Span` or `Transaction` to the `start_span` method. You can also set the `sync` flag to `false`, if you’d like the span to be marked as asynchronous. This has no effect other than being queryable in Elasticsearch.
148
+
149
+ ```ruby
150
+ transaction = ElasticAPM.current_transaction # or start one with `.start_transaction`
151
+ Thread.new do
152
+ ElasticAPM.start_span(
153
+ 'job 1',
154
+ parent: transaction,
155
+ sync: false
156
+ ) { Worker.perform }
157
+ ElasticAPM.end_span
158
+ end
159
+ ```
160
+
161
+
162
+ ### `ElasticAPM.end_span` [api-agent-end_span]
163
+
164
+ Ends the currently running span.
165
+
166
+
167
+ ### `ElasticAPM.with_span` [api-agent-with_span]
168
+
169
+ Wraps a block in a Span.
170
+
171
+ Arguments:
172
+
173
+ * `name`: A name for your span. **Required**.
174
+ * `type`: The type of span eg. `db`.
175
+ * `subtype`: The subtype of span eg. `postgresql`.
176
+ * `action`: The action type of span eg. `connect` or `query`.
177
+ * `context`: An instance of `Span::Context`.
178
+ * `include_stacktrace`: Whether or not to collect a Stacktrace.
179
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
180
+ * `parent:`: An optional parent transaction or span. Relevant when the span is created in another thread.
181
+ * `sync:`: An boolean to indicate whether the span is created synchronously or not.
182
+ * `&block`: An optional block to wrap with the span. The block is passed the span as an optional argument.
183
+
184
+ Returns the return value of the given block.
185
+
186
+ If you’d like to create an asynchronous span, you have to pass the parent `Span` or `Transaction` to the `with_span` method. You can also set the `sync` flag to `false`, if you’d like the span to be marked as asynchronous.
187
+
188
+ ```ruby
189
+ transaction = ElasticAPM.current_transaction # or start one with `.start_transaction`
190
+ Thread.new do
191
+ ElasticAPM.with_span(
192
+ 'job 1',
193
+ parent: transaction,
194
+ sync: false
195
+ ) { Worker.perform }
196
+ end
197
+ ```
198
+
199
+
200
+ ### `ElasticAPM.build_context` [api-agent-build-context]
201
+
202
+ Build a new *Context* from a Rack `env`.
203
+
204
+ A context provides information about the current request, response, user and more.
205
+
206
+ Arguments:
207
+
208
+ * `rack_env`: An instance of Rack::Env
209
+ * `for_type`: Symbol representing type of event, eg. `:transaction` or `error`
210
+
211
+ Returns the built context.
212
+
213
+
214
+ ## Rails [rails-start]
215
+
216
+ Start the agent and hook into Rails manually. This is useful if you skip requiring the gem and using the `Railtie`.
217
+
218
+ ```ruby
219
+ ElasticAPM::Rails.start(server_url: 'http://localhost:8200')
220
+ ```
221
+
222
+
223
+ ## Sinatra [sinatra-start]
224
+
225
+ Start the agent and hook into Sinatra.
226
+
227
+ ```ruby
228
+ ElasticAPM::Sinatra.start(MySinatraApp, server_url: 'http://localhost:8200')
229
+ ```
230
+
231
+
232
+ ## Grape [grape-start]
233
+
234
+ Start the agent and hook into Grape.
235
+
236
+ ```ruby
237
+ ElasticAPM::Grape.start(MyGrapeApp, server_url: 'http://localhost:8200')
238
+ ```
239
+
240
+
241
+ ## Errors [_errors]
242
+
243
+
244
+ ### `ElasticAPM.report` [api-agent-report]
245
+
246
+ Send an `Exception` to Elastic APM.
247
+
248
+ If reported inside a transaction, the context from that will be added.
249
+
250
+ ```ruby
251
+ begin
252
+ do_a_thing_and_fail
253
+ rescue Exception => e
254
+ ElasticAPM.report(e)
255
+ end
256
+ ```
257
+
258
+ Arguments:
259
+
260
+ * `exception`: An instance of `Exception`. **Required**.
261
+ * `handled`: Whether the error was *handled* eg. wasn’t rescued and was represented to the user. Default: `true`.
262
+
263
+ Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
264
+
265
+
266
+ ### `ElasticAPM.report_message` [api-agent-report-message]
267
+
268
+ Send a custom message to Elastic APM.
269
+
270
+ If reported inside a transaction, the context from that will be added.
271
+
272
+ ```ruby
273
+ ElasticAPM.report_message('This should probably never happen?!')
274
+ ```
275
+
276
+ Arguments:
277
+
278
+ * `message`: A custom error string. **Required**.
279
+
280
+ Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
281
+
282
+
283
+ ## Context [api-context]
284
+
285
+
286
+ ### `ElasticAPM.set_label` [api-agent-set-label]
287
+
288
+ Add a label to the current transaction. Labels are basic key-value pairs that are indexed in your Elasticsearch database and therefore searchable. The value can be a string, nil, numeric or boolean.
289
+
290
+ ::::{tip}
291
+ Before using custom labels, ensure you understand the different types of [metadata](docs-content://solutions/observability/apps/metadata.md) that are available.
292
+ ::::
293
+
294
+
295
+ ```ruby
296
+ before_action do
297
+ ElasticAPM.set_label(:company_id, current_user.company.id)
298
+ end
299
+ ```
300
+
301
+ Arguments:
302
+
303
+ * `key`: A string key. Note that `.`, `*` or `"` will be converted to `_`.
304
+ * `value`: A value.
305
+
306
+ Returns the set `value`.
307
+
308
+ ::::{warning}
309
+ Be aware that labels are indexed in Elasticsearch. Using too many unique keys will result in **[Mapping explosion](https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion)**.
310
+ ::::
311
+
312
+
313
+
314
+ ### `ElasticAPM.set_custom_context` [api-agent-set-custom-context]
315
+
316
+ Add custom context to the current transaction. Use this to further specify a context that will help you track or diagnose what’s going on inside your app.
317
+
318
+ ::::{tip}
319
+ Before using custom context, ensure you understand the different types of [metadata](docs-content://solutions/observability/apps/metadata.md) that are available.
320
+ ::::
321
+
322
+
323
+ If called several times during a transaction the custom context will be destructively merged with `merge!`.
324
+
325
+ ```ruby
326
+ before_action do
327
+ ElasticAPM.set_custom_context(company: current_user.company.to_h)
328
+ end
329
+ ```
330
+
331
+ Arguments:
332
+
333
+ * `context`: A hash of JSON-compatible key-values. Can be nested.
334
+
335
+ Returns current custom context.
336
+
337
+
338
+ ### `ElasticAPM.set_user` [api-agent-set-user]
339
+
340
+ Add the current user to the current transaction’s context.
341
+
342
+ Arguments:
343
+
344
+ * `user`: An object representing the user
345
+
346
+ Returns the given user
347
+
348
+
349
+ ## Data [_data]
350
+
351
+
352
+ ### `ElasticAPM.add_filter` [api-agent-add-filter]
353
+
354
+ Provide a filter to transform payloads before sending.
355
+
356
+ Arguments:
357
+
358
+ * `key`: A unique key identifying the filter
359
+ * `callable`: An object or proc (responds to `.call(payload)`)
360
+
361
+ Return the altered payload.
362
+
363
+ If `nil` is returned all subsequent filters will be skipped and the post request cancelled.
364
+
365
+ Example:
366
+
367
+ ```ruby
368
+ ElasticAPM.add_filter(:filter_pings) do |payload|
369
+ payload[:transactions]&.reject! do |t|
370
+ t[:name] == 'PingsController#index'
371
+ end
372
+ payload
373
+ end
374
+ ```
375
+
376
+
377
+ ## Transaction [api-transaction]
378
+
379
+ `ElasticAPM.transaction` returns a `Transaction` (if the agent is running).
380
+
381
+
382
+ ### Properties [_properties]
383
+
384
+ * `name`: String
385
+ * `type`: String
386
+ * `result`: String
387
+ * `outcome`: String (*unknown*, *success*, *failure*, nil)
388
+ * `trace_id`: String (readonly)
389
+
390
+
391
+ ### `#sampled?` [api-transaction-sampled_]
392
+
393
+ Whether the transaction is *sampled* eg. it includes stacktraces for its spans.
394
+
395
+
396
+ ### `#ensure_parent_id` [api-transaction-ensure_parent_id]
397
+
398
+ If the transaction does not have a parent-ID yet, calling this method generates a new ID, sets it as the parent-ID of this transaction, and returns it as a `String`.
399
+
400
+ This enables the correlation of the spans the JavaScript Real User Monitoring (RUM) agent creates for the initial page load with the transaction of the backend service.
401
+
402
+ If your service generates the HTML page dynamically, initializing the JavaScript RUM agent with the value of this method allows analyzing the time spent in the browser vs in the backend services.
403
+
404
+ To enable the JavaScript RUM agent, initialize the RUM agent with the Ruby agent’s current transaction:
405
+
406
+ ```html
407
+ <script src="elastic-apm-js-base/dist/bundles/elastic-apm-js-base.umd.min.js"></script>
408
+ <script>
409
+ var elasticApm = initApm({
410
+ serviceName: '',
411
+ serverUrl: 'http://localhost:8200',
412
+ pageLoadTraceId: "<%= ElasticAPM.current_transaction&.trace_id %>",
413
+ pageLoadSpanId: "<%= ElasticAPM.current_transaction&.ensure_parent_id %>",
414
+ pageLoadSampled: <%= ElasticAPM.current_transaction&.sampled? %>
415
+ })
416
+ </script>
417
+ ```
418
+
419
+ See the [JavaScript RUM agent documentation](apm-agent-rum-js://reference/index.md) for more information.
420
+
421
+
422
+ ## Span [api-span]
423
+
424
+
425
+ ### Properties [_properties_2]
426
+
427
+ * `name`: String
428
+ * `type`: String