elastic-apm 4.7.3 → 4.8.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.exclude.yml +21 -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/PULL_REQUEST_TEMPLATE.md +2 -2
  11. data/.github/dependabot.yml +24 -19
  12. data/.github/workflows/README.md +1 -2
  13. data/.github/workflows/addToProject.yml +16 -2
  14. data/.github/workflows/ci.yml +6 -6
  15. data/.github/workflows/docs-build.yml +19 -0
  16. data/.github/workflows/docs-cleanup.yml +14 -0
  17. data/.github/workflows/github-commands-comment.yml +38 -0
  18. data/.github/workflows/microbenchmark.yml +7 -24
  19. data/.github/workflows/release.yml +39 -24
  20. data/.github/workflows/run-matrix.yml +21 -12
  21. data/.github/workflows/test-reporter.yml +4 -3
  22. data/.github/workflows/updatecli.yml +45 -13
  23. data/Gemfile +13 -0
  24. data/bin/dev +2 -2
  25. data/docs/docset.yml +9 -0
  26. data/docs/reference/advanced-topics.md +12 -0
  27. data/docs/reference/api-reference.md +422 -0
  28. data/docs/reference/configuration.md +734 -0
  29. data/docs/{context.asciidoc → reference/context.md} +21 -21
  30. data/docs/reference/custom-instrumentation.md +72 -0
  31. data/docs/{getting-started-rack.asciidoc → reference/getting-started-rack.md} +20 -29
  32. data/docs/reference/getting-started-rails.md +27 -0
  33. data/docs/reference/graphql.md +21 -0
  34. data/docs/reference/index.md +24 -0
  35. data/docs/{logs.asciidoc → reference/logs.md} +38 -56
  36. data/docs/reference/metrics.md +199 -0
  37. data/docs/reference/opentracing-api.md +70 -0
  38. data/docs/reference/performance-tuning.md +71 -0
  39. data/docs/reference/set-up-apm-ruby-agent.md +16 -0
  40. data/docs/reference/supported-technologies.md +128 -0
  41. data/docs/reference/toc.yml +22 -0
  42. data/docs/reference/upgrading.md +19 -0
  43. data/docs/release-notes/index.md +166 -0
  44. data/docs/release-notes/known-issues.md +24 -0
  45. data/docs/release-notes/toc.yml +3 -0
  46. data/lib/elastic_apm/context_builder.rb +5 -2
  47. data/lib/elastic_apm/spies/sidekiq.rb +2 -1
  48. data/lib/elastic_apm/stacktrace_builder.rb +3 -3
  49. data/lib/elastic_apm/version.rb +1 -1
  50. data/updatecli-compose.yaml +23 -0
  51. metadata +37 -36
  52. data/.ci/snapshoty.yml +0 -33
  53. data/.ci/updatecli/updatecli.d/update-gherkin-specs.yml +0 -84
  54. data/.ci/updatecli/updatecli.d/update-json-specs.yml +0 -84
  55. data/.ci/updatecli/updatecli.d/update-specs.yml +0 -86
  56. data/.ci/updatecli/values.yml +0 -14
  57. data/.github/workflows/coverage-reporter.yml +0 -34
  58. data/.github/workflows/opentelemetry.yml +0 -22
  59. data/.github/workflows/snapshoty.yml +0 -35
  60. data/CHANGELOG.asciidoc +0 -990
  61. data/docs/advanced.asciidoc +0 -14
  62. data/docs/api.asciidoc +0 -487
  63. data/docs/configuration.asciidoc +0 -889
  64. data/docs/custom-instrumentation.asciidoc +0 -80
  65. data/docs/debugging.asciidoc +0 -44
  66. data/docs/getting-started-rails.asciidoc +0 -30
  67. data/docs/graphql.asciidoc +0 -23
  68. data/docs/index.asciidoc +0 -38
  69. data/docs/introduction.asciidoc +0 -36
  70. data/docs/metrics.asciidoc +0 -235
  71. data/docs/opentracing.asciidoc +0 -94
  72. data/docs/performance-tuning.asciidoc +0 -106
  73. data/docs/redirects.asciidoc +0 -9
  74. data/docs/release-notes.asciidoc +0 -15
  75. data/docs/set-up.asciidoc +0 -19
  76. data/docs/supported-technologies.asciidoc +0 -157
  77. data/docs/upgrading.asciidoc +0 -18
  78. /data/docs/{images → reference/images}/dynamic-config.svg +0 -0
@@ -24,13 +24,13 @@ jobs:
24
24
  outputs:
25
25
  matrix: ${{ steps.generate.outputs.matrix }}
26
26
  steps:
27
- - uses: actions/checkout@v3
27
+ - uses: actions/checkout@v4
28
28
  - id: generate
29
- uses: elastic/apm-pipeline-library/.github/actions/version-framework@current
29
+ uses: elastic/oblt-actions/version-framework@v1
30
30
  with:
31
- versionsFile: ${{ inputs.versionsFile }}
32
- frameworksFile: ${{ inputs.frameworksFile }}
33
- excludedFile: ${{ inputs.excludedFile }}
31
+ versions-file: ${{ inputs.versionsFile }}
32
+ frameworks-file: ${{ inputs.frameworksFile }}
33
+ excluded-file: ${{ inputs.excludedFile }}
34
34
  test:
35
35
  needs:
36
36
  - create-test-matrix
@@ -40,20 +40,29 @@ jobs:
40
40
  max-parallel: 20
41
41
  matrix: ${{ fromJSON(needs.create-test-matrix.outputs.matrix) }}
42
42
  steps:
43
- - uses: actions/checkout@v3
43
+ - uses: actions/checkout@v4
44
44
  - name: Run BDD tests
45
45
  run: ./spec/scripts/features.sh ${{ matrix.version }}
46
46
  - name: Run test
47
47
  run: ./spec/scripts/spec.sh ${{ matrix.version }} ${{ matrix.framework }}
48
48
  env:
49
49
  JUNIT_PREFIX: ${{ matrix.version }}-${{ matrix.framework }}
50
+
50
51
  - if: success() || failure()
51
- uses: actions/upload-artifact@v3
52
+ id: normalize-junit
53
+ uses: actions/github-script@v7
52
54
  with:
53
- name: test-results
54
- path: "**/spec/junit-reports/**/*ruby-agent-junit.xml"
55
+ result-encoding: string
56
+ script: |
57
+ function normalizeName(name) {
58
+ return name.replace(/["/:<>|*?\\]/g, '-')
59
+ }
60
+ const framework = normalizeName('${{ matrix.framework }}')
61
+ const version = normalizeName('${{ matrix.version }}')
62
+ return `${version}-${framework}`
55
63
  - if: success() || failure()
56
- uses: actions/upload-artifact@v3
64
+ name: Upload JUnit Test Results
65
+ uses: actions/upload-artifact@v4
57
66
  with:
58
- name: coverage
59
- path: "coverage/"
67
+ name: test-results-${{ steps.normalize-junit.outputs.result }}
68
+ path: "**/spec/junit-reports/**/*ruby-agent-junit.xml"
@@ -10,15 +10,16 @@ on:
10
10
 
11
11
  permissions:
12
12
  contents: read
13
+ actions: read
13
14
  checks: write
14
15
 
15
16
  jobs:
16
17
  report:
17
18
  runs-on: ubuntu-latest
18
19
  steps:
19
- - uses: elastic/apm-pipeline-library/.github/actions/test-report@current
20
+ - uses: elastic/oblt-actions/test-report@v1
20
21
  with:
21
- artifact: test-results
22
- name: test-report
22
+ artifact: /test-results(.*)/
23
+ name: 'Test Report $1'
23
24
  path: "**/*ruby-agent-junit.xml"
24
25
  reporter: java-junit
@@ -9,21 +9,53 @@ permissions:
9
9
  contents: read
10
10
 
11
11
  jobs:
12
- bump:
12
+ compose:
13
13
  runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ packages: read
14
17
  steps:
15
- - uses: actions/checkout@v3
16
- - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Get token
21
+ id: get_token
22
+ uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
23
+ with:
24
+ app_id: ${{ secrets.OBS_AUTOMATION_APP_ID }}
25
+ private_key: ${{ secrets.OBS_AUTOMATION_APP_PEM }}
26
+ permissions: >-
27
+ {
28
+ "contents": "write",
29
+ "pull_requests": "write"
30
+ }
31
+
32
+ - uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
33
+ with:
34
+ registry: ghcr.io
35
+ username: ${{ github.actor }}
36
+ password: ${{ secrets.GITHUB_TOKEN }}
37
+
38
+ - uses: elastic/oblt-actions/updatecli/run@v1
39
+ with:
40
+ command: --experimental compose diff
41
+ # TODO: update to the latest version so the policies can work as expected.
42
+ # latest changes in the policies require to use the dependson feature.
43
+ version: "v0.88.0"
44
+ env:
45
+ GITHUB_TOKEN: ${{ steps.get_token.outputs.token }}
46
+
47
+ - uses: elastic/oblt-actions/updatecli/run@v1
17
48
  with:
18
- vaultUrl: ${{ secrets.VAULT_ADDR }}
19
- vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
20
- vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
21
- pipeline: .ci/updatecli/updatecli.d
22
- values: .ci/updatecli/values.yml
49
+ command: --experimental compose apply
50
+ # TODO: update to the latest version so the policies can work as expected.
51
+ # latest changes in the policies require to use the dependson feature.
52
+ version: "v0.88.0"
53
+ env:
54
+ GITHUB_TOKEN: ${{ steps.get_token.outputs.token }}
55
+
23
56
  - if: failure()
24
- uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
57
+ uses: elastic/oblt-actions/slack/send@v1
25
58
  with:
26
- vaultUrl: ${{ secrets.VAULT_ADDR }}
27
- vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
28
- vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
29
- slackChannel: "#apm-agent-ruby"
59
+ bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
60
+ channel-id: "#apm-agent-ruby"
61
+ message: ":traffic_cone: updatecli failed for `${{ github.repository }}@${{ github.ref_name }}`, @robots-ci please look what's going on <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>"
data/Gemfile CHANGED
@@ -91,6 +91,10 @@ frameworks_versions.each do |framework, version|
91
91
  gem 'net-smtp', require: false
92
92
  end
93
93
 
94
+ if framework =='rails' && RUBY_VERSION >= '3.4' && ['4.2', '5.2', '6.1'].include?(version)
95
+ gem 'mutex_m'
96
+ end
97
+
94
98
  case version
95
99
  when 'master' # grape
96
100
  gem framework, github: GITHUB_REPOS.fetch(framework)
@@ -103,6 +107,11 @@ frameworks_versions.each do |framework, version|
103
107
  end
104
108
  end
105
109
 
110
+ # Handle Rack::Auth::Digest being removed in rack 3.1, grape requires it
111
+ if frameworks_versions.key?('grape')
112
+ gem 'rack', '~> 3.0.0'
113
+ end
114
+
106
115
  if frameworks_versions.key?('rails')
107
116
  unless /^(main|6)/.match?(frameworks_versions['rails'])
108
117
  gem 'delayed_job', require: nil
@@ -125,8 +134,12 @@ if RUBY_PLATFORM == 'java'
125
134
  end
126
135
  elsif frameworks_versions['rails'] =~ /^(4|5)/
127
136
  gem 'sqlite3', '~> 1.3.6'
137
+ elsif frameworks_versions['rails'] =~ /^(6|7)/
138
+ gem 'sqlite3', '~> 1.4'
128
139
  elsif RUBY_VERSION < '2.7'
129
140
  gem 'sqlite3', '~> 1.4.4'
141
+ elsif RUBY_VERSION < '3.0'
142
+ gem 'sqlite3', '~> 1.3.6'
130
143
  else
131
144
  gem 'sqlite3'
132
145
  end
data/bin/dev CHANGED
@@ -40,7 +40,7 @@ def run(cmd)
40
40
  end
41
41
 
42
42
  unless options[:skip_build]
43
- run 'docker-compose build ' \
43
+ run 'docker compose build ' \
44
44
  " --build-arg RUBY_IMAGE=#{RUBY_IMAGE}" \
45
45
  " --build-arg USER_ID_GROUP=#{USER_ID_GROUP}" \
46
46
  " --build-arg FRAMEWORKS=#{FRAMEWORKS}" \
@@ -48,7 +48,7 @@ unless options[:skip_build]
48
48
  exit $?.exitstatus unless $?.success?
49
49
  end
50
50
 
51
- run 'docker-compose run' \
51
+ run 'docker compose run' \
52
52
  " -u #{USER_ID_GROUP}" \
53
53
  ' --rm' \
54
54
  " specs #{ARGV.join}"
data/docs/docset.yml ADDED
@@ -0,0 +1,9 @@
1
+ project: 'APM Ruby agent docs'
2
+ cross_links:
3
+ - apm-agent-rum-js
4
+ - docs-content
5
+ - ecs-logging
6
+ - ecs-logging-ruby
7
+ toc:
8
+ - toc: reference
9
+ - toc: release-notes
@@ -0,0 +1,12 @@
1
+ ---
2
+ mapped_pages:
3
+ - https://www.elastic.co/guide/en/apm/agent/ruby/current/advanced.html
4
+ ---
5
+
6
+ # Advanced topics [advanced]
7
+
8
+ * [Adding additional context](/reference/context.md)
9
+ * [Custom instrumentation](/reference/custom-instrumentation.md)
10
+
11
+
12
+
@@ -0,0 +1,422 @@
1
+ ---
2
+ mapped_pages:
3
+ - https://www.elastic.co/guide/en/apm/agent/ruby/current/api.html
4
+ ---
5
+
6
+ # API reference [api]
7
+
8
+ Although most usage is covered automatically, Elastic APM also has a public API that allows custom usage.
9
+
10
+
11
+ ## Agent life cycle [agent-life-cycle]
12
+
13
+ Controlling when the agent starts and stops.
14
+
15
+
16
+ ### `ElasticAPM.start` [api-agent-start]
17
+
18
+ To create and start an ElasticAPM agent use `ElasticAPM.start`:
19
+
20
+ ```ruby
21
+ ElasticAPM.start(server_url: 'http://localhost:8200')
22
+ ```
23
+
24
+ * `config`: An optional hash or `ElasticAPM::Config` instance with configuration options. See [Configuration](/reference/configuration.md).
25
+
26
+ 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).
27
+
28
+
29
+ ### `ElasticAPM.stop` [api-agent-stop]
30
+
31
+ Stop the currently running agent. Use this inside `at_exit` in your [Rack app](/reference/getting-started-rack.md) to gracefully shut down.
32
+
33
+
34
+ ### `ElasticAPM.restart` [api-agent-restart]
35
+
36
+ If the agent is already running, this method will stop and start the agent.
37
+
38
+ If the agent is not already running, this method will start the agent.
39
+
40
+ 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.
41
+
42
+
43
+ ### `ElasticAPM.running?` [api-agent-running]
44
+
45
+ Returns whether the ElasticAPM Agent is currently running.
46
+
47
+
48
+ ### `ElasticAPM.agent` [api-agent-agent]
49
+
50
+ Returns the currently running agent or nil.
51
+
52
+
53
+ ## Instrumentation [_instrumentation]
54
+
55
+
56
+ ### `ElasticAPM.current_transaction` [api-agent-current-transaction]
57
+
58
+ Returns the current `ElasticAPM::Transaction` or nil.
59
+
60
+
61
+ ### `ElasticAPM.start_transaction` [api-agent-start_transaction]
62
+
63
+ Start a *transaction* eg. an incoming web request or a background job.
64
+
65
+ ```ruby
66
+ # call with block
67
+ ElasticAPM.start_transaction('Name')
68
+ do_work # ...
69
+ ElasticAPM.end_transaction('result')
70
+ ```
71
+
72
+ Arguments:
73
+
74
+ * `name`: A name for your transaction. Transactions are grouped by name. **Required**.
75
+ * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
76
+ * `context:`: An optional [Context](#api-context) used to enrich the transaction with information about the current request.
77
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
78
+
79
+ Returns the transaction.
80
+
81
+
82
+ ### `ElasticAPM.end_transaction` [api-agent-end_transaction]
83
+
84
+ Ends the currently running transaction.
85
+
86
+ Arguments:
87
+
88
+ * `result`: A `String` result of the transaction, eg. `'success'`.
89
+
90
+
91
+ ### `ElasticAPM.with_transaction` [api-agent-with_transaction]
92
+
93
+ Wrap a block in a Transaction, starting and ending around the block
94
+
95
+ ```ruby
96
+ ElasticAPM.with_transaction 'Do things' do |transaction|
97
+ do_work # ...
98
+
99
+ transaction.result = 'success'
100
+ end
101
+ ```
102
+
103
+ Arguments:
104
+
105
+ * `name`: A name for your transaction. Transactions are grouped by name. **Required**.
106
+ * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
107
+ * `context:`: An optional [Context](#api-context) used to enrich the transaction with information about the current request.
108
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
109
+ * `&block`: A block to wrap. Optionally yields the transaction.
110
+
111
+ Returns the return value of the given block.
112
+
113
+
114
+ ### `ElasticAPM.start_span` [api-agent-start_span]
115
+
116
+ Start a new span.
117
+
118
+ ```ruby
119
+ ElasticAPM.with_transaction 'Do things' do
120
+ ElasticAPM.start_span 'Do one of the things'
121
+ Database.query # ...
122
+ ElasticAPM.end_span
123
+ end
124
+ ```
125
+
126
+ Arguments:
127
+
128
+ * `name`: A name for your span. **Required**.
129
+ * `type`: The type of span eg. `db`.
130
+ * `subtype`: The subtype of span eg. `postgresql`.
131
+ * `action`: The action type of span eg. `connect` or `query`.
132
+ * `context`: An instance of `Span::Context`.
133
+ * `include_stacktrace`: Whether or not to collect a Stacktrace.
134
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
135
+ * `parent:`: An optional parent transaction or span. Relevant when the span is created in another thread.
136
+ * `sync:`: An boolean to indicate whether the span is created synchronously or not.
137
+ * `&block`: An optional block to wrap with the span. The block is passed the span as an optional argument.
138
+
139
+ Returns the created span.
140
+
141
+ 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.
142
+
143
+ ```ruby
144
+ transaction = ElasticAPM.current_transaction # or start one with `.start_transaction`
145
+ Thread.new do
146
+ ElasticAPM.start_span(
147
+ 'job 1',
148
+ parent: transaction,
149
+ sync: false
150
+ ) { Worker.perform }
151
+ ElasticAPM.end_span
152
+ end
153
+ ```
154
+
155
+
156
+ ### `ElasticAPM.end_span` [api-agent-end_span]
157
+
158
+ Ends the currently running span.
159
+
160
+
161
+ ### `ElasticAPM.with_span` [api-agent-with_span]
162
+
163
+ Wraps a block in a Span.
164
+
165
+ Arguments:
166
+
167
+ * `name`: A name for your span. **Required**.
168
+ * `type`: The type of span eg. `db`.
169
+ * `subtype`: The subtype of span eg. `postgresql`.
170
+ * `action`: The action type of span eg. `connect` or `query`.
171
+ * `context`: An instance of `Span::Context`.
172
+ * `include_stacktrace`: Whether or not to collect a Stacktrace.
173
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
174
+ * `parent:`: An optional parent transaction or span. Relevant when the span is created in another thread.
175
+ * `sync:`: An boolean to indicate whether the span is created synchronously or not.
176
+ * `&block`: An optional block to wrap with the span. The block is passed the span as an optional argument.
177
+
178
+ Returns the return value of the given block.
179
+
180
+ 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.
181
+
182
+ ```ruby
183
+ transaction = ElasticAPM.current_transaction # or start one with `.start_transaction`
184
+ Thread.new do
185
+ ElasticAPM.with_span(
186
+ 'job 1',
187
+ parent: transaction,
188
+ sync: false
189
+ ) { Worker.perform }
190
+ end
191
+ ```
192
+
193
+
194
+ ### `ElasticAPM.build_context` [api-agent-build-context]
195
+
196
+ Build a new *Context* from a Rack `env`.
197
+
198
+ A context provides information about the current request, response, user and more.
199
+
200
+ Arguments:
201
+
202
+ * `rack_env`: An instance of Rack::Env
203
+ * `for_type`: Symbol representing type of event, eg. `:transaction` or `error`
204
+
205
+ Returns the built context.
206
+
207
+
208
+ ## Rails [rails-start]
209
+
210
+ Start the agent and hook into Rails manually. This is useful if you skip requiring the gem and using the `Railtie`.
211
+
212
+ ```ruby
213
+ ElasticAPM::Rails.start(server_url: 'http://localhost:8200')
214
+ ```
215
+
216
+
217
+ ## Sinatra [sinatra-start]
218
+
219
+ Start the agent and hook into Sinatra.
220
+
221
+ ```ruby
222
+ ElasticAPM::Sinatra.start(MySinatraApp, server_url: 'http://localhost:8200')
223
+ ```
224
+
225
+
226
+ ## Grape [grape-start]
227
+
228
+ Start the agent and hook into Grape.
229
+
230
+ ```ruby
231
+ ElasticAPM::Grape.start(MyGrapeApp, server_url: 'http://localhost:8200')
232
+ ```
233
+
234
+
235
+ ## Errors [_errors]
236
+
237
+
238
+ ### `ElasticAPM.report` [api-agent-report]
239
+
240
+ Send an `Exception` to Elastic APM.
241
+
242
+ If reported inside a transaction, the context from that will be added.
243
+
244
+ ```ruby
245
+ begin
246
+ do_a_thing_and_fail
247
+ rescue Exception => e
248
+ ElasticAPM.report(e)
249
+ end
250
+ ```
251
+
252
+ Arguments:
253
+
254
+ * `exception`: An instance of `Exception`. **Required**.
255
+ * `handled`: Whether the error was *handled* eg. wasn’t rescued and was represented to the user. Default: `true`.
256
+
257
+ Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
258
+
259
+
260
+ ### `ElasticAPM.report_message` [api-agent-report-message]
261
+
262
+ Send a custom message to Elastic APM.
263
+
264
+ If reported inside a transaction, the context from that will be added.
265
+
266
+ ```ruby
267
+ ElasticAPM.report_message('This should probably never happen?!')
268
+ ```
269
+
270
+ Arguments:
271
+
272
+ * `message`: A custom error string. **Required**.
273
+
274
+ Returns `[String]` ID of the generated `[ElasticAPM::Error]` object.
275
+
276
+
277
+ ## Context [api-context]
278
+
279
+
280
+ ### `ElasticAPM.set_label` [api-agent-set-label]
281
+
282
+ 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.
283
+
284
+ ::::{tip}
285
+ Before using custom labels, ensure you understand the different types of [metadata](docs-content://solutions/observability/apps/metadata.md) that are available.
286
+ ::::
287
+
288
+
289
+ ```ruby
290
+ before_action do
291
+ ElasticAPM.set_label(:company_id, current_user.company.id)
292
+ end
293
+ ```
294
+
295
+ Arguments:
296
+
297
+ * `key`: A string key. Note that `.`, `*` or `"` will be converted to `_`.
298
+ * `value`: A value.
299
+
300
+ Returns the set `value`.
301
+
302
+ ::::{warning}
303
+ 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)**.
304
+ ::::
305
+
306
+
307
+
308
+ ### `ElasticAPM.set_custom_context` [api-agent-set-custom-context]
309
+
310
+ 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.
311
+
312
+ ::::{tip}
313
+ Before using custom context, ensure you understand the different types of [metadata](docs-content://solutions/observability/apps/metadata.md) that are available.
314
+ ::::
315
+
316
+
317
+ If called several times during a transaction the custom context will be destructively merged with `merge!`.
318
+
319
+ ```ruby
320
+ before_action do
321
+ ElasticAPM.set_custom_context(company: current_user.company.to_h)
322
+ end
323
+ ```
324
+
325
+ Arguments:
326
+
327
+ * `context`: A hash of JSON-compatible key-values. Can be nested.
328
+
329
+ Returns current custom context.
330
+
331
+
332
+ ### `ElasticAPM.set_user` [api-agent-set-user]
333
+
334
+ Add the current user to the current transaction’s context.
335
+
336
+ Arguments:
337
+
338
+ * `user`: An object representing the user
339
+
340
+ Returns the given user
341
+
342
+
343
+ ## Data [_data]
344
+
345
+
346
+ ### `ElasticAPM.add_filter` [api-agent-add-filter]
347
+
348
+ Provide a filter to transform payloads before sending.
349
+
350
+ Arguments:
351
+
352
+ * `key`: A unique key identifying the filter
353
+ * `callable`: An object or proc (responds to `.call(payload)`)
354
+
355
+ Return the altered payload.
356
+
357
+ If `nil` is returned all subsequent filters will be skipped and the post request cancelled.
358
+
359
+ Example:
360
+
361
+ ```ruby
362
+ ElasticAPM.add_filter(:filter_pings) do |payload|
363
+ payload[:transactions]&.reject! do |t|
364
+ t[:name] == 'PingsController#index'
365
+ end
366
+ payload
367
+ end
368
+ ```
369
+
370
+
371
+ ## Transaction [api-transaction]
372
+
373
+ `ElasticAPM.transaction` returns a `Transaction` (if the agent is running).
374
+
375
+
376
+ ### Properties [_properties]
377
+
378
+ * `name`: String
379
+ * `type`: String
380
+ * `result`: String
381
+ * `outcome`: String (*unknown*, *success*, *failure*, nil)
382
+ * `trace_id`: String (readonly)
383
+
384
+
385
+ ### `#sampled?` [api-transaction-sampled_]
386
+
387
+ Whether the transaction is *sampled* eg. it includes stacktraces for its spans.
388
+
389
+
390
+ ### `#ensure_parent_id` [api-transaction-ensure_parent_id]
391
+
392
+ 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`.
393
+
394
+ 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.
395
+
396
+ 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.
397
+
398
+ To enable the JavaScript RUM agent, initialize the RUM agent with the Ruby agent’s current transaction:
399
+
400
+ ```html
401
+ <script src="elastic-apm-js-base/dist/bundles/elastic-apm-js-base.umd.min.js"></script>
402
+ <script>
403
+ var elasticApm = initApm({
404
+ serviceName: '',
405
+ serverUrl: 'http://localhost:8200',
406
+ pageLoadTraceId: "<%= ElasticAPM.current_transaction&.trace_id %>",
407
+ pageLoadSpanId: "<%= ElasticAPM.current_transaction&.ensure_parent_id %>",
408
+ pageLoadSampled: <%= ElasticAPM.current_transaction&.sampled? %>
409
+ })
410
+ </script>
411
+ ```
412
+
413
+ See the [JavaScript RUM agent documentation](apm-agent-rum-js://reference/index.md) for more information.
414
+
415
+
416
+ ## Span [api-span]
417
+
418
+
419
+ ### Properties [_properties_2]
420
+
421
+ * `name`: String
422
+ * `type`: String