elastic-apm 4.6.2 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.exclude.yml +193 -0
  3. data/.ci/.ruby.yml +10 -0
  4. data/.ci/scripts/bench.sh +52 -0
  5. data/.ci/scripts/install-build-system.sh +5 -0
  6. data/.ci/snapshoty.yml +2 -3
  7. data/.ci/updatecli.d/update-gherkin-specs.yml +117 -0
  8. data/.ci/updatecli.d/update-json-specs.yml +121 -0
  9. data/.github/workflows/ci-docs.yml +20 -0
  10. data/.github/workflows/ci.yml +70 -0
  11. data/.github/workflows/coverage-reporter.yml +34 -0
  12. data/.github/workflows/microbenchmark.yml +48 -0
  13. data/.github/workflows/opentelemetry.yml +27 -0
  14. data/.github/workflows/release.yml +71 -0
  15. data/.github/workflows/run-matrix.yml +56 -0
  16. data/.github/workflows/snapshoty.yml +35 -0
  17. data/.github/workflows/test-reporter.yml +24 -0
  18. data/.github/workflows/{update-specs.yml → updatecli.yml} +2 -4
  19. data/.pre-commit-config.yaml +0 -2
  20. data/CHANGELOG.asciidoc +12 -0
  21. data/Gemfile +4 -0
  22. data/README.md +1 -1
  23. data/bench/rubyprof.rb +1 -0
  24. data/bin/run-tests +10 -1
  25. data/docker-compose.yml +4 -1
  26. data/docs/configuration.asciidoc +6 -5
  27. data/docs/index.asciidoc +2 -2
  28. data/docs/{log-correlation.asciidoc → logs.asciidoc} +29 -2
  29. data/docs/opentracing.asciidoc +1 -1
  30. data/docs/redirects.asciidoc +9 -0
  31. data/lib/elastic_apm/context_builder.rb +3 -3
  32. data/lib/elastic_apm/metrics.rb +24 -20
  33. data/lib/elastic_apm/span_helpers.rb +6 -6
  34. data/lib/elastic_apm/spies/faraday.rb +1 -1
  35. data/lib/elastic_apm/version.rb +1 -1
  36. metadata +24 -19
  37. data/.ci/.jenkins_exclude.yml +0 -191
  38. data/.ci/.jenkins_ruby.yml +0 -10
  39. data/.ci/.jenkins_ruby_benchmarks.yml +0 -6
  40. data/.ci/Jenkinsfile +0 -450
  41. data/.ci/jobs/apm-agent-ruby-downstream.yml +0 -38
  42. data/.ci/jobs/apm-agent-ruby-linting-mbp.yml +0 -39
  43. data/.ci/jobs/apm-agent-ruby-mbp.yml +0 -43
  44. data/.ci/jobs/apm-agent-ruby.yml +0 -4
  45. data/.ci/jobs/defaults.yml +0 -24
  46. data/.ci/linting.groovy +0 -32
  47. data/.ci/packer_cache.sh +0 -16
  48. /data/.ci/{.jenkins_codecov.yml → .codecov.yml} +0 -0
  49. /data/.ci/{.jenkins_framework.yml → .framework.yml} +0 -0
  50. /data/.ci/{.jenkins_main_framework.yml → .main_framework.yml} +0 -0
  51. /data/.ci/{update-specs.yml → updatecli.d/update-specs.yml} +0 -0
@@ -0,0 +1,48 @@
1
+ name: microbenchmark
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - main
8
+ paths-ignore:
9
+ - '**.md'
10
+ - '**.asciidoc'
11
+
12
+ # limit the access of the generated GITHUB_TOKEN
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ microbenchmark:
18
+ runs-on: ubuntu-latest
19
+ # wait up to 1 hour
20
+ timeout-minutes: 60
21
+ steps:
22
+ - id: buildkite
23
+ name: Run buildkite pipeline
24
+ uses: elastic/apm-pipeline-library/.github/actions/buildkite@current
25
+ with:
26
+ vaultUrl: ${{ secrets.VAULT_ADDR }}
27
+ vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
28
+ vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
29
+ pipeline: apm-agent-microbenchmark
30
+ triggerMessage: "${{ github.repository }}@${{ github.ref_name }}"
31
+ waitFor: true
32
+ printBuildLogs: true
33
+ buildEnvVars: |
34
+ script=.ci/scripts/bench.sh
35
+ repo=apm-agent-ruby
36
+ sha=${{ github.sha }}
37
+ BRANCH_NAME=${{ github.ref_name }}
38
+
39
+ - if: ${{ failure() }}
40
+ uses: elastic/apm-pipeline-library/.github/actions/slack-message@current
41
+ with:
42
+ url: ${{ secrets.VAULT_ADDR }}
43
+ roleId: ${{ secrets.VAULT_ROLE_ID }}
44
+ secretId: ${{ secrets.VAULT_SECRET_ID }}
45
+ channel: "#apm-agent-ruby"
46
+ message: |
47
+ :ghost: [${{ github.repository }}] microbenchmark *${{ github.ref_name }}* failed to run in Buildkite.
48
+ Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>)
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: OpenTelemetry Export Trace
3
+
4
+ on:
5
+ workflow_run:
6
+ workflows:
7
+ - Auto Assign to Project(s)
8
+ - Issue Labeler
9
+ - ci
10
+ - coverage-reporter
11
+ - microbenchmark
12
+ - release
13
+ - run-matrix
14
+ - snapshoty
15
+ - test-reporter
16
+ - updatecli
17
+ types: [completed]
18
+
19
+ jobs:
20
+ otel-export-trace:
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: elastic/apm-pipeline-library/.github/actions/opentelemetry@current
24
+ with:
25
+ vaultUrl: ${{ secrets.VAULT_ADDR }}
26
+ vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
27
+ vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
@@ -0,0 +1,71 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v[0-9]+*"
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ release:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6
19
+ - uses: hashicorp/vault-action@v2.4.2
20
+ with:
21
+ url: ${{ secrets.VAULT_ADDR }}
22
+ method: approle
23
+ roleId: ${{ secrets.VAULT_ROLE_ID }}
24
+ secretId: ${{ secrets.VAULT_SECRET_ID }}
25
+ secrets: |
26
+ secret/apm-team/ci/apm-agent-ruby-rubygems-release apiKey | API_KEY ;
27
+ - name: RubyGems login
28
+ run: |
29
+ RUBY_HOME="${HOME}/.gem"
30
+ RUBY_CREDENTIALS_FILE="${RUBY_HOME}/credentials"
31
+ mkdir -p "${RUBY_HOME}"
32
+ echo '---' > "${RUBY_CREDENTIALS_FILE}"
33
+ echo ":rubygems_api_key: ${API_KEY}" >> "${RUBY_CREDENTIALS_FILE}"
34
+ chmod 0600 "${RUBY_CREDENTIALS_FILE}"
35
+ - name: Install build system
36
+ run: .ci/scripts/install-build-system.sh
37
+ - run: rake release
38
+ update-branch:
39
+ needs:
40
+ - release
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v3
44
+ - uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: 2.6
47
+ - name: Setup Git
48
+ uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
49
+ - name: Install build system
50
+ run: .ci/scripts/install-build-system.sh
51
+ - run: rake release:update_branch
52
+
53
+ status:
54
+ if: always()
55
+ runs-on: ubuntu-latest
56
+ needs:
57
+ - release
58
+ - update-branch
59
+ steps:
60
+ - id: check
61
+ uses: elastic/apm-pipeline-library/.github/actions/check-dependent-jobs@current
62
+ with:
63
+ needs: ${{ toJSON(needs) }}
64
+ - run: ${{ steps.check.outputs.isSuccess }}
65
+ - if: always()
66
+ uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
67
+ with:
68
+ vaultUrl: ${{ secrets.VAULT_ADDR }}
69
+ vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
70
+ vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
71
+ slackChannel: "#apm-agent-ruby"
@@ -0,0 +1,56 @@
1
+ ---
2
+ # Runs the tests based on the provided files in ci.yml
3
+ name: run-matrix
4
+
5
+ on:
6
+ workflow_call:
7
+ inputs:
8
+ versionsFile:
9
+ required: true
10
+ type: string
11
+ frameworksFile:
12
+ required: true
13
+ type: string
14
+ excludedFile:
15
+ required: true
16
+ type: string
17
+
18
+ jobs:
19
+ create-test-matrix:
20
+ runs-on: ubuntu-latest
21
+ outputs:
22
+ matrix: ${{ steps.generate.outputs.matrix }}
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - id: generate
26
+ uses: elastic/apm-pipeline-library/.github/actions/version-framework@current
27
+ with:
28
+ versionsFile: ${{ inputs.versionsFile }}
29
+ frameworksFile: ${{ inputs.frameworksFile }}
30
+ excludedFile: ${{ inputs.excludedFile }}
31
+ test:
32
+ needs:
33
+ - create-test-matrix
34
+ runs-on: ubuntu-latest
35
+ strategy:
36
+ fail-fast: false
37
+ max-parallel: 20
38
+ matrix: ${{ fromJSON(needs.create-test-matrix.outputs.matrix) }}
39
+ steps:
40
+ - uses: actions/checkout@v3
41
+ - name: Run BDD tests
42
+ run: ./spec/scripts/features.sh ${{ matrix.version }}
43
+ - name: Run test
44
+ run: ./spec/scripts/spec.sh ${{ matrix.version }} ${{ matrix.framework }}
45
+ env:
46
+ JUNIT_PREFIX: ${{ matrix.version }}-${{ matrix.framework }}
47
+ - if: success() || failure()
48
+ uses: actions/upload-artifact@v3
49
+ with:
50
+ name: test-results
51
+ path: "**/spec/junit-reports/**/*ruby-agent-junit.xml"
52
+ - if: success() || failure()
53
+ uses: actions/upload-artifact@v3
54
+ with:
55
+ name: coverage
56
+ path: "coverage/"
@@ -0,0 +1,35 @@
1
+ name: snapshoty
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows:
6
+ - ci
7
+ types:
8
+ - completed
9
+ branches:
10
+ - main
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ publish:
17
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Download artifacts
22
+ run: >
23
+ gh run download ${{ github.event.workflow_run.id }}
24
+ --name package
25
+ --repo "${GITHUB_REPOSITORY}"
26
+ --dir pkg
27
+ env:
28
+ GH_TOKEN: ${{ github.token }}
29
+ - name: Publish snapshot
30
+ uses: elastic/apm-pipeline-library/.github/actions/snapshoty-simple@current
31
+ with:
32
+ config: '.ci/snapshoty.yml'
33
+ vaultUrl: ${{ secrets.VAULT_ADDR }}
34
+ vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
35
+ vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
@@ -0,0 +1,24 @@
1
+ ---
2
+ ## Workflow to process the JUnit test results and add a report to the checks.
3
+ name: test-reporter
4
+ on:
5
+ workflow_run:
6
+ workflows:
7
+ - ci
8
+ types:
9
+ - completed
10
+
11
+ permissions:
12
+ contents: read
13
+ checks: write
14
+
15
+ jobs:
16
+ report:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: elastic/apm-pipeline-library/.github/actions/test-report@current
20
+ with:
21
+ artifact: test-results
22
+ name: test-report
23
+ path: "**/*ruby-agent-junit.xml"
24
+ reporter: java-junit
@@ -1,4 +1,4 @@
1
- name: update-specs
1
+ name: updatecli
2
2
 
3
3
  on:
4
4
  workflow_dispatch: ~
@@ -14,13 +14,11 @@ jobs:
14
14
  steps:
15
15
  - uses: actions/checkout@v3
16
16
  - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current
17
- env:
18
- BRANCH_NAME: ${{ github.ref_name }}
19
17
  with:
20
18
  vaultUrl: ${{ secrets.VAULT_ADDR }}
21
19
  vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
22
20
  vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
23
- pipeline: ./.ci/update-specs.yml
21
+ pipeline: .ci/updatecli.d
24
22
  - if: failure()
25
23
  uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
26
24
  with:
@@ -13,6 +13,4 @@ repos:
13
13
  rev: current
14
14
  hooks:
15
15
  - id: check-bash-syntax
16
- - id: check-jenkins-pipelines
17
- - id: check-jjbb
18
16
  - id: check-unicode-non-breaking-spaces
data/CHANGELOG.asciidoc CHANGED
@@ -34,6 +34,18 @@ endif::[]
34
34
  [[release-notes-4.x]]
35
35
  === Ruby Agent version 4.x
36
36
 
37
+ [[release-notes-4.7.0]]
38
+ ==== 4.7.0
39
+
40
+ [float]
41
+ ===== Fixed
42
+ - Handle Faraday response being nil {pull}1382[#1382]
43
+ - Fix error with invalid %-encoding {pull}1400[#1400]
44
+
45
+ [float]
46
+ ===== Added
47
+ - Add keyword args for span_method helper {pull}1395[#1395]
48
+
37
49
  [[release-notes-4.6.2]]
38
50
  ==== 4.6.2
39
51
 
data/Gemfile CHANGED
@@ -62,6 +62,10 @@ gem 'sucker_punch', '~> 2.0', require: nil
62
62
  gem 'yard', require: nil
63
63
  gem 'yarjuf'
64
64
 
65
+ if RUBY_VERSION < '2.5'
66
+ gem 'loofah', '~> 2.20.0', require: nil
67
+ end
68
+
65
69
  ## Install Framework
66
70
  GITHUB_REPOS = {
67
71
  'grape' => 'ruby-grape/grape',
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Elastic APM agent for Ruby
4
4
 
5
- [![Jenkins](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-ruby/apm-agent-ruby-mbp/main)](https://apm-ci.elastic.co/job/apm-agent-ruby/job/apm-agent-ruby-mbp/job/main/) [![Gem](https://img.shields.io/gem/v/elastic-apm.svg)](https://rubygems.org/gems/elastic-apm)
5
+ [![ci](https://github.com/elastic/apm-agent-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/elastic/apm-agent-ruby/actions/workflows/ci.yml) [![Gem](https://img.shields.io/gem/v/elastic-apm.svg)](https://rubygems.org/gems/elastic-apm)
6
6
 
7
7
  The official Rubygem for [Elastic][] [APM][].
8
8
 
data/bench/rubyprof.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'ruby-prof'
data/bin/run-tests CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/bin/bash
2
2
  set -e
3
3
 
4
+ JUNIT_PREFIX=${JUNIT_PREFIX:-""}
5
+
4
6
  runRspec(){
5
7
  local case=${1:-""}
6
8
  local bn=${case}
@@ -8,9 +10,16 @@ runRspec(){
8
10
  if [ -n "${case}" ]; then
9
11
  bn="$(basename ${case} _spec.rb)/"
10
12
  fi
13
+ # If working on an isolated environment then copy the file to
14
+ # the original location
15
+ TEST_REPORT_DIR=spec/junit-reports/${JUNIT_PREFIX}${bn}
16
+ if [ -n "$APP_PATH" ] ; then
17
+ TEST_REPORT_DIR=$APP_PATH/$TEST_REPORT_DIR
18
+ mkdir -p $TEST_REPORT_DIR
19
+ fi
11
20
  bundle exec rspec \
12
21
  -f progress \
13
- -r yarjuf -f JUnit -o spec/junit-reports/${bn}ruby-agent-junit.xml \
22
+ -r yarjuf -f JUnit -o ${TEST_REPORT_DIR}ruby-agent-junit.xml \
14
23
  ${case}
15
24
  }
16
25
  specific_spec=$1
data/docker-compose.yml CHANGED
@@ -35,8 +35,11 @@ services:
35
35
  ruby_rspec:
36
36
  image: apm-agent-ruby:${RUBY_VERSION}
37
37
  environment:
38
+ APP_PATH: /opt/app
39
+ FRAMEWORK: rails
40
+ LOCAL_USER_ID: ${LOCAL_USER_ID}
41
+ LOCAL_GROUP_ID: ${LOCAL_GROUP_ID}
38
42
  MONGODB_URL: 'mongodb:27017'
39
- user: ${USER_ID}
40
43
  security_opt:
41
44
  - no-new-privileges
42
45
 
@@ -24,7 +24,7 @@ When using this method, strings are split by comma, e.g.,
24
24
  [[configuration-precedence]]
25
25
  === Configuration precedence
26
26
 
27
- Options are applied in the following order (last one wins):
27
+ Options are applied in the following order (last one wins):
28
28
 
29
29
  1. Defaults
30
30
  2. Arguments to `ElasticAPM.start` / `Config.new`
@@ -170,7 +170,7 @@ WARNING: Secret tokens only provide any real security if your APM server uses TL
170
170
  |============
171
171
 
172
172
  This base64-encoded string is used to ensure that only your agents can send data to your APM server.
173
- The API key must be created using the {apm-guide-ref}/api-key.html[APM server command-line tool].
173
+ The API key must be created using the {apm-guide-ref}/api-key.html[APM server command-line tool].
174
174
 
175
175
  WARNING: API keys only provide any real security if your APM server uses TLS.
176
176
 
@@ -199,7 +199,7 @@ The <<config-log-path,logs>> should tell you what went wrong.
199
199
  | `ELASTIC_APM_API_REQUEST_SIZE` | `api_request_size` | `"750kb"`
200
200
  |============
201
201
 
202
- The maximum amount of bytes sent over one request to APM Server. The agent will open a new request when this limit is reached.
202
+ The maximum amount of bytes sent over one request to APM Server. The agent will open a new request when this limit is reached.
203
203
 
204
204
  This must be provided in *<<config-format-size, size format>>*.
205
205
 
@@ -301,7 +301,8 @@ If set to `true`, the client will poll the APM Server regularly for new agent co
301
301
 
302
302
  Usually APM Server determines how often to poll, but if not, set the default interval is 5 minutes.
303
303
 
304
- NOTE: This feature requires APM Server v7.3 or later and that the APM Server is configured with `kibana.enabled: true`.
304
+ NOTE: This feature requires APM Server v7.3 or later.
305
+ See {kibana-ref}/agent-configuration.html[APM Agent central configuration] for more information.
305
306
 
306
307
  [float]
307
308
  [[config-cloud-provider]]
@@ -701,7 +702,7 @@ The name of the given service node. This is optional, and if omitted, the APM
701
702
  Server will fall back on `system.container.id` if available, and
702
703
  `host.name` if necessary.
703
704
 
704
- This option allows you to set the node name manually to ensure it's unique and meaningful.
705
+ This option allows you to set the node name manually to ensure it's unique and meaningful.
705
706
 
706
707
  [float]
707
708
  [[config-service-version]]
data/docs/index.asciidoc CHANGED
@@ -23,12 +23,12 @@ include::./api.asciidoc[]
23
23
 
24
24
  include::./metrics.asciidoc[]
25
25
 
26
+ include::./logs.asciidoc[]
27
+
26
28
  include::./opentracing.asciidoc[]
27
29
 
28
30
  include::./graphql.asciidoc[]
29
31
 
30
- include::./log-correlation.asciidoc[]
31
-
32
32
  include::./performance-tuning.asciidoc[]
33
33
 
34
34
  include::./debugging.asciidoc[]
@@ -3,8 +3,26 @@ NOTE: For the best reading experience,
3
3
  please view this documentation at https://www.elastic.co/guide/en/apm/agent/ruby[elastic.co]
4
4
  endif::[]
5
5
 
6
- [[log-correlation]]
7
- == Log correlation
6
+ [[logs]]
7
+ == Logs
8
+
9
+ Elastic Ruby APM Agent provides the following log features:
10
+
11
+ - <<log-correlation-ids>>: Automatically inject correlation IDs that allow navigation between logs, traces and services.
12
+ - <<log-reformatting>>: Automatically reformat plaintext logs in {ecs-logging-ref}/intro.html[ECS logging] format.
13
+
14
+ Those features are part of {observability-guide}/application-logs.html[Application log ingestion strategies].
15
+
16
+ The {ecs-logging-ruby-ref}/intro.html[`ecs-logging-ruby`] library can also be used to format logs in the {ecs-logging-ref}/intro.html[ECS logging] format without an APM agent.
17
+ When deployed with the Ruby APM agent, the agent will provide <<log-correlation-ids,log correlation>> IDs.
18
+
19
+ [float]
20
+ [[log-correlation-ids]]
21
+ === Log correlation
22
+
23
+ {apm-guide-ref}/log-correlation.html[Log correlation] allows you to navigate to all logs belonging to a particular trace
24
+ and vice-versa: for a specific log, see in which context it has been logged and which parameters the user provided.
25
+
8
26
 
9
27
  Trace/log correlation can be set up in three different ways.
10
28
 
@@ -119,3 +137,12 @@ PUT _ingest/pipeline/extract_trace_id
119
137
  ----
120
138
 
121
139
  Please see {apm-guide-ref}/log-correlation.html[Observability integrations] for more information.
140
+
141
+ [float]
142
+ [[log-reformatting]]
143
+ === Log reformatting (experimental)
144
+
145
+ Log reformatting is controlled by the <<config-log-ecs-formatting, `log_ecs_reformatting`>> configuration option, and is disabled by default.
146
+
147
+ The reformatted logs will include both the <<log-correlation-ids, trace and service correlation>> IDs.
148
+
@@ -89,6 +89,6 @@ The `Span.set_baggage` method is not supported.
89
89
  Baggage items are dropped with a warning log message.
90
90
 
91
91
  [float]
92
- [[logs]]
92
+ [[opentracing-logs]]
93
93
  === Logs
94
94
  Logs are currently not supported.
@@ -0,0 +1,9 @@
1
+ ["appendix",role="exclude",id="redirects"]
2
+ = Deleted pages
3
+
4
+ The following pages have moved or been deleted.
5
+
6
+ [role="exclude",id="log-correlation"]
7
+ === Log correlation
8
+
9
+ This section has moved. See <<logs>>.
@@ -44,7 +44,7 @@ module ElasticAPM
44
44
  request = context.request
45
45
 
46
46
  request.socket = Context::Request::Socket.new(req)
47
- request.http_version = build_http_version rack_env
47
+ request.http_version = build_http_version req
48
48
  request.method = req.request_method
49
49
  request.url = Context::Request::Url.new(req)
50
50
 
@@ -104,8 +104,8 @@ module ElasticAPM
104
104
  key.gsub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
105
105
  end
106
106
 
107
- def build_http_version(rack_env)
108
- return unless (http_version = rack_env['HTTP_VERSION'])
107
+ def build_http_version(req)
108
+ return unless (http_version = req.env['HTTP_VERSION'])
109
109
  http_version.gsub(%r{HTTP/}, '')
110
110
  end
111
111
  end
@@ -50,27 +50,9 @@ module ElasticAPM
50
50
  return
51
51
  end
52
52
 
53
- debug 'Starting metrics'
54
-
55
- # Only set the @sets once, in case we stop
56
- # and start again.
57
- if @sets.nil?
58
- sets = {
59
- system: CpuMemSet,
60
- vm: VMSet,
61
- breakdown: BreakdownSet,
62
- transaction: TransactionSet
63
- }
64
- if defined?(JVMSet)
65
- debug "Enabling JVM metrics collection"
66
- sets[:jvm] = JVMSet
67
- end
53
+ define_sets
68
54
 
69
- @sets = sets.each_with_object({}) do |(key, kls), _sets_|
70
- debug "Adding metrics collector '#{kls}'"
71
- _sets_[key] = kls.new(config)
72
- end
73
- end
55
+ debug 'Starting metrics'
74
56
 
75
57
  @timer_task = Concurrent::TimerTask.execute(
76
58
  run_now: true,
@@ -135,6 +117,28 @@ module ElasticAPM
135
117
  arr.concat(samples)
136
118
  end
137
119
  end
120
+
121
+ def define_sets
122
+ # Only set the @sets once, in case we stop
123
+ # and start again.
124
+ return unless @sets.nil?
125
+
126
+ sets = {
127
+ system: CpuMemSet,
128
+ vm: VMSet,
129
+ breakdown: BreakdownSet,
130
+ transaction: TransactionSet
131
+ }
132
+ if defined?(JVMSet)
133
+ debug "Enabling JVM metrics collection"
134
+ sets[:jvm] = JVMSet
135
+ end
136
+
137
+ @sets = sets.each_with_object({}) do |(key, kls), _sets_|
138
+ debug "Adding metrics collector '#{kls}'"
139
+ _sets_[key] = kls.new(config)
140
+ end
141
+ end
138
142
  end
139
143
  end
140
144
  end
@@ -22,17 +22,17 @@ module ElasticAPM
22
22
  module SpanHelpers
23
23
  # @api private
24
24
  module ClassMethods
25
- def span_class_method(method, name = nil, type = nil)
26
- __span_method_on(singleton_class, method, name, type)
25
+ def span_class_method(method, name = nil, type = nil, **kwargs)
26
+ __span_method_on(singleton_class, method, name, type, **kwargs)
27
27
  end
28
28
 
29
- def span_method(method, name = nil, type = nil)
30
- __span_method_on(self, method, name, type)
29
+ def span_method(method, name = nil, type = nil, **kwargs)
30
+ __span_method_on(self, method, name, type, **kwargs)
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- def __span_method_on(klass, method, name = nil, type = nil)
35
+ def __span_method_on(klass, method, name = nil, type = nil, **kwargs)
36
36
  name ||= method.to_s
37
37
  type ||= Span::DEFAULT_TYPE
38
38
 
@@ -42,7 +42,7 @@ module ElasticAPM
42
42
  return super(*args, &block)
43
43
  end
44
44
 
45
- ElasticAPM.with_span name.to_s, type.to_s do
45
+ ElasticAPM.with_span name.to_s, type.to_s, **kwargs do
46
46
  super(*args, &block)
47
47
  end
48
48
  end)
@@ -109,7 +109,7 @@ module ElasticAPM
109
109
  yield req if block
110
110
  end
111
111
  rescue Faraday::ClientError, Faraday::ServerError => e # Faraday::Response::RaiseError
112
- status = e.response[:status]
112
+ status = e.response_status
113
113
  http = span&.context&.http
114
114
  if http && status
115
115
  http.status_code = status.to_s
@@ -18,5 +18,5 @@
18
18
  # frozen_string_literal: true
19
19
 
20
20
  module ElasticAPM
21
- VERSION = '4.6.2'
21
+ VERSION = '4.7.0'
22
22
  end