elastic-apm 3.1.0 → 3.2.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.jenkins_exclude.yml +47 -0
  3. data/.ci/.jenkins_framework.yml +4 -0
  4. data/.ci/.jenkins_master_framework.yml +1 -0
  5. data/.ci/.jenkins_ruby.yml +1 -0
  6. data/.ci/downstreamTests.groovy +1 -1
  7. data/.gitignore +2 -1
  8. data/.rspec +1 -0
  9. data/CHANGELOG.asciidoc +24 -0
  10. data/Dockerfile +43 -0
  11. data/Gemfile +34 -15
  12. data/README.md +30 -1
  13. data/bin/dev +54 -0
  14. data/bin/run-tests +27 -0
  15. data/docker-compose.yml +32 -0
  16. data/docs/api.asciidoc +13 -2
  17. data/docs/configuration.asciidoc +30 -0
  18. data/docs/getting-started-rack.asciidoc +24 -0
  19. data/docs/release-notes.asciidoc +1 -1
  20. data/lib/elastic_apm.rb +12 -1
  21. data/lib/elastic_apm/agent.rb +15 -3
  22. data/lib/elastic_apm/central_config.rb +39 -19
  23. data/lib/elastic_apm/child_durations.rb +42 -0
  24. data/lib/elastic_apm/config.rb +27 -11
  25. data/lib/elastic_apm/context/request/socket.rb +1 -1
  26. data/lib/elastic_apm/context_builder.rb +1 -1
  27. data/lib/elastic_apm/error.rb +10 -0
  28. data/lib/elastic_apm/error/exception.rb +7 -0
  29. data/lib/elastic_apm/grape.rb +48 -0
  30. data/lib/elastic_apm/instrumenter.rb +77 -4
  31. data/lib/elastic_apm/logging.rb +0 -2
  32. data/lib/elastic_apm/metrics.rb +39 -26
  33. data/lib/elastic_apm/metrics/breakdown_set.rb +14 -0
  34. data/lib/elastic_apm/metrics/{cpu_mem.rb → cpu_mem_set.rb} +62 -54
  35. data/lib/elastic_apm/metrics/metric.rb +117 -0
  36. data/lib/elastic_apm/metrics/set.rb +106 -0
  37. data/lib/elastic_apm/metrics/span_scoped_set.rb +39 -0
  38. data/lib/elastic_apm/metrics/transaction_set.rb +11 -0
  39. data/lib/elastic_apm/metrics/vm_set.rb +44 -0
  40. data/lib/elastic_apm/metricset.rb +31 -4
  41. data/lib/elastic_apm/normalizers.rb +6 -0
  42. data/lib/elastic_apm/normalizers/grape.rb +5 -0
  43. data/lib/elastic_apm/normalizers/grape/endpoint_run.rb +47 -0
  44. data/lib/elastic_apm/normalizers/rails/active_record.rb +16 -5
  45. data/lib/elastic_apm/opentracing.rb +4 -4
  46. data/lib/elastic_apm/rails.rb +12 -2
  47. data/lib/elastic_apm/railtie.rb +1 -5
  48. data/lib/elastic_apm/sinatra.rb +1 -1
  49. data/lib/elastic_apm/span.rb +15 -10
  50. data/lib/elastic_apm/spies.rb +0 -1
  51. data/lib/elastic_apm/sql_summarizer.rb +8 -6
  52. data/lib/elastic_apm/subscriber.rb +4 -1
  53. data/lib/elastic_apm/transaction.rb +6 -6
  54. data/lib/elastic_apm/transport/base.rb +7 -0
  55. data/lib/elastic_apm/transport/connection.rb +11 -69
  56. data/lib/elastic_apm/transport/connection/http.rb +43 -35
  57. data/lib/elastic_apm/transport/connection/proxy_pipe.rb +0 -3
  58. data/lib/elastic_apm/transport/headers.rb +62 -0
  59. data/lib/elastic_apm/transport/serializers.rb +0 -2
  60. data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +19 -6
  61. data/lib/elastic_apm/transport/serializers/span_serializer.rb +3 -3
  62. data/lib/elastic_apm/transport/user_agent.rb +31 -0
  63. data/lib/elastic_apm/transport/worker.rb +1 -2
  64. data/lib/elastic_apm/version.rb +1 -1
  65. metadata +20 -6
  66. data/lib/elastic_apm/metrics/vm.rb +0 -60
  67. data/lib/elastic_apm/util/prefixed_logger.rb +0 -18
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'concurrent'
4
- require 'zlib'
5
-
6
3
  module ElasticAPM
7
4
  module Transport
8
5
  class Connection
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticAPM
4
+ module Transport
5
+ # @api private
6
+ class Headers
7
+ HEADERS = {
8
+ 'Content-Type' => 'application/x-ndjson',
9
+ 'Transfer-Encoding' => 'chunked'
10
+ }.freeze
11
+ GZIP_HEADERS = HEADERS.merge(
12
+ 'Content-Encoding' => 'gzip'
13
+ ).freeze
14
+
15
+ def initialize(config, initial: {})
16
+ @config = config
17
+ @hash = build!(initial)
18
+ end
19
+
20
+ attr_accessor :hash
21
+
22
+ def [](key)
23
+ @hash[key]
24
+ end
25
+
26
+ def []=(key, value)
27
+ @hash[key] = value
28
+ end
29
+
30
+ def merge(other)
31
+ self.class.new(@config, initial: @hash.merge(other))
32
+ end
33
+
34
+ def merge!(other)
35
+ @hash.merge!(other)
36
+ self
37
+ end
38
+
39
+ def to_h
40
+ @hash
41
+ end
42
+
43
+ def chunked
44
+ merge(
45
+ @config.http_compression? ? GZIP_HEADERS : HEADERS
46
+ )
47
+ end
48
+
49
+ private
50
+
51
+ def build!(headers)
52
+ headers[:'User-Agent'] = UserAgent.new(@config).to_s
53
+
54
+ if (token = @config.secret_token)
55
+ headers[:Authorization] = "Bearer #{token}"
56
+ end
57
+
58
+ headers
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
-
5
3
  module ElasticAPM
6
4
  module Transport
7
5
  # @api private
@@ -5,15 +5,28 @@ module ElasticAPM
5
5
  module Serializers
6
6
  # @api private
7
7
  class MetricsetSerializer < Serializer
8
+ # rubocop:disable Metrics/MethodLength
8
9
  def build(metricset)
9
- {
10
- metricset: {
11
- timestamp: metricset.timestamp.to_i,
12
- tags: keyword_object(metricset.labels),
13
- samples: build_samples(metricset.samples)
14
- }
10
+ payload = {
11
+ timestamp: metricset.timestamp.to_i,
12
+ samples: build_samples(metricset.samples)
15
13
  }
14
+
15
+ if metricset.tags?
16
+ payload[:tags] = mixed_object(metricset.tags)
17
+ end
18
+
19
+ if metricset.transaction
20
+ payload[:transaction] = metricset.transaction
21
+ end
22
+
23
+ if metricset.span
24
+ payload[:span] = metricset.span
25
+ end
26
+
27
+ { metricset: payload }
16
28
  end
29
+ # rubocop:enable Metrics/MethodLength
17
30
 
18
31
  private
19
32
 
@@ -13,12 +13,12 @@ module ElasticAPM
13
13
 
14
14
  attr_reader :context_serializer
15
15
 
16
- # rubocop:disable Metrics/MethodLength
16
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
17
17
  def build(span)
18
18
  {
19
19
  span: {
20
20
  id: span.id,
21
- transaction_id: span.transaction_id,
21
+ transaction_id: span.transaction.id,
22
22
  parent_id: span.parent_id,
23
23
  name: keyword_field(span.name),
24
24
  type: join_type(span),
@@ -30,7 +30,7 @@ module ElasticAPM
30
30
  }
31
31
  }
32
32
  end
33
- # rubocop:enable Metrics/MethodLength
33
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
34
34
 
35
35
  # @api private
36
36
  class ContextSerializer < Serializer
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticAPM
4
+ module Transport
5
+ # @api private
6
+ class UserAgent
7
+ def initialize(config)
8
+ @built = build(config)
9
+ end
10
+
11
+ def to_s
12
+ @built
13
+ end
14
+
15
+ private
16
+
17
+ def build(config)
18
+ metadata = Metadata.new(config)
19
+
20
+ [
21
+ "elastic-apm-ruby/#{VERSION}",
22
+ HTTP::Request::USER_AGENT,
23
+ [
24
+ metadata.service.runtime.name,
25
+ metadata.service.runtime.version
26
+ ].join('/')
27
+ ].join(' ')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -25,8 +25,7 @@ module ElasticAPM
25
25
  @serializers = serializers
26
26
  @filters = filters
27
27
 
28
- metadata = serializers.serialize(Metadata.new(config))
29
- @connection = conn_adapter.new(config, metadata)
28
+ @connection = conn_adapter.new(config)
30
29
  end
31
30
 
32
31
  attr_reader :queue, :filters, :name, :connection, :serializers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElasticAPM
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
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.1.0
4
+ version: 3.2.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: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -69,6 +69,7 @@ files:
69
69
  - CHANGELOG.md
70
70
  - CODE_OF_CONDUCT.md
71
71
  - CONTRIBUTING.md
72
+ - Dockerfile
72
73
  - Gemfile
73
74
  - LICENSE
74
75
  - README.md
@@ -82,8 +83,11 @@ files:
82
83
  - bench/tmp/.gitkeep
83
84
  - bin/build_docs
84
85
  - bin/console
86
+ - bin/dev
87
+ - bin/run-tests
85
88
  - bin/setup
86
89
  - bin/with_framework
90
+ - docker-compose.yml
87
91
  - docs/advanced.asciidoc
88
92
  - docs/api.asciidoc
89
93
  - docs/configuration.asciidoc
@@ -106,6 +110,7 @@ files:
106
110
  - lib/elastic_apm/agent.rb
107
111
  - lib/elastic_apm/central_config.rb
108
112
  - lib/elastic_apm/central_config/cache_control.rb
113
+ - lib/elastic_apm/child_durations.rb
109
114
  - lib/elastic_apm/config.rb
110
115
  - lib/elastic_apm/config/bytes.rb
111
116
  - lib/elastic_apm/config/duration.rb
@@ -123,6 +128,7 @@ files:
123
128
  - lib/elastic_apm/error/exception.rb
124
129
  - lib/elastic_apm/error/log.rb
125
130
  - lib/elastic_apm/error_builder.rb
131
+ - lib/elastic_apm/grape.rb
126
132
  - lib/elastic_apm/instrumenter.rb
127
133
  - lib/elastic_apm/internal_error.rb
128
134
  - lib/elastic_apm/logging.rb
@@ -132,12 +138,19 @@ files:
132
138
  - lib/elastic_apm/metadata/system_info.rb
133
139
  - lib/elastic_apm/metadata/system_info/container_info.rb
134
140
  - lib/elastic_apm/metrics.rb
135
- - lib/elastic_apm/metrics/cpu_mem.rb
136
- - lib/elastic_apm/metrics/vm.rb
141
+ - lib/elastic_apm/metrics/breakdown_set.rb
142
+ - lib/elastic_apm/metrics/cpu_mem_set.rb
143
+ - lib/elastic_apm/metrics/metric.rb
144
+ - lib/elastic_apm/metrics/set.rb
145
+ - lib/elastic_apm/metrics/span_scoped_set.rb
146
+ - lib/elastic_apm/metrics/transaction_set.rb
147
+ - lib/elastic_apm/metrics/vm_set.rb
137
148
  - lib/elastic_apm/metricset.rb
138
149
  - lib/elastic_apm/middleware.rb
139
150
  - lib/elastic_apm/naively_hashable.rb
140
151
  - lib/elastic_apm/normalizers.rb
152
+ - lib/elastic_apm/normalizers/grape.rb
153
+ - lib/elastic_apm/normalizers/grape/endpoint_run.rb
141
154
  - lib/elastic_apm/normalizers/rails.rb
142
155
  - lib/elastic_apm/normalizers/rails/action_controller.rb
143
156
  - lib/elastic_apm/normalizers/rails/action_mailer.rb
@@ -178,6 +191,7 @@ files:
178
191
  - lib/elastic_apm/transport/connection/proxy_pipe.rb
179
192
  - lib/elastic_apm/transport/filters.rb
180
193
  - lib/elastic_apm/transport/filters/secrets_filter.rb
194
+ - lib/elastic_apm/transport/headers.rb
181
195
  - lib/elastic_apm/transport/serializers.rb
182
196
  - lib/elastic_apm/transport/serializers/context_serializer.rb
183
197
  - lib/elastic_apm/transport/serializers/error_serializer.rb
@@ -185,11 +199,11 @@ files:
185
199
  - lib/elastic_apm/transport/serializers/metricset_serializer.rb
186
200
  - lib/elastic_apm/transport/serializers/span_serializer.rb
187
201
  - lib/elastic_apm/transport/serializers/transaction_serializer.rb
202
+ - lib/elastic_apm/transport/user_agent.rb
188
203
  - lib/elastic_apm/transport/worker.rb
189
204
  - lib/elastic_apm/util.rb
190
205
  - lib/elastic_apm/util/inflector.rb
191
206
  - lib/elastic_apm/util/lru_cache.rb
192
- - lib/elastic_apm/util/prefixed_logger.rb
193
207
  - lib/elastic_apm/util/throttle.rb
194
208
  - lib/elastic_apm/version.rb
195
209
  - vendor/.gitkeep
@@ -213,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
227
  - !ruby/object:Gem::Version
214
228
  version: '0'
215
229
  requirements: []
216
- rubygems_version: 3.0.3
230
+ rubygems_version: 3.0.6
217
231
  signing_key:
218
232
  specification_version: 4
219
233
  summary: The official Elastic APM agent for Ruby
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElasticAPM
4
- module Metrics
5
- # @api private
6
- class VM
7
- include Logging
8
-
9
- def initialize(config)
10
- @config = config
11
- @total_time = 0
12
- @disabled = false
13
- end
14
-
15
- attr_reader :config
16
- attr_writer :disabled
17
-
18
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
19
- # rubocop:disable Metrics/CyclomaticComplexity
20
- def collect
21
- return if disabled?
22
-
23
- stat = GC.stat
24
- thread_count = Thread.list.count
25
-
26
- sample = {
27
- 'ruby.gc.count': stat[:count],
28
- 'ruby.threads': thread_count
29
- }
30
-
31
- (live_slots = stat[:heap_live_slots]) &&
32
- sample[:'ruby.heap.slots.live'] = live_slots
33
- (heap_slots = stat[:heap_free_slots]) &&
34
- sample[:'ruby.heap.slots.free'] = heap_slots
35
- (allocated = stat[:total_allocated_objects]) &&
36
- sample[:'ruby.heap.allocations.total'] = allocated
37
-
38
- return sample unless GC::Profiler.enabled?
39
-
40
- @total_time += GC::Profiler.total_time
41
- GC::Profiler.clear
42
- sample[:'ruby.gc.time'] = @total_time
43
-
44
- sample
45
- rescue TypeError => e
46
- error 'VM metrics encountered error: %s', e
47
- debug('Backtrace:') { e.backtrace.join("\n") }
48
-
49
- @disabled = true
50
- nil
51
- end
52
- # rubocop:enable Metrics/CyclomaticComplexity
53
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
54
-
55
- def disabled?
56
- @disabled
57
- end
58
- end
59
- end
60
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ElasticAPM
4
- # @api private
5
- class PrefixedLogger < Logger
6
- def initialize(logdev, prefix: '', **args)
7
- super(logdev, **args)
8
-
9
- @prefix = prefix
10
- end
11
-
12
- attr_reader :prefix
13
-
14
- def add(severity, message = nil, progname = nil, &block)
15
- super(severity, message, format('%s%s', prefix, progname), &block)
16
- end
17
- end
18
- end