Skip to content

Commit 0aa4e8b

Browse files
committed
Merge branch 'add-transaction-name-sampling-config' into pr-1510-and-1531
* add-transaction-name-sampling-config: Add ability to configure sampling rate based on transaction span name Updates to allow tests to pass (elastic#1541) fix image paths for docs-assembler (elastic#1538)
2 parents cba8707 + 74bc922 commit 0aa4e8b

File tree

12 files changed

+114
-151
lines changed

12 files changed

+114
-151
lines changed

.ci/.exclude.yml

Lines changed: 15 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ exclude:
22
# Ruby 2.4
33
# Only test on rails-4.2, sinatra-1.4
44
- VERSION: ruby:2.4
5-
FRAMEWORK: rails-7.0
5+
FRAMEWORK: rails-7.2
66
- VERSION: ruby:2.4
77
FRAMEWORK: rails-6.1
8-
- VERSION: ruby:2.4
9-
FRAMEWORK: rails-6.0
108
- VERSION: ruby:2.4
119
FRAMEWORK: rails-5.2
1210
- VERSION: ruby:2.4
1311
FRAMEWORK: sinatra-2.2
1412
- VERSION: ruby:2.4
1513
FRAMEWORK: grape-1.6
16-
- VERSION: ruby:2.4
17-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.0
1814
- VERSION: ruby:2.4
1915
FRAMEWORK: rails-main
2016
- VERSION: ruby:2.4
@@ -26,8 +22,6 @@ exclude:
2622
# Only test on ruby 2.4
2723
- VERSION: ruby:3.1
2824
FRAMEWORK: rails-4.2
29-
- VERSION: ruby:3.0
30-
FRAMEWORK: rails-4.2
3125
- VERSION: ruby:2.7
3226
FRAMEWORK: rails-4.2
3327
- VERSION: ruby:2.6
@@ -43,8 +37,6 @@ exclude:
4337
# sinatra-1.4 exclusions
4438
- VERSION: ruby:3.1
4539
FRAMEWORK: sinatra-1.4
46-
- VERSION: ruby:3.0
47-
FRAMEWORK: sinatra-1.4
4840
- VERSION: ruby:2.7
4941
FRAMEWORK: sinatra-1.4
5042
- VERSION: jruby:9.2
@@ -56,22 +48,18 @@ exclude:
5648
- VERSION: elasticobservability/jruby:9.2-8-jdk
5749
FRAMEWORK: sinatra-1.4
5850

59-
# rails-6.0 and rails-6.1 exclusions
51+
# rails-6.1 and rails 7.0 exclusions
6052
# Don't test on ruby 2.4
6153
- VERSION: ruby:2.4
6254
FRAMEWORK: rails-6.1
6355
- VERSION: ruby:2.4
64-
FRAMEWORK: rails-6.0
56+
FRAMEWORK: rails-7.2
6557

6658
# Only test rails main on ruby 3.1
67-
- VERSION: ruby:3.0
68-
FRAMEWORK: rails-main
6959
- VERSION: ruby:2.7
7060
FRAMEWORK: rails-main
7161
- VERSION: ruby:2.6
7262
FRAMEWORK: rails-main
73-
- VERSION: ruby:2.5
74-
FRAMEWORK: rails-main
7563
- VERSION: ruby:2.4
7664
FRAMEWORK: rails-main
7765
- VERSION: jruby:9.2
@@ -83,29 +71,25 @@ exclude:
8371
- VERSION: elasticobservability/jruby:9.2-8-jdk
8472
FRAMEWORK: rails-main
8573

86-
# Only test rails 7.0 on ruby >= 2.7
74+
# Only test rails 7.2 on ruby >= 3.1
75+
- VERSION: ruby:2.7
76+
FRAMEWORK: rails-7.2
8777
- VERSION: ruby:2.6
88-
FRAMEWORK: rails-7.0
89-
- VERSION: ruby:2.5
90-
FRAMEWORK: rails-7.0
78+
FRAMEWORK: rails-7.2
9179
- VERSION: ruby:2.4
92-
FRAMEWORK: rails-7.0
80+
FRAMEWORK: rails-7.2
9381
- VERSION: jruby:9.2
94-
FRAMEWORK: rails-7.0
82+
FRAMEWORK: rails-7.2
9583
- VERSION: elasticobservability/jruby:9.2-13-jdk
96-
FRAMEWORK: rails-7.0
84+
FRAMEWORK: rails-7.2
9785
- VERSION: elasticobservability/jruby:9.2-11-jdk
98-
FRAMEWORK: rails-7.0
86+
FRAMEWORK: rails-7.2
9987
- VERSION: elasticobservability/jruby:9.2-8-jdk
100-
FRAMEWORK: rails-7.0
88+
FRAMEWORK: rails-7.2
10189

10290
# Only test sinatra main on ruby 2.7 and ruby 3.1
103-
- VERSION: ruby:3.0
104-
FRAMEWORK: sinatra-main
10591
- VERSION: ruby:2.6
10692
FRAMEWORK: sinatra-main
107-
- VERSION: ruby:2.5
108-
FRAMEWORK: sinatra-main
10993
- VERSION: ruby:2.4
11094
FRAMEWORK: sinatra-main
11195
- VERSION: jruby:9.2
@@ -117,11 +101,9 @@ exclude:
117101
- VERSION: elasticobservability/jruby:9.2-8-jdk
118102
FRAMEWORK: sinatra-main
119103

120-
# Only test grape master on ruby 2.7 and ruby 3.0
104+
# Only test grape master on ruby 2.7 and ruby 3.1
121105
- VERSION: ruby:2.6
122106
FRAMEWORK: grape-master
123-
- VERSION: ruby:2.5
124-
FRAMEWORK: grape-master
125107
- VERSION: ruby:2.4
126108
FRAMEWORK: grape-master
127109
- VERSION: jruby:9.2
@@ -133,61 +115,12 @@ exclude:
133115
- VERSION: elasticobservability/jruby:9.2-8-jdk
134116
FRAMEWORK: grape-master
135117

136-
# grape 1.5 doesn't support ruby 3.0
118+
# grape 1.5 doesn't support ruby 3.1
137119
- VERSION: ruby:3.1
138120
FRAMEWORK: grape-1.6
139-
- VERSION: ruby:3.1
140-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
141-
- VERSION: ruby:3.1
142-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
143-
- VERSION: ruby:3.0
144-
FRAMEWORK: grape-1.6
145-
- VERSION: ruby:3.0
146-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
147121

148-
# only test ruby >= 3.0 with rails 6.0 and rails 6.1
122+
# only test ruby >= 3.1 with rails 6.1 and rails 7.0
149123
- VERSION: ruby:3.1
150124
FRAMEWORK: rails-5.2
151125
- VERSION: ruby:3.1
152126
FRAMEWORK: rails-5.1
153-
- VERSION: ruby:3.0
154-
FRAMEWORK: rails-5.2
155-
- VERSION: ruby:3.0
156-
FRAMEWORK: rails-5.1
157-
158-
# Unsupported
159-
# Ruby 2.6
160-
- VERSION: ruby:2.6
161-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
162-
- VERSION: ruby:2.6
163-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
164-
# Ruby 2.5
165-
- VERSION: ruby:2.5
166-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
167-
- VERSION: ruby:2.5
168-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
169-
# Ruby 2.4
170-
- VERSION: ruby:2.4
171-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
172-
- VERSION: ruby:2.4
173-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
174-
# JRuby 9.2
175-
- VERSION: jruby:9.2
176-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
177-
- VERSION: jruby:9.2
178-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
179-
# JRuby 9.2-13-jdk
180-
- VERSION: elasticobservability/jruby:9.2-13-jdk
181-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
182-
- VERSION: elasticobservability/jruby:9.2-13-jdk
183-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
184-
# JRuby 9.2-11-jdk
185-
- VERSION: elasticobservability/jruby:9.2-11-jdk
186-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
187-
- VERSION: elasticobservability/jruby:9.2-11-jdk
188-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0
189-
# JRuby 9.2-8-jdk
190-
- VERSION: elasticobservability/jruby:9.2-8-jdk
191-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1
192-
- VERSION: elasticobservability/jruby:9.2-8-jdk
193-
FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0

.ci/.framework.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
FRAMEWORK:
2-
- rails-7.0
2+
- rails-7.2
33
- rails-6.1
4-
- rails-6.0
54
- rails-5.2
65
- rails-4.2
76

87
- sinatra-2.2
98
- sinatra-1.4
109

1110
- grape-1.6
12-
13-
- grape-1.6,sinatra-2.2,rails-6.1

.ci/.ruby.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
VERSION:
22
- ruby:3.4
33
- ruby:3.1
4-
- ruby:3.0
54
- ruby:2.7
65
- ruby:2.6
76
- ruby:2.4

Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ frameworks_versions.each do |framework, version|
103103
end
104104
end
105105

106+
# Handle Rack::Auth::Digest being removed in rack 3.1, grape requires it
107+
if frameworks_versions.key?('grape')
108+
gem 'rack', '~> 3.0.0'
109+
end
110+
106111
if frameworks_versions.key?('rails')
107112
unless /^(main|6)/.match?(frameworks_versions['rails'])
108113
gem 'delayed_job', require: nil
@@ -125,8 +130,12 @@ if RUBY_PLATFORM == 'java'
125130
end
126131
elsif frameworks_versions['rails'] =~ /^(4|5)/
127132
gem 'sqlite3', '~> 1.3.6'
133+
elsif frameworks_versions['rails'] =~ /^(6|7)/
134+
gem 'sqlite3', '~> 1.4'
128135
elsif RUBY_VERSION < '2.7'
129136
gem 'sqlite3', '~> 1.4.4'
137+
elsif RUBY_VERSION < '3.0'
138+
gem 'sqlite3', '~> 1.3.6'
130139
else
131140
gem 'sqlite3'
132141
end

docs/reference/configuration.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Options are applied in the following order (last one wins):
2323
2. Arguments to `ElasticAPM.start` / `Config.new`
2424
3. Config file, e.g., `config/elastic_apm.yml`
2525
4. Environment variables
26-
5. [Central configuration](docs-content://solutions/observability/apps/apm-agent-central-configuration.md) (supported options are marked with [![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration))
26+
5. [Central configuration](docs-content://solutions/observability/apps/apm-agent-central-configuration.md) (supported options are marked with [![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration))
2727

2828

2929
## Dynamic configuration [dynamic-configuration]
3030

31-
Configuration options marked with the ![dynamic config](/reference/images/dynamic-config.svg "") badge can be changed at runtime when set from a supported source.
31+
Configuration options marked with the ![dynamic config](images/dynamic-config.svg "") badge can be changed at runtime when set from a supported source.
3232

3333
The Agent supports [Central configuration](docs-content://solutions/observability/apps/apm-agent-central-configuration.md), which allows you to fine-tune certain configurations via the APM app. This feature is enabled in the Agent by default, with [`central_config`](#config-central-config).
3434

@@ -65,7 +65,7 @@ ElasticAPM::Sinatra.start(
6565
)
6666
```
6767

68-
See [Getting started with Rack](/reference/getting-started-rack.md).
68+
See [Getting started with Rack](getting-started-rack.md).
6969

7070

7171
## Grape and Rack [_grape_and_rack]
@@ -80,7 +80,7 @@ ElasticAPM::Grape.start(
8080
)
8181
```
8282

83-
See [Getting started with Rack](/reference/getting-started-rack.md).
83+
See [Getting started with Rack](getting-started-rack.md).
8484

8585

8686
## Options [_options]
@@ -154,7 +154,7 @@ If you hit the limit, consider increasing the agent’s [worker pool size](#conf
154154

155155
### `api_request_size` [config-api-request-size]
156156

157-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
157+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
158158

159159
| | | |
160160
| --- | --- | --- |
@@ -168,7 +168,7 @@ This must be provided in **[size format](#config-format-size)**.
168168

169169
### `api_request_time` [config-api-request-time]
170170

171-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
171+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
172172

173173
| | | |
174174
| --- | --- | --- |
@@ -197,7 +197,7 @@ This feature requires APM Server and Kibana >= 7.3.
197197

198198
### `capture_body` [config-capture-body]
199199

200-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
200+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
201201

202202
| | | | |
203203
| --- | --- | --- | --- |
@@ -218,7 +218,7 @@ Request bodies often contain sensitive values like passwords and credit card num
218218

219219
### `capture_headers` [config-capture-headers]
220220

221-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
221+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
222222

223223
| | | |
224224
| --- | --- | --- |
@@ -404,7 +404,7 @@ The host name to use when sending error and transaction data to the APM server.
404404

405405
Use this option to ignore certain URL patterns such as healthchecks or admin sections.
406406

407-
*Ignoring* in this context means *don’t wrap in a [Transaction](/reference/api-reference.md#api-transaction)*. Errors will still be reported.
407+
*Ignoring* in this context means *don’t wrap in a [Transaction](api-reference.md#api-transaction)*. Errors will still be reported.
408408

409409
Use a comma separated string when setting this option via `ENV`. Eg. `ELASTIC_APM_IGNORE_URL_PATTERNS="a,b" # => [/a/, /b/]`
410410

@@ -444,7 +444,7 @@ Note that if you’re using Rails, the agent will ignore this option and use the
444444

445445
### `log_level` [config-log-level]
446446

447-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
447+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
448448

449449
| Environment | `Config` key | Default |
450450
| --- | --- | --- |
@@ -526,7 +526,7 @@ See [Http.rb’s docs](https://github.com/httprb/http/wiki/Proxy-Support).
526526

527527
### `recording` [config-recording]
528528

529-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
529+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
530530

531531
| Environment | `Config` key | Default |
532532
| --- | --- | --- |
@@ -619,7 +619,7 @@ Especially for spans, collecting source code can have a large impact on storage
619619
620620
### `span_frames_min_duration` [config-span-frames-min-duration-ms]
621621
622-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
622+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
623623
624624
| | | |
625625
| --- | --- | --- |
@@ -655,7 +655,7 @@ The maximum number of stack trace lines per span/error.
655655
656656
### `transaction_max_spans` [config-transaction-max-spans]
657657
658-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
658+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
659659
660660
| | | |
661661
| --- | --- | --- |
@@ -667,7 +667,7 @@ Limits the amount of spans that are recorded per transaction. This is helpful in
667667
668668
### `transaction_sample_rate` [config-transaction-sample-rate]
669669
670-
[![dynamic config](/reference/images/dynamic-config.svg "") ](#dynamic-configuration)
670+
[![dynamic config](images/dynamic-config.svg "") ](#dynamic-configuration)
671671
672672
| | | |
673673
| --- | --- | --- |

lib/elastic_apm/context_builder.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ def get_body(req)
7979
when 'application/x-www-form-urlencoded', 'multipart/form-data'
8080
req.POST.dup
8181
else
82-
body = req.body.read
83-
req.body.rewind
82+
io = req.body
83+
return '' unless io
84+
85+
body = io.read
86+
io.rewind
8487
body.byteslice(0, MAX_BODY_LENGTH).force_encoding('utf-8').scrub
8588
end
8689
end

lib/elastic_apm/instrumenter.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,9 @@ def start_span(
202202
# we need to check if the span should be sampled
203203
# and update the transaction's sample rate accordingly
204204
if transaction.started_spans == 0 && span_sample_rate && span_sample_rate != transaction.sample_rate
205-
# if span_sample_rate && span_sample_rate != transaction.sample_rate
206205
span_sampled = random_sample?(span_sample_rate)
207-
if transaction.sampled? != span_sampled
208-
transaction.sampled = span_sampled
209-
transaction.sample_rate = span_sample_rate
210-
end
206+
transaction.sampled = span_sampled
207+
transaction.sample_rate = span_sampled ? span_sample_rate : 0
211208
end
212209
end
213210

spec/elastic_apm/grpc_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
require 'spec_helper'
2121

22-
# if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0'
22+
# if !defined?(JRUBY_VERSION) && RUBY_VERSION >= '3.0'
2323
# require 'grpc'
2424
#
2525
# module ElasticAPM

0 commit comments

Comments
 (0)