elastic-apm 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/.jenkins_exclude.yml +39 -20
- data/.ci/.jenkins_framework.yml +2 -2
- data/.ci/Jenkinsfile +32 -19
- data/.ci/packer_cache.sh +14 -0
- data/.github/ISSUE_TEMPLATE/Bug_report.md +13 -11
- data/.github/ISSUE_TEMPLATE/Feature_request.md +8 -8
- data/.github/PULL_REQUEST_TEMPLATE.md +51 -5
- data/.gitignore +3 -0
- data/CHANGELOG.asciidoc +21 -1
- data/CONTRIBUTING.md +0 -44
- data/README.md +62 -13
- data/docs/api.asciidoc +1 -1
- data/docs/configuration.asciidoc +43 -6
- data/lib/elastic_apm/agent.rb +1 -0
- data/lib/elastic_apm/config.rb +32 -5
- data/lib/elastic_apm/config/wildcard_pattern_list.rb +3 -1
- data/lib/elastic_apm/context/response.rb +1 -1
- data/lib/elastic_apm/metrics/metric.rb +6 -4
- data/lib/elastic_apm/middleware.rb +3 -4
- data/lib/elastic_apm/opentracing.rb +2 -1
- data/lib/elastic_apm/span/context/db.rb +9 -2
- data/lib/elastic_apm/spies/faraday.rb +1 -1
- data/lib/elastic_apm/spies/http.rb +2 -1
- data/lib/elastic_apm/spies/net_http.rb +2 -1
- data/lib/elastic_apm/spies/sequel.rb +13 -3
- data/lib/elastic_apm/trace_context.rb +47 -51
- data/lib/elastic_apm/trace_context/traceparent.rb +96 -0
- data/lib/elastic_apm/trace_context/tracestate.rb +26 -0
- data/lib/elastic_apm/transport/filters/secrets_filter.rb +6 -3
- data/lib/elastic_apm/transport/serializers/span_serializer.rb +2 -1
- data/lib/elastic_apm/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ba0e1480f379488014123efe0974b22741593d451f1a501390dd0f8af17be2
|
4
|
+
data.tar.gz: f448574e08404ef0354998ef7e87173e653ef837309a3114f8694dcae97dbae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a730f4a97d7c974fa6f8d4acd5f5d5274f552eeeaacf169d2feb27e19b0b8ac1959df2cd8efa7718517cdf7bd1f81ad6e09d3fc57bba1f96d48b5c7572c472
|
7
|
+
data.tar.gz: 0e695ab76052b342ae71ba7e4eed6a6a03f1368ac67638fbc3a4e8ef2c1558e183d3911eeb38aba296d4ae469f37c4665123f4fe204760ce9f74dcdc238150ee
|
data/.ci/.jenkins_exclude.yml
CHANGED
@@ -1,4 +1,27 @@
|
|
1
1
|
exclude:
|
2
|
+
# Ruby 2.3
|
3
|
+
# Only includes rails-5.2, sinatra-2.0
|
4
|
+
- RUBY_VERSION: ruby:2.3
|
5
|
+
FRAMEWORK: rails-6.0
|
6
|
+
- RUBY_VERSION: ruby:2.3
|
7
|
+
FRAMEWORK: rails-5.1
|
8
|
+
- RUBY_VERSION: ruby:2.3
|
9
|
+
FRAMEWORK: rails-5.0
|
10
|
+
- RUBY_VERSION: ruby:2.3
|
11
|
+
FRAMEWORK: rails-4.2
|
12
|
+
- RUBY_VERSION: ruby:2.3
|
13
|
+
FRAMEWORK: sinatra-1.4
|
14
|
+
- RUBY_VERSION: ruby:2.3
|
15
|
+
FRAMEWORK: grape-1.3
|
16
|
+
- RUBY_VERSION: ruby:2.3
|
17
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
18
|
+
- RUBY_VERSION: ruby:2.3
|
19
|
+
FRAMEWORK: rails-master
|
20
|
+
- RUBY_VERSION: ruby:2.3
|
21
|
+
FRAMEWORK: sinatra-master
|
22
|
+
- RUBY_VERSION: ruby:2.3
|
23
|
+
FRAMEWORK: grape-master
|
24
|
+
|
2
25
|
- RUBY_VERSION: ruby:2.7
|
3
26
|
FRAMEWORK: rails-4.2
|
4
27
|
- RUBY_VERSION: jruby:9.2
|
@@ -18,8 +41,6 @@ exclude:
|
|
18
41
|
|
19
42
|
- RUBY_VERSION: ruby:2.4
|
20
43
|
FRAMEWORK: rails-6.0
|
21
|
-
- RUBY_VERSION: ruby:2.3
|
22
|
-
FRAMEWORK: rails-6.0
|
23
44
|
- RUBY_VERSION: jruby:9.1
|
24
45
|
FRAMEWORK: rails-6.0
|
25
46
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.1-7-jdk
|
@@ -32,8 +53,6 @@ exclude:
|
|
32
53
|
FRAMEWORK: rails-master
|
33
54
|
- RUBY_VERSION: ruby:2.4
|
34
55
|
FRAMEWORK: rails-master
|
35
|
-
- RUBY_VERSION: ruby:2.3
|
36
|
-
FRAMEWORK: rails-master
|
37
56
|
- RUBY_VERSION: jruby:9.2
|
38
57
|
FRAMEWORK: rails-master
|
39
58
|
- RUBY_VERSION: jruby:9.1
|
@@ -53,8 +72,6 @@ exclude:
|
|
53
72
|
FRAMEWORK: sinatra-master
|
54
73
|
- RUBY_VERSION: ruby:2.4
|
55
74
|
FRAMEWORK: sinatra-master
|
56
|
-
- RUBY_VERSION: ruby:2.3
|
57
|
-
FRAMEWORK: sinatra-master
|
58
75
|
- RUBY_VERSION: jruby:9.2
|
59
76
|
FRAMEWORK: sinatra-master
|
60
77
|
- RUBY_VERSION: jruby:9.1
|
@@ -76,8 +93,6 @@ exclude:
|
|
76
93
|
FRAMEWORK: grape-master
|
77
94
|
- RUBY_VERSION: ruby:2.4
|
78
95
|
FRAMEWORK: grape-master
|
79
|
-
- RUBY_VERSION: ruby:2.3
|
80
|
-
FRAMEWORK: grape-master
|
81
96
|
- RUBY_VERSION: jruby:9.2
|
82
97
|
FRAMEWORK: grape-master
|
83
98
|
- RUBY_VERSION: jruby:9.1
|
@@ -93,25 +108,29 @@ exclude:
|
|
93
108
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.1-7-jdk
|
94
109
|
FRAMEWORK: grape-master
|
95
110
|
|
111
|
+
# Unsupported
|
112
|
+
- RUBY_VERSION: jruby:9.1
|
113
|
+
FRAMEWORK: grape-1.3
|
114
|
+
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.1-7-jdk
|
115
|
+
FRAMEWORK: grape-1.3
|
116
|
+
|
96
117
|
- RUBY_VERSION: ruby:2.6
|
97
|
-
FRAMEWORK: grape-1.
|
118
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
98
119
|
- RUBY_VERSION: ruby:2.5
|
99
|
-
FRAMEWORK: grape-1.
|
120
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
100
121
|
- RUBY_VERSION: ruby:2.4
|
101
|
-
FRAMEWORK: grape-1.
|
102
|
-
- RUBY_VERSION: ruby:2.3
|
103
|
-
FRAMEWORK: grape-1.2,sinatra-2.0,rails-6.0
|
122
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
104
123
|
- RUBY_VERSION: jruby:9.2
|
105
|
-
FRAMEWORK: grape-1.
|
124
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
106
125
|
- RUBY_VERSION: jruby:9.1
|
107
|
-
FRAMEWORK: grape-1.
|
126
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
108
127
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.2-13-jdk
|
109
|
-
FRAMEWORK: grape-1.
|
128
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
110
129
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.2-12-jdk
|
111
|
-
FRAMEWORK: grape-1.
|
130
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
112
131
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.2-11-jdk
|
113
|
-
FRAMEWORK: grape-1.
|
132
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
114
133
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.2-8-jdk
|
115
|
-
FRAMEWORK: grape-1.
|
134
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
116
135
|
- RUBY_VERSION: docker.elastic.co/observability-ci/jruby:9.1-7-jdk
|
117
|
-
FRAMEWORK: grape-1.
|
136
|
+
FRAMEWORK: grape-1.3,sinatra-2.0,rails-6.0
|
data/.ci/.jenkins_framework.yml
CHANGED
data/.ci/Jenkinsfile
CHANGED
@@ -5,10 +5,15 @@ import co.elastic.matrix.*
|
|
5
5
|
import groovy.transform.Field
|
6
6
|
|
7
7
|
/**
|
8
|
-
This is required to
|
8
|
+
This is required to know if there any failures when running the downstream jobs.
|
9
9
|
*/
|
10
10
|
@Field def rubyTasksFailed = false
|
11
11
|
|
12
|
+
/**
|
13
|
+
This is required to store the build status for the downstream jobs.
|
14
|
+
*/
|
15
|
+
@Field def rubyDownstreamJobs = [:]
|
16
|
+
|
12
17
|
pipeline {
|
13
18
|
agent { label 'linux && immutable' }
|
14
19
|
environment {
|
@@ -94,8 +99,9 @@ pipeline {
|
|
94
99
|
script {
|
95
100
|
def ruby = readYaml(file: '.ci/.jenkins_ruby.yml')
|
96
101
|
def testTasks = [:]
|
102
|
+
def i = 0
|
97
103
|
ruby['RUBY_VERSION'].each{ rubyVersion ->
|
98
|
-
testTasks[rubyVersion] = { runJob(rubyVersion) }
|
104
|
+
testTasks[rubyVersion] = { runJob(rubyVersion, i++) }
|
99
105
|
}
|
100
106
|
parallel(testTasks)
|
101
107
|
}
|
@@ -143,10 +149,7 @@ pipeline {
|
|
143
149
|
script {
|
144
150
|
def versions = readYaml(file: ".ci/.jenkins_ruby.yml")
|
145
151
|
def benchmarkTask = [:]
|
146
|
-
|
147
|
-
// NoMethodError: undefined method `[]' for nil:NilClass
|
148
|
-
// <main> at bench/report.rb:48
|
149
|
-
versions['RUBY_VERSION'].findAll { !it.contains('9.2') }.each{ v ->
|
152
|
+
versions['RUBY_VERSION'].each{ v ->
|
150
153
|
benchmarkTask[v] = runBenchmark(v)
|
151
154
|
}
|
152
155
|
parallel(benchmarkTask)
|
@@ -157,12 +160,18 @@ pipeline {
|
|
157
160
|
}
|
158
161
|
}
|
159
162
|
}
|
160
|
-
stage('Populate
|
163
|
+
stage('Populate Downstream failures') {
|
161
164
|
when {
|
162
165
|
expression { return rubyTasksFailed }
|
163
166
|
}
|
164
167
|
steps {
|
165
|
-
|
168
|
+
script {
|
169
|
+
def message = 'Failures when running the "Test" stage'
|
170
|
+
if (notifyBuildResult.isAnyDownstreamJobFailedWithTimeout(rubyDownstreamJobs)) {
|
171
|
+
message += ' related to a timeout issue'
|
172
|
+
}
|
173
|
+
error(message)
|
174
|
+
}
|
166
175
|
}
|
167
176
|
}
|
168
177
|
stage('Integration Tests') {
|
@@ -243,7 +252,7 @@ pipeline {
|
|
243
252
|
}
|
244
253
|
post {
|
245
254
|
cleanup {
|
246
|
-
notifyBuildResult()
|
255
|
+
notifyBuildResult(downstreamJobs: rubyDownstreamJobs)
|
247
256
|
}
|
248
257
|
}
|
249
258
|
}
|
@@ -268,7 +277,7 @@ def runBenchmark(version){
|
|
268
277
|
dockerLogin(secret: "${DOCKER_SECRET}", registry: "${DOCKER_REGISTRY}")
|
269
278
|
}
|
270
279
|
try{
|
271
|
-
sh "./spec/scripts/benchmarks.sh ${version}"
|
280
|
+
sh """./spec/scripts/benchmarks.sh "${version}" "${REFERENCE_REPO}" """
|
272
281
|
} catch(e){
|
273
282
|
throw e
|
274
283
|
} finally {
|
@@ -285,19 +294,23 @@ def runBenchmark(version){
|
|
285
294
|
}
|
286
295
|
}
|
287
296
|
|
288
|
-
def runJob(rubyVersion){
|
297
|
+
def runJob(String rubyVersion, int sleep = 1){
|
298
|
+
def buildObject
|
289
299
|
try {
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
300
|
+
def quiet = (sleep * randomNumber(min: 2, max: 6)) + 5
|
301
|
+
buildObject = build(job: "apm-agent-ruby/apm-agent-ruby-downstream/${env.BRANCH_NAME}",
|
302
|
+
parameters: [
|
303
|
+
string(name: 'RUBY_VERSION', value: "${rubyVersion}"),
|
304
|
+
string(name: 'BRANCH_SPECIFIER', value: "${env.GIT_BASE_COMMIT}")
|
305
|
+
],
|
306
|
+
quietPeriod: quiet)
|
297
307
|
} catch(e) {
|
298
308
|
rubyTasksFailed = true
|
299
|
-
|
309
|
+
buildObject = e
|
310
|
+
warnError('Downstream Failed') {
|
300
311
|
error("Downstream job for '${rubyVersion}' failed")
|
301
312
|
}
|
313
|
+
} finally {
|
314
|
+
rubyDownstreamJobs["${rubyVersion}"] = buildObject
|
302
315
|
}
|
303
316
|
}
|
data/.ci/packer_cache.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
source /usr/local/bin/bash_standard_lib.sh
|
4
|
+
|
5
|
+
grep "-" .ci/.jenkins_ruby.yml | grep -v 'observability-ci' | cut -d'-' -f2- | \
|
6
|
+
while read -r version;
|
7
|
+
do
|
8
|
+
transformedName=${version/:/-}
|
9
|
+
transformedVersion=$(echo "${version}" | cut -d":" -f2)
|
10
|
+
imageName="apm-agent-ruby"
|
11
|
+
registryImageName="docker.elastic.co/observability-ci/${imageName}:${transformedName}"
|
12
|
+
(retry 2 docker pull "${registryImageName}")
|
13
|
+
docker tag "${registryImageName}" "${imageName}:${transformedVersion}"
|
14
|
+
done
|
@@ -4,26 +4,28 @@ about: Create a report to help us improve
|
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
**To Reproduce**
|
7
|
+
## Describe the bug
|
10
8
|
|
9
|
+
## Steps to reproduce
|
10
|
+
<!--
|
11
11
|
1. ...
|
12
12
|
2. ...
|
13
13
|
3. ...
|
14
14
|
4. ...
|
15
|
+
-->
|
15
16
|
|
16
|
-
|
17
|
+
## Expected behavior
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
19
|
+
## Environment
|
20
|
+
<!-- Please complete the following information -->
|
21
|
+
- **OS**: <!-- [e.g. Linux] -->
|
22
|
+
- **Ruby version**:
|
23
|
+
- **Framework and version**: <!-- [e.g. Rails 6.0.1] -->
|
24
|
+
- **APM Server version**:
|
25
|
+
- **Agent version**:
|
24
26
|
|
25
27
|
|
26
|
-
|
28
|
+
## Additional context
|
27
29
|
|
28
30
|
Add any other context about the problem here.
|
29
31
|
|
@@ -4,14 +4,14 @@ about: Suggest an idea for this project
|
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
|
8
|
-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
7
|
+
## Is your feature request related to a problem? Please describe.
|
8
|
+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
9
9
|
|
10
|
-
|
11
|
-
A clear and concise description of what you want to happen.
|
10
|
+
## Describe the solution you'd like
|
11
|
+
<!-- A clear and concise description of what you want to happen. -->
|
12
12
|
|
13
|
-
|
14
|
-
A clear and concise description of any alternative solutions or features you've considered.
|
13
|
+
## Describe alternatives you've considered
|
14
|
+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
15
15
|
|
16
|
-
|
17
|
-
Add any other context or screenshots about the feature request here.
|
16
|
+
## Additional context
|
17
|
+
<!-- Add any other context or screenshots about the feature request here. -->
|
@@ -1,14 +1,60 @@
|
|
1
|
+
<!--
|
2
|
+
A few suggestions about filling out this PR
|
3
|
+
|
4
|
+
1. Use a descriptive title for the PR.
|
5
|
+
2. If this pull request is work in progress, create a draft PR instead of prefixing the title with WIP.
|
6
|
+
3. Please label this PR at least one of the following labels, depending on the scope of your change:
|
7
|
+
- feature request, which adds new behavior
|
8
|
+
- bug fix
|
9
|
+
- enhancement, which modifies existing behavior
|
10
|
+
- breaking change
|
11
|
+
4. Remove those recommended/optional sections if you don't need them. Only "What does this PR do", "Why is it important?" and "Checklist" are mandatory.
|
12
|
+
5. Generally, we require that you test any code you are adding or modifying.
|
13
|
+
Once your changes are ready to submit for review:
|
14
|
+
6. Submit the pull request: Push your local changes to your forked copy of the repository and submit a pull request (https://help.github.com/articles/using-pull-requests).
|
15
|
+
7. Please be patient. We might not be able to review your code as fast as we would like to, but we'll do our best to dedicate to it the attention it deserves. Your effort is much appreciated!
|
16
|
+
-->
|
17
|
+
|
1
18
|
## What does this pull request do?
|
2
19
|
|
3
|
-
<!--
|
4
|
-
|
20
|
+
<!--
|
21
|
+
Use this space to describe what the proposed code _does_, ie. what precisely will be done differently from this change.
|
5
22
|
-->
|
6
23
|
|
7
24
|
## Why is it important?
|
8
25
|
|
9
|
-
<!--
|
10
|
-
|
26
|
+
<!--
|
27
|
+
Optionally provide an explanation of why this is important.
|
28
|
+
-->
|
29
|
+
|
30
|
+
## Checklist
|
31
|
+
<!--
|
32
|
+
Add a checklist of things that are required to be reviewed in order to have the PR approved
|
33
|
+
|
34
|
+
List here all the items you have verified BEFORE sending this PR. Please DO NOT remove any item, striking through those that do not apply. (Just in case, strikethrough uses two tildes. ~~Scratch this.~~)
|
11
35
|
-->
|
12
36
|
|
37
|
+
- [ ] I have signed the [Contributor License Agreement](https://www.elastic.co/contributor-agreement/).
|
38
|
+
- [ ] My code follows the style guidelines of this project (See `.rubocop.yml`)
|
39
|
+
- [ ] I have rebased my changes on top of the latest master branch
|
40
|
+
<!--
|
41
|
+
Update your local repository with the most recent code from the main repo, and rebase your branch on top of the latest master branch. We prefer your initial changes to be squashed into a single commit. Later, if we ask you to make changes, add them as separate commits. This makes them easier to review.
|
42
|
+
-->
|
43
|
+
- [ ] I have added tests that prove my fix is effective or that my feature works
|
44
|
+
- [ ] New and existing [**unit** tests](https://github.com/elastic/apm-agent-ruby/blob/master/CONTRIBUTING.md#testing) pass locally with my changes
|
45
|
+
<!--
|
46
|
+
Run the test suite to make sure that nothing is broken. See https://github.com/elastic/apm-agent-ruby/blob/master/CONTRIBUTING.md#testing for details.
|
47
|
+
-->
|
48
|
+
- [ ] I have made corresponding changes to the documentation
|
49
|
+
- [ ] I have updated [CHANGELOG.asciidoc](CHANGELOG.asciidoc)
|
50
|
+
- [ ] I have updated [supported-technologies.asciidoc](docs/supported-technologies.asciidoc)
|
51
|
+
- [ ] Added an API method or config option? Document in which version this will be introduced
|
52
|
+
|
13
53
|
## Related issues
|
14
|
-
|
54
|
+
<!--
|
55
|
+
Link related issues below. Insert the issue link or reference after the word "Closes" if merging this should automatically close it.
|
56
|
+
- Closes #ISSUE_ID
|
57
|
+
- Relates #ISSUE_ID
|
58
|
+
- Requires #ISSUE_ID
|
59
|
+
- Superseds #ISSUE_ID
|
60
|
+
-->
|
data/.gitignore
CHANGED
data/CHANGELOG.asciidoc
CHANGED
@@ -35,6 +35,26 @@ endif::[]
|
|
35
35
|
[[release-notes-3.x]]
|
36
36
|
=== Ruby Agent version 3.x
|
37
37
|
|
38
|
+
[[release-notes-3.5.0]]
|
39
|
+
==== 3.5.0 (2020-02-12)
|
40
|
+
|
41
|
+
[float]
|
42
|
+
===== Added
|
43
|
+
|
44
|
+
- Pass along tracestate headers and add prefixless Traceparent header {pull}694[#694]
|
45
|
+
- Add sanitize_field_names to replace custom_key_filters {pull}708[#708]
|
46
|
+
- Add `rows_affected` to database related spans (Sequel only for now) {pull}668[#668]
|
47
|
+
|
48
|
+
[float]
|
49
|
+
===== Changed
|
50
|
+
|
51
|
+
- Rename disabled_instrumentations to disable_instrumentations {pull}695[#695]
|
52
|
+
|
53
|
+
[float]
|
54
|
+
===== Fixed
|
55
|
+
|
56
|
+
- Fix thread race condition in metrics collection (JRuby) {pull}669[#669]
|
57
|
+
|
38
58
|
[[release-notes-3.4.0]]
|
39
59
|
==== 3.4.0 (2020-01-10)
|
40
60
|
|
@@ -45,7 +65,7 @@ endif::[]
|
|
45
65
|
- Add more precise (experimental) SQL summarizer {pull}640[#640]
|
46
66
|
- Add support for Shoryuken (AWS SQS) {pull}674[#674]
|
47
67
|
- Add support for Sneakers (Experimental) {pull}676[#676]
|
48
|
-
- Add option `api_key` to specify an Api key to use with the apm server {pull}655[#655]
|
68
|
+
- Add option `api_key` (experimental) to specify an Api key to use with the apm server {pull}655[#655]
|
49
69
|
|
50
70
|
[float]
|
51
71
|
===== Changed
|
data/CONTRIBUTING.md
CHANGED
@@ -18,50 +18,6 @@ Talk about what you would like to do.
|
|
18
18
|
It may be that somebody is already working on it,
|
19
19
|
or that there are particular issues that you should know about before implementing the change.
|
20
20
|
|
21
|
-
### Submitting your changes
|
22
|
-
|
23
|
-
Generally, we require that you test any code you are adding or modifying.
|
24
|
-
Once your changes are ready to submit for review:
|
25
|
-
|
26
|
-
1. Sign the Contributor License Agreement
|
27
|
-
|
28
|
-
Please make sure you have signed our [Contributor License Agreement](https://www.elastic.co/contributor-agreement/).
|
29
|
-
We are not asking you to assign copyright to us,
|
30
|
-
but to give us the right to distribute your code without restriction.
|
31
|
-
We ask this of all contributors in order to assure our users of the origin and continuing existence of the code.
|
32
|
-
You only need to sign the CLA once.
|
33
|
-
|
34
|
-
2. Test your changes
|
35
|
-
|
36
|
-
Run the test suite to make sure that nothing is broken.
|
37
|
-
See [testing](#testing) for details.
|
38
|
-
|
39
|
-
3. Rebase your changes
|
40
|
-
|
41
|
-
Update your local repository with the most recent code from the main repo,
|
42
|
-
and rebase your branch on top of the latest master branch.
|
43
|
-
We prefer your initial changes to be squashed into a single commit.
|
44
|
-
Later,
|
45
|
-
if we ask you to make changes,
|
46
|
-
add them as separate commits.
|
47
|
-
This makes them easier to review.
|
48
|
-
As a final step before merging we will either ask you to squash all commits yourself or we'll do it for you.
|
49
|
-
|
50
|
-
4. Submit a pull request
|
51
|
-
|
52
|
-
Push your local changes to your forked copy of the repository and [submit a pull request](https://help.github.com/articles/using-pull-requests).
|
53
|
-
In the pull request,
|
54
|
-
choose a title which sums up the changes that you have made,
|
55
|
-
and in the body provide more details about what your changes do.
|
56
|
-
Also mention the number of the issue where discussion has taken place,
|
57
|
-
eg "Closes #123".
|
58
|
-
|
59
|
-
5. Be patient
|
60
|
-
|
61
|
-
We might not be able to review your code as fast as we would like to,
|
62
|
-
but we'll do our best to dedicate it the attention it deserves.
|
63
|
-
Your effort is much appreciated!
|
64
|
-
|
65
21
|
### Workflow
|
66
22
|
|
67
23
|
All feature development and most bug fixes hit the master branch first.
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# elastic-apm
|
2
|
+
|
2
3
|
## Elastic APM agent for Ruby
|
3
4
|
|
4
5
|
[![Jenkins](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-ruby/apm-agent-ruby-mbp/master)](https://apm-ci.elastic.co/job/apm-agent-ruby/job/apm-agent-ruby-mbp/job/master/) [![Gem](https://img.shields.io/gem/v/elastic-apm.svg)](https://rubygems.org/gems/elastic-apm)
|
@@ -11,21 +12,69 @@ The official Rubygem for [Elastic][] [APM][].
|
|
11
12
|
|
12
13
|
## Documentation
|
13
14
|
|
14
|
-
[Full documentation at elastic.co](https://www.elastic.co/guide/en/apm/agent/ruby/
|
15
|
+
[Full documentation at elastic.co](https://www.elastic.co/guide/en/apm/agent/ruby/current/index.html).
|
15
16
|
|
16
17
|
<ul>
|
17
|
-
<li
|
18
|
-
<
|
19
|
-
<
|
20
|
-
<li
|
21
|
-
<
|
22
|
-
|
23
|
-
<
|
24
|
-
<
|
25
|
-
</
|
26
|
-
</
|
27
|
-
|
28
|
-
<li
|
18
|
+
<li>
|
19
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/set-up.html">Set up the Agent</a>
|
20
|
+
<ul>
|
21
|
+
<li>
|
22
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rails.html">Getting started with Rails</a>
|
23
|
+
</li>
|
24
|
+
<li>
|
25
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rack.html">Getting started with Rack</a>
|
26
|
+
</li>
|
27
|
+
</ul>
|
28
|
+
</li>
|
29
|
+
<li>
|
30
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/supported-technologies.html">Supported technologies</a>
|
31
|
+
</li>
|
32
|
+
<li>
|
33
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/configuration.html">Configuration</a>
|
34
|
+
</li>
|
35
|
+
<li>
|
36
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/advanced.html">Advanced Topics</a>
|
37
|
+
<ul>
|
38
|
+
<li>
|
39
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/context.html">Adding additional context</a>
|
40
|
+
</li>
|
41
|
+
<li>
|
42
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/custom-instrumentation.html">Custom instrumentation</a>
|
43
|
+
</li>
|
44
|
+
</ul>
|
45
|
+
</li>
|
46
|
+
<li>
|
47
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/api.html">API reference</a>
|
48
|
+
</li>
|
49
|
+
<li>
|
50
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/metrics.html">Metrics</a>
|
51
|
+
</li>
|
52
|
+
<li>
|
53
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/opentracing.html">OpenTracing API</a>
|
54
|
+
</li>
|
55
|
+
<li>
|
56
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/log-correlation.html">Log correlation</a>
|
57
|
+
</li>
|
58
|
+
<li>
|
59
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/debugging.html">Troubleshooting</a>
|
60
|
+
</li>
|
61
|
+
<li class="collapsible">
|
62
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/release-notes.html">Release notes</a>
|
63
|
+
<ul>
|
64
|
+
<li>
|
65
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/release-notes-3.x.html">Ruby Agent version 3.x</a>
|
66
|
+
</li>
|
67
|
+
<li>
|
68
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/release-notes-2.x.html">Ruby Agent version 2.x</a>
|
69
|
+
</li>
|
70
|
+
<li>
|
71
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/release-notes-1.x.html">Ruby Agent version 1.x</a>
|
72
|
+
</li>
|
73
|
+
<li>
|
74
|
+
<a href="https://www.elastic.co/guide/en/apm/agent/ruby/current/release-notes-0.x.html">Ruby Agent version 0.x</a>
|
75
|
+
</li>
|
76
|
+
</ul>
|
77
|
+
</li>
|
29
78
|
</ul>
|
30
79
|
|
31
80
|
---
|
data/docs/api.asciidoc
CHANGED
@@ -446,7 +446,7 @@ JavaScript RUM agent with the value of this method allows analyzing the time
|
|
446
446
|
spent in the browser vs in the backend services.
|
447
447
|
|
448
448
|
To enable the JavaScript RUM agent, initilialize the RUM agent with the Ruby
|
449
|
-
agent'
|
449
|
+
agent's current transaction:
|
450
450
|
|
451
451
|
[source,html]
|
452
452
|
----
|
data/docs/configuration.asciidoc
CHANGED
@@ -14,7 +14,6 @@ The recommended way to configure Elastic APM is to create a file
|
|
14
14
|
|
15
15
|
[source,yaml]
|
16
16
|
----
|
17
|
-
---
|
18
17
|
server_url: 'http://localhost:8200'
|
19
18
|
secret_token: <%= ENV["VERY_SECRET_TOKEN"] %>
|
20
19
|
----
|
@@ -90,7 +89,7 @@ Some options can be set with `ENV` variables and all of them may be set in
|
|
90
89
|
your source code.
|
91
90
|
|
92
91
|
When setting values for lists using `ENV` variables, strings are split by comma
|
93
|
-
eg `
|
92
|
+
eg `ELASTIC_APM_SANITIZE_FIELD_NAMES="a,b" # => [/a/, /b/]`.
|
94
93
|
|
95
94
|
[float]
|
96
95
|
[[config-config-file]]
|
@@ -147,6 +146,23 @@ ruby -r securerandom -e 'print SecureRandom.uuid'
|
|
147
146
|
|
148
147
|
WARNING: Secret tokens only provide any real security if your APM server uses TLS.
|
149
148
|
|
149
|
+
[float]
|
150
|
+
[[config-api-key]]
|
151
|
+
==== `api_key`
|
152
|
+
|
153
|
+
[options="header"]
|
154
|
+
|============
|
155
|
+
| Environment | `Config` key | Default | Example
|
156
|
+
| `ELASTIC_APM_API_KEY` | `api_key` | `nil` | A base64-encoded string
|
157
|
+
|============
|
158
|
+
|
159
|
+
This base64-encoded string is used to ensure that only your agents can send data to your APM server.
|
160
|
+
You must have created the api key using the APM server command line tool. Please see the APM server
|
161
|
+
documentation for details on how to do that. Please note that this feature is experimental in the
|
162
|
+
APM server in version 7.6.
|
163
|
+
|
164
|
+
WARNING: Api keys only provide any real security if your APM server uses TLS.
|
165
|
+
|
150
166
|
[float]
|
151
167
|
[[config-active]]
|
152
168
|
==== `active`
|
@@ -271,7 +287,7 @@ NOTE: This feature requires APM Server v7.3 or later and that the APM Server is
|
|
271
287
|
|
272
288
|
[float]
|
273
289
|
[[config-custom-key-filters]]
|
274
|
-
==== `custom_key_filters`
|
290
|
+
==== `custom_key_filters` deprecated:[3.5.0,See <<config-sanitize-field-names>> instead.]
|
275
291
|
[options="header"]
|
276
292
|
|============
|
277
293
|
| Environment | `Config` key | Default | Example
|
@@ -286,6 +302,8 @@ Use this option to add your own custom header keys to the list of filtered keys.
|
|
286
302
|
When setting this option via `ENV`, use a comma separated string.
|
287
303
|
Eg. `ELASTIC_APM_CUSTOM_KEY_FILTERS="a,b" # => [/a/, /b/]`
|
288
304
|
|
305
|
+
NOTE: This option is being removed. See <<config-sanitize-field-names>> instead.
|
306
|
+
|
289
307
|
[float]
|
290
308
|
[[config-default-tags]]
|
291
309
|
==== `default_tags`
|
@@ -328,6 +346,7 @@ that are set will override `global_labels`.
|
|
328
346
|
|
329
347
|
A comma-separated list of dotted metrics names that should not be sent to the APM Server.
|
330
348
|
You can use `*` to match multiple metrics.
|
349
|
+
Matching is case-insensitive.
|
331
350
|
|
332
351
|
[float]
|
333
352
|
[[config-disable-send]]
|
@@ -351,12 +370,12 @@ Disables the agent's startup message announcing itself.
|
|
351
370
|
|
352
371
|
[float]
|
353
372
|
[[config-disabled-instrumentations]]
|
354
|
-
==== `
|
373
|
+
==== `disable_instrumentations`
|
355
374
|
|
356
375
|
[options="header"]
|
357
376
|
|============
|
358
|
-
| Environment
|
359
|
-
| `
|
377
|
+
| Environment | `Config` key | Default
|
378
|
+
| `ELASTIC_APM_DISABLE_INSTRUMENTATIONS` | `disable_instrumentations` | `['json']`
|
360
379
|
|============
|
361
380
|
|
362
381
|
Elastic APM automatically instruments select third party libraries.
|
@@ -591,6 +610,24 @@ There are also `ENV` version of these following the same pattern of putting `ELA
|
|
591
610
|
|
592
611
|
See https://github.com/httprb/http/wiki/Proxy-Support[Http.rb's docs].
|
593
612
|
|
613
|
+
[float]
|
614
|
+
[[config-sanitize-field-names]]
|
615
|
+
==== `sanitize_field_names`
|
616
|
+
|
617
|
+
[options="header"]
|
618
|
+
|============
|
619
|
+
| Environment | `Config` key | Default | Example
|
620
|
+
| `ELASTIC_APM_SANITIZE_FIELD_NAMES` | `sanitize_field_names` | `[]` | `Auth*tion,abc*,*xyz`
|
621
|
+
|============
|
622
|
+
|
623
|
+
Sometimes it is necessary to sanitize the data sent to Elastic APM, e.g. remove sensitive data.
|
624
|
+
|
625
|
+
Configure a list of wildcard patterns of field names which should be sanitized. These apply to HTTP headers and bodies (if you're capturing those.)
|
626
|
+
|
627
|
+
Supports the wildcard `*`, which matches zero or more characters.
|
628
|
+
Examples: `/foo/*/bar/*/baz*`, `*foo*`.
|
629
|
+
Matching is case insensitive.
|
630
|
+
|
594
631
|
[float]
|
595
632
|
[[config-service-name]]
|
596
633
|
==== `service_name`
|
data/lib/elastic_apm/agent.rb
CHANGED
data/lib/elastic_apm/config.rb
CHANGED
@@ -32,12 +32,11 @@ module ElasticAPM
|
|
32
32
|
option :current_user_id_method, type: :string, default: 'id'
|
33
33
|
option :current_user_username_method, type: :string, default: 'username'
|
34
34
|
option :custom_key_filters, type: :list, default: [], converter: RegexpList.new
|
35
|
-
option :default_tags, type: :dict, default: {}
|
36
35
|
option :default_labels, type: :dict, default: {}
|
37
36
|
option :disable_metrics, type: :list, default: [], converter: WildcardPatternList.new
|
38
37
|
option :disable_send, type: :bool, default: false
|
39
38
|
option :disable_start_message, type: :bool, default: false
|
40
|
-
option :
|
39
|
+
option :disable_instrumentations, type: :list, default: %w[json]
|
41
40
|
option :disabled_spies, type: :list, default: []
|
42
41
|
option :environment, type: :string, default: ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
43
42
|
option :framework_name, type: :string
|
@@ -58,6 +57,7 @@ module ElasticAPM
|
|
58
57
|
option :proxy_password, type: :string
|
59
58
|
option :proxy_port, type: :int
|
60
59
|
option :proxy_username, type: :string
|
60
|
+
option :sanitize_field_names, type: :list, default: [], converter: WildcardPatternList.new
|
61
61
|
option :server_ca_cert, type: :string
|
62
62
|
option :service_name, type: :string
|
63
63
|
option :service_version, type: :string
|
@@ -69,10 +69,10 @@ module ElasticAPM
|
|
69
69
|
option :stack_trace_limit, type: :int, default: 999_999
|
70
70
|
option :transaction_max_spans, type: :int, default: 500
|
71
71
|
option :transaction_sample_rate, type: :float, default: 1.0
|
72
|
+
option :use_elastic_traceparent_header, type: :bool, default: true
|
73
|
+
option :use_experimental_sql_parser, type: :bool, default: false
|
72
74
|
option :verify_server_cert, type: :bool, default: true
|
73
75
|
|
74
|
-
option :use_experimental_sql_parser, type: :bool, default: false
|
75
|
-
|
76
76
|
# rubocop:enable Metrics/LineLength, Layout/ExtraSpacing
|
77
77
|
def initialize(options = {})
|
78
78
|
@options = load_schema
|
@@ -129,7 +129,7 @@ module ElasticAPM
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def enabled_instrumentations
|
132
|
-
available_instrumentations -
|
132
|
+
available_instrumentations - disable_instrumentations
|
133
133
|
end
|
134
134
|
|
135
135
|
def method_missing(name, *args)
|
@@ -194,6 +194,33 @@ module ElasticAPM
|
|
194
194
|
super.split.first + '>'
|
195
195
|
end
|
196
196
|
|
197
|
+
# Deprecations
|
198
|
+
|
199
|
+
def default_tags=(value)
|
200
|
+
warn '[DEPRECATED] The option default_tags has been renamed to ' \
|
201
|
+
'default_labels.'
|
202
|
+
self.default_labels = value
|
203
|
+
end
|
204
|
+
|
205
|
+
def custom_key_filters=(value)
|
206
|
+
unless value == self.class.schema[:custom_key_filters][:default]
|
207
|
+
warn '[DEPRECATED] The option custom_key_filters is being removed. ' \
|
208
|
+
'See sanitize_field_names for an alternative.'
|
209
|
+
end
|
210
|
+
|
211
|
+
set(:custom_key_filters, value)
|
212
|
+
end
|
213
|
+
|
214
|
+
def disabled_instrumentations
|
215
|
+
disable_instrumentations
|
216
|
+
end
|
217
|
+
|
218
|
+
def disabled_instrumentations=(value)
|
219
|
+
warn '[DEPRECATED] The option disabled_instrumentations has been ' \
|
220
|
+
'renamed to disable_instrumentations to align with other agents.'
|
221
|
+
self.disable_instrumentations = value
|
222
|
+
end
|
223
|
+
|
197
224
|
private
|
198
225
|
|
199
226
|
def load_config_file
|
@@ -14,6 +14,8 @@ module ElasticAPM
|
|
14
14
|
!!@pattern.match(other)
|
15
15
|
end
|
16
16
|
|
17
|
+
alias :match :match?
|
18
|
+
|
17
19
|
private
|
18
20
|
|
19
21
|
def convert(str)
|
@@ -22,7 +24,7 @@ module ElasticAPM
|
|
22
24
|
arr << (char == '*' ? '.*' : Regexp.escape(char))
|
23
25
|
end
|
24
26
|
|
25
|
-
Regexp.new('\A' + parts.join + '\Z')
|
27
|
+
Regexp.new('\A' + parts.join + '\Z', Regexp::IGNORECASE)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -37,13 +37,15 @@ module ElasticAPM
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def collect
|
40
|
-
|
40
|
+
@mutex.synchronize do
|
41
|
+
collected = @value
|
41
42
|
|
42
|
-
|
43
|
+
@value = initial_value if reset_on_collect?
|
43
44
|
|
44
|
-
|
45
|
+
return nil if reset_on_collect? && collected == 0
|
45
46
|
|
46
|
-
|
47
|
+
collected
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -56,10 +56,9 @@ module ElasticAPM
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def trace_context(env)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
warn "Couldn't parse invalid traceparent header: #{header.inspect}"
|
59
|
+
TraceContext.parse(env: env)
|
60
|
+
rescue TraceContext::InvalidTraceparentHeader => e
|
61
|
+
warn e.message
|
63
62
|
nil
|
64
63
|
end
|
65
64
|
|
@@ -277,7 +277,8 @@ module ElasticAPM
|
|
277
277
|
def inject(span_context, format, carrier)
|
278
278
|
case format
|
279
279
|
when ::OpenTracing::FORMAT_RACK
|
280
|
-
carrier['elastic-apm-traceparent'] =
|
280
|
+
carrier['elastic-apm-traceparent'] =
|
281
|
+
span_context.traceparent.to_header
|
281
282
|
else
|
282
283
|
warn 'Only injection via HTTP headers and Rack is available'
|
283
284
|
end
|
@@ -5,14 +5,21 @@ module ElasticAPM
|
|
5
5
|
class Context
|
6
6
|
# @api private
|
7
7
|
class Db
|
8
|
-
def initialize(
|
8
|
+
def initialize(
|
9
|
+
instance: nil,
|
10
|
+
statement: nil,
|
11
|
+
type: nil,
|
12
|
+
user: nil,
|
13
|
+
rows_affected: nil
|
14
|
+
)
|
9
15
|
@instance = instance
|
10
16
|
@statement = statement
|
11
17
|
@type = type
|
12
18
|
@user = user
|
19
|
+
@rows_affected = rows_affected
|
13
20
|
end
|
14
21
|
|
15
|
-
attr_accessor :instance, :statement, :type, :user
|
22
|
+
attr_accessor :instance, :statement, :type, :user, :rows_affected
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -36,7 +36,8 @@ module ElasticAPM
|
|
36
36
|
context: context
|
37
37
|
) do |span|
|
38
38
|
trace_context = span&.trace_context || transaction.trace_context
|
39
|
-
req[
|
39
|
+
trace_context.apply_headers { |key, value| req[key] = value }
|
40
|
+
|
40
41
|
result = perform_without_apm(req, options)
|
41
42
|
|
42
43
|
if (http = span&.context&.http)
|
@@ -67,7 +67,8 @@ module ElasticAPM
|
|
67
67
|
context: context
|
68
68
|
) do |span|
|
69
69
|
trace_context = span&.trace_context || transaction.trace_context
|
70
|
-
req[
|
70
|
+
trace_context.apply_headers { |key, value| req[key] = value }
|
71
|
+
|
71
72
|
result = request_without_apm(req, body, &block)
|
72
73
|
|
73
74
|
if (http = span&.context&.http)
|
@@ -37,14 +37,24 @@ module ElasticAPM
|
|
37
37
|
destination: { name: subtype, resource: subtype, type: TYPE }
|
38
38
|
)
|
39
39
|
|
40
|
-
ElasticAPM.
|
40
|
+
span = ElasticAPM.start_span(
|
41
41
|
name,
|
42
42
|
TYPE,
|
43
43
|
subtype: subtype,
|
44
44
|
action: ACTION,
|
45
|
-
context: context
|
46
|
-
&block
|
45
|
+
context: context
|
47
46
|
)
|
47
|
+
yield.tap do |result|
|
48
|
+
if name =~ /^(UPDATE|DELETE)/
|
49
|
+
if connection.respond_to?(:changes)
|
50
|
+
span.context.db.rows_affected = connection.changes
|
51
|
+
elsif result.is_a?(Integer)
|
52
|
+
span.context.db.rows_affected = result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ensure
|
57
|
+
ElasticAPM.end_span
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
@@ -1,82 +1,78 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'elastic_apm/trace_context/tracestate'
|
4
|
+
require 'elastic_apm/trace_context/traceparent'
|
5
|
+
|
3
6
|
module ElasticAPM
|
4
7
|
# @api private
|
5
8
|
class TraceContext
|
6
|
-
|
7
|
-
|
8
|
-
VERSION = '00'
|
9
|
-
HEX_REGEX = /[^[:xdigit:]]/.freeze
|
9
|
+
extend Forwardable
|
10
10
|
|
11
|
-
|
12
|
-
ID_LENGTH = 8
|
11
|
+
class InvalidTraceparentHeader < StandardError; end
|
13
12
|
|
14
13
|
def initialize(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
id: nil,
|
19
|
-
recorded: true
|
14
|
+
traceparent: nil,
|
15
|
+
tracestate: nil,
|
16
|
+
**legacy_traceparent_attrs
|
20
17
|
)
|
21
|
-
@
|
22
|
-
@
|
23
|
-
# TODO: rename to parent_id with next major version bump
|
24
|
-
@parent_id = span_id
|
25
|
-
@id = id || hex(ID_LENGTH)
|
26
|
-
@recorded = recorded
|
18
|
+
@traceparent = traceparent || Traceparent.new(**legacy_traceparent_attrs)
|
19
|
+
@tracestate = tracestate
|
27
20
|
end
|
28
21
|
|
29
|
-
attr_accessor :
|
22
|
+
attr_accessor :traceparent, :tracestate
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
raise InvalidTraceparentHeader unless header.length == 55
|
34
|
-
raise InvalidTraceparentHeader unless header[0..1] == VERSION
|
24
|
+
def_delegators :traceparent,
|
25
|
+
:version, :trace_id, :id, :parent_id, :ensure_parent_id, :recorded?
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
class << self
|
28
|
+
def parse(legacy_header = nil, env: nil)
|
29
|
+
if !legacy_header && !env
|
30
|
+
raise ArgumentError, 'TraceContext expects either env: or single ' \
|
31
|
+
'argument header string'
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
raise InvalidTraceparentHeader if HEX_REGEX =~ t.parent_id
|
44
|
-
end
|
45
|
-
end
|
34
|
+
return legacy_parse_from_header(legacy_header) if legacy_header
|
46
35
|
|
47
|
-
|
48
|
-
@flags = flags
|
36
|
+
return unless (header = get_traceparent_header(env))
|
49
37
|
|
50
|
-
|
51
|
-
end
|
38
|
+
parent = TraceContext::Traceparent.parse(header)
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
|
40
|
+
state =
|
41
|
+
if (header = env['HTTP_TRACESTATE'])
|
42
|
+
TraceContext::Tracestate.parse(header)
|
43
|
+
end
|
56
44
|
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
new(traceparent: parent, tracestate: state)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def legacy_parse_from_header(header)
|
51
|
+
parent = Traceparent.parse(header)
|
52
|
+
new(traceparent: parent)
|
53
|
+
end
|
60
54
|
|
61
|
-
|
62
|
-
|
55
|
+
def get_traceparent_header(env)
|
56
|
+
env['HTTP_ELASTIC_APM_TRACEPARENT'] || env['HTTP_TRACEPARENT']
|
57
|
+
end
|
63
58
|
end
|
64
59
|
|
65
60
|
def child
|
66
61
|
dup.tap do |tc|
|
67
|
-
tc.
|
68
|
-
tc.id = hex(ID_LENGTH)
|
62
|
+
tc.traceparent = tc.traceparent.child
|
69
63
|
end
|
70
64
|
end
|
71
65
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
66
|
+
def apply_headers
|
67
|
+
yield 'Traceparent', traceparent.to_header
|
68
|
+
|
69
|
+
if tracestate
|
70
|
+
yield 'Tracestate', tracestate.to_header
|
71
|
+
end
|
75
72
|
|
76
|
-
|
73
|
+
return unless ElasticAPM.agent.config.use_elastic_traceparent_header
|
77
74
|
|
78
|
-
|
79
|
-
SecureRandom.hex(len)
|
75
|
+
yield 'Elastic-Apm-Traceparent', traceparent.to_header
|
80
76
|
end
|
81
77
|
end
|
82
78
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElasticAPM
|
4
|
+
class TraceContext
|
5
|
+
# @api private
|
6
|
+
class Traceparent
|
7
|
+
VERSION = '00'
|
8
|
+
HEX_REGEX = /[^[:xdigit:]]/.freeze
|
9
|
+
|
10
|
+
TRACE_ID_LENGTH = 16
|
11
|
+
ID_LENGTH = 8
|
12
|
+
|
13
|
+
# rubocop:disable Metrics/ParameterLists
|
14
|
+
def initialize(
|
15
|
+
version: VERSION,
|
16
|
+
trace_id: nil,
|
17
|
+
span_id: nil,
|
18
|
+
id: nil,
|
19
|
+
recorded: true,
|
20
|
+
tracestate: nil
|
21
|
+
)
|
22
|
+
@version = version
|
23
|
+
@trace_id = trace_id || hex(TRACE_ID_LENGTH)
|
24
|
+
# TODO: rename span_id kw arg to parent_id with next major version bump
|
25
|
+
@parent_id = span_id
|
26
|
+
@id = id || hex(ID_LENGTH)
|
27
|
+
@recorded = recorded
|
28
|
+
@tracestate = tracestate
|
29
|
+
end
|
30
|
+
# rubocop:enable Metrics/ParameterLists
|
31
|
+
|
32
|
+
attr_accessor :version, :id, :trace_id, :parent_id, :recorded, :tracestate
|
33
|
+
|
34
|
+
alias :recorded? :recorded
|
35
|
+
|
36
|
+
def self.parse(header)
|
37
|
+
raise_invalid(header) unless header.length == 55
|
38
|
+
raise_invalid(header) unless header[0..1] == VERSION
|
39
|
+
|
40
|
+
new.tap do |t|
|
41
|
+
t.version, t.trace_id, t.parent_id, t.flags =
|
42
|
+
header.split('-').tap do |values|
|
43
|
+
values[-1] = Util.hex_to_bits(values[-1])
|
44
|
+
end
|
45
|
+
|
46
|
+
raise_invalid(header) if HEX_REGEX =~ t.trace_id
|
47
|
+
raise_invalid(header) if HEX_REGEX =~ t.parent_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class << self
|
52
|
+
private
|
53
|
+
|
54
|
+
def raise_invalid(header)
|
55
|
+
raise InvalidTraceparentHeader,
|
56
|
+
"Couldn't parse invalid traceparent header: #{header.inspect}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def flags=(flags)
|
61
|
+
@flags = flags
|
62
|
+
|
63
|
+
self.recorded = flags[7] == '1'
|
64
|
+
end
|
65
|
+
|
66
|
+
def flags
|
67
|
+
format('0000000%d', recorded? ? 1 : 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
def hex_flags
|
71
|
+
format('%02x', flags.to_i(2))
|
72
|
+
end
|
73
|
+
|
74
|
+
def ensure_parent_id
|
75
|
+
@parent_id ||= hex(ID_LENGTH)
|
76
|
+
end
|
77
|
+
|
78
|
+
def child
|
79
|
+
dup.tap do |copy|
|
80
|
+
copy.parent_id = id
|
81
|
+
copy.id = hex(ID_LENGTH)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_header
|
86
|
+
format('%s-%s-%s-%s', version, trace_id, id, hex_flags)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def hex(len)
|
92
|
+
SecureRandom.hex(len)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElasticAPM
|
4
|
+
class TraceContext
|
5
|
+
# @api private
|
6
|
+
class Tracestate
|
7
|
+
def initialize(values = [])
|
8
|
+
@values = values
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :values
|
12
|
+
|
13
|
+
def self.parse(header)
|
14
|
+
# HTTP allows multiple headers with the same name, eg. multiple
|
15
|
+
# Set-Cookie headers per response.
|
16
|
+
# Rack handles this by joining the headers under the same key, separated
|
17
|
+
# by newlines, see https://www.rubydoc.info/github/rack/rack/file/SPEC
|
18
|
+
new(String(header).split("\n"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_header
|
22
|
+
values.join(',')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -25,7 +25,10 @@ module ElasticAPM
|
|
25
25
|
|
26
26
|
def initialize(config)
|
27
27
|
@config = config
|
28
|
-
@key_filters =
|
28
|
+
@key_filters =
|
29
|
+
KEY_FILTERS +
|
30
|
+
config.custom_key_filters +
|
31
|
+
config.sanitize_field_names
|
29
32
|
end
|
30
33
|
|
31
34
|
def call(payload)
|
@@ -60,11 +63,11 @@ module ElasticAPM
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def filter_key?(key)
|
63
|
-
@key_filters.any? { |regex|
|
66
|
+
@key_filters.any? { |regex| regex.match(key) }
|
64
67
|
end
|
65
68
|
|
66
69
|
def filter_value?(value)
|
67
|
-
VALUE_FILTERS.any? { |regex|
|
70
|
+
VALUE_FILTERS.any? { |regex| regex.match(value) }
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
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: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- ".ci/jobs/apm-agent-ruby.yml"
|
59
59
|
- ".ci/jobs/defaults.yml"
|
60
60
|
- ".ci/linting.groovy"
|
61
|
+
- ".ci/packer_cache.sh"
|
61
62
|
- ".ci/prepare-git-context.sh"
|
62
63
|
- ".github/ISSUE_TEMPLATE/Bug_report.md"
|
63
64
|
- ".github/ISSUE_TEMPLATE/Feature_request.md"
|
@@ -197,6 +198,8 @@ files:
|
|
197
198
|
- lib/elastic_apm/stacktrace_builder.rb
|
198
199
|
- lib/elastic_apm/subscriber.rb
|
199
200
|
- lib/elastic_apm/trace_context.rb
|
201
|
+
- lib/elastic_apm/trace_context/traceparent.rb
|
202
|
+
- lib/elastic_apm/trace_context/tracestate.rb
|
200
203
|
- lib/elastic_apm/transaction.rb
|
201
204
|
- lib/elastic_apm/transport/base.rb
|
202
205
|
- lib/elastic_apm/transport/connection.rb
|