elastic-apm 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/Jenkinsfile +4 -1
  3. data/CHANGELOG.asciidoc +497 -0
  4. data/CHANGELOG.md +1 -359
  5. data/Rakefile +2 -2
  6. data/docs/advanced.asciidoc +0 -2
  7. data/docs/api.asciidoc +12 -1
  8. data/docs/configuration.asciidoc +15 -4
  9. data/docs/custom-instrumentation.asciidoc +2 -2
  10. data/docs/debugging.asciidoc +1 -1
  11. data/docs/getting-started-rack.asciidoc +4 -1
  12. data/docs/getting-started-rails.asciidoc +2 -2
  13. data/docs/index.asciidoc +8 -9
  14. data/docs/introduction.asciidoc +17 -15
  15. data/docs/opentracing.asciidoc +13 -13
  16. data/docs/release-notes.asciidoc +11 -1
  17. data/docs/set-up.asciidoc +16 -0
  18. data/docs/supported-technologies.asciidoc +2 -4
  19. data/lib/elastic_apm.rb +2 -2
  20. data/lib/elastic_apm/agent.rb +4 -4
  21. data/lib/elastic_apm/central_config.rb +7 -3
  22. data/lib/elastic_apm/config.rb +2 -2
  23. data/lib/elastic_apm/config/options.rb +6 -0
  24. data/lib/elastic_apm/context.rb +15 -1
  25. data/lib/elastic_apm/instrumenter.rb +8 -7
  26. data/lib/elastic_apm/normalizers.rb +0 -9
  27. data/lib/elastic_apm/normalizers/rails.rb +10 -0
  28. data/lib/elastic_apm/normalizers/{action_controller.rb → rails/action_controller.rb} +0 -0
  29. data/lib/elastic_apm/normalizers/{action_mailer.rb → rails/action_mailer.rb} +0 -0
  30. data/lib/elastic_apm/normalizers/{action_view.rb → rails/action_view.rb} +0 -0
  31. data/lib/elastic_apm/normalizers/{active_record.rb → rails/active_record.rb} +0 -0
  32. data/lib/elastic_apm/rails.rb +1 -0
  33. data/lib/elastic_apm/sinatra.rb +36 -0
  34. data/lib/elastic_apm/transaction.rb +13 -6
  35. data/lib/elastic_apm/transport/serializers/context_serializer.rb +13 -1
  36. data/lib/elastic_apm/version.rb +1 -1
  37. metadata +10 -6
@@ -47,7 +47,7 @@ module ElasticAPM
47
47
  @current = Current.new
48
48
  end
49
49
 
50
- attr_reader :config, :stacktrace_builder, :enqueue
50
+ attr_reader :stacktrace_builder, :enqueue
51
51
 
52
52
  def start
53
53
  debug 'Starting instrumenter'
@@ -82,6 +82,7 @@ module ElasticAPM
82
82
  def start_transaction(
83
83
  name = nil,
84
84
  type = nil,
85
+ config:,
85
86
  context: nil,
86
87
  trace_context: nil
87
88
  )
@@ -92,7 +93,7 @@ module ElasticAPM
92
93
  "Transactions may not be nested.\nAlready inside #{transaction}"
93
94
  end
94
95
 
95
- sampled = trace_context ? trace_context.recorded? : random_sample?
96
+ sampled = trace_context ? trace_context.recorded? : random_sample?(config)
96
97
 
97
98
  transaction =
98
99
  Transaction.new(
@@ -101,7 +102,7 @@ module ElasticAPM
101
102
  context: context,
102
103
  trace_context: trace_context,
103
104
  sampled: sampled,
104
- labels: config.default_labels
105
+ config: config
105
106
  )
106
107
 
107
108
  transaction.start
@@ -149,7 +150,7 @@ module ElasticAPM
149
150
 
150
151
  transaction.inc_started_spans!
151
152
 
152
- if transaction.max_spans_reached?(config)
153
+ if transaction.max_spans_reached?
153
154
  transaction.inc_dropped_spans!
154
155
  return
155
156
  end
@@ -167,7 +168,7 @@ module ElasticAPM
167
168
  stacktrace_builder: stacktrace_builder
168
169
  )
169
170
 
170
- if backtrace && config.span_frames_min_duration?
171
+ if backtrace && transaction.config.span_frames_min_duration?
171
172
  span.original_backtrace = backtrace
172
173
  end
173
174
 
@@ -205,7 +206,7 @@ module ElasticAPM
205
206
 
206
207
  def set_user(user)
207
208
  return unless current_transaction
208
- current_transaction.context.user = Context::User.infer(config, user)
209
+ current_transaction.set_user(user)
209
210
  end
210
211
 
211
212
  def inspect
@@ -216,7 +217,7 @@ module ElasticAPM
216
217
 
217
218
  private
218
219
 
219
- def random_sample?
220
+ def random_sample?(config)
220
221
  rand <= config.transaction_sample_rate
221
222
  end
222
223
  end
@@ -56,13 +56,4 @@ module ElasticAPM # :nodoc:
56
56
  end
57
57
  end
58
58
  end
59
-
60
- %w[
61
- action_controller
62
- action_mailer
63
- action_view
64
- active_record
65
- ].each do |lib|
66
- require "elastic_apm/normalizers/#{lib}"
67
- end
68
59
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ action_controller
5
+ action_mailer
6
+ action_view
7
+ active_record
8
+ ].each do |lib|
9
+ require "elastic_apm/normalizers/rails/#{lib}"
10
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'elastic_apm/subscriber'
4
+ require 'elastic_apm/normalizers/rails'
4
5
 
5
6
  module ElasticAPM
6
7
  # Module for explicitly starting the ElasticAPM agent and hooking into Rails.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticAPM
4
+ # Module for starting the ElasticAPM agent and hooking into Sinatra.
5
+ module Sinatra
6
+ extend self
7
+ # Start the ElasticAPM agent and hook into Sinatra.
8
+ #
9
+ # @param app [Sinatra::Base] A Sinatra app.
10
+ # @param config [Config, Hash] An instance of Config or a Hash config.
11
+ # @return [true, nil] true if the agent was started, nil otherwise.
12
+ def start(app, config)
13
+ config = Config.new(config) unless config.is_a?(Config)
14
+ configure_app(app, config)
15
+
16
+ ElasticAPM.start(config)
17
+ ElasticAPM.running?
18
+ rescue StandardError => e
19
+ config.logger.error format('Failed to start: %s', e.message)
20
+ config.logger.debug "Backtrace:\n" + e.backtrace.join("\n")
21
+ end
22
+
23
+ private
24
+
25
+ def configure_app(app, config)
26
+ config.service_name ||= format_name(app.to_s)
27
+ config.framework_name ||= 'Sinatra'
28
+ config.framework_version ||= ::Sinatra::VERSION
29
+ config.__root_path ||= Dir.pwd
30
+ end
31
+
32
+ def format_name(str)
33
+ str && str.gsub('::', '_')
34
+ end
35
+ end
36
+ end
@@ -13,22 +13,25 @@ module ElasticAPM
13
13
 
14
14
  DEFAULT_TYPE = 'custom'
15
15
 
16
- # rubocop:disable Metrics/ParameterLists
16
+ # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
17
17
  def initialize(
18
18
  name = nil,
19
19
  type = nil,
20
20
  sampled: true,
21
21
  context: nil,
22
- labels: nil,
22
+ config:,
23
23
  trace_context: nil
24
24
  )
25
25
  @name = name
26
26
  @type = type || DEFAULT_TYPE
27
+ @config = config
27
28
 
28
29
  @sampled = sampled
29
30
 
30
31
  @context = context || Context.new # TODO: Lazy generate this?
31
- Util.reverse_merge!(@context.labels, labels) if labels
32
+ if config.default_labels
33
+ Util.reverse_merge!(@context.labels, config.default_labels)
34
+ end
32
35
 
33
36
  @trace_context = trace_context || TraceContext.new(recorded: sampled)
34
37
 
@@ -37,12 +40,12 @@ module ElasticAPM
37
40
 
38
41
  @notifications = [] # for AS::Notifications
39
42
  end
40
- # rubocop:enable Metrics/ParameterLists
43
+ # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
41
44
 
42
45
  attr_accessor :name, :type, :result
43
46
 
44
47
  attr_reader :context, :duration, :started_spans, :dropped_spans,
45
- :timestamp, :trace_context, :notifications
48
+ :timestamp, :trace_context, :notifications, :config
46
49
 
47
50
  def sampled?
48
51
  @sampled
@@ -82,7 +85,7 @@ module ElasticAPM
82
85
  @dropped_spans += 1
83
86
  end
84
87
 
85
- def max_spans_reached?(config)
88
+ def max_spans_reached?
86
89
  started_spans > config.transaction_max_spans
87
90
  end
88
91
 
@@ -92,6 +95,10 @@ module ElasticAPM
92
95
  context.response = Context::Response.new(*args)
93
96
  end
94
97
 
98
+ def set_user(user)
99
+ context.user = Context::User.infer(config, user)
100
+ end
101
+
95
102
  def inspect
96
103
  "<ElasticAPM::Transaction id:#{id}" \
97
104
  " name:#{name.inspect} type:#{type.inspect}>"
@@ -13,7 +13,8 @@ module ElasticAPM
13
13
  tags: mixed_object(context.labels),
14
14
  request: build_request(context.request),
15
15
  response: build_response(context.response),
16
- user: build_user(context.user)
16
+ user: build_user(context.user),
17
+ service: build_service(context.service)
17
18
  }
18
19
  end
19
20
 
@@ -79,6 +80,17 @@ module ElasticAPM
79
80
  hash: keyword_field(url.hash)
80
81
  }
81
82
  end
83
+
84
+ def build_service(service)
85
+ return unless service
86
+
87
+ {
88
+ framework: {
89
+ name: keyword_field(service.framework.name),
90
+ version: keyword_field(service.framework.version)
91
+ }
92
+ }
93
+ end
82
94
  end
83
95
  end
84
96
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElasticAPM
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.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.0.0
4
+ version: 3.1.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-08 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -65,6 +65,7 @@ files:
65
65
  - ".pre-commit-config.yaml"
66
66
  - ".rspec"
67
67
  - ".rubocop.yml"
68
+ - CHANGELOG.asciidoc
68
69
  - CHANGELOG.md
69
70
  - CODE_OF_CONDUCT.md
70
71
  - CONTRIBUTING.md
@@ -97,6 +98,7 @@ files:
97
98
  - docs/metrics.asciidoc
98
99
  - docs/opentracing.asciidoc
99
100
  - docs/release-notes.asciidoc
101
+ - docs/set-up.asciidoc
100
102
  - docs/supported-technologies.asciidoc
101
103
  - elastic-apm.gemspec
102
104
  - lib/elastic-apm.rb
@@ -136,13 +138,15 @@ files:
136
138
  - lib/elastic_apm/middleware.rb
137
139
  - lib/elastic_apm/naively_hashable.rb
138
140
  - lib/elastic_apm/normalizers.rb
139
- - lib/elastic_apm/normalizers/action_controller.rb
140
- - lib/elastic_apm/normalizers/action_mailer.rb
141
- - lib/elastic_apm/normalizers/action_view.rb
142
- - lib/elastic_apm/normalizers/active_record.rb
141
+ - lib/elastic_apm/normalizers/rails.rb
142
+ - lib/elastic_apm/normalizers/rails/action_controller.rb
143
+ - lib/elastic_apm/normalizers/rails/action_mailer.rb
144
+ - lib/elastic_apm/normalizers/rails/action_view.rb
145
+ - lib/elastic_apm/normalizers/rails/active_record.rb
143
146
  - lib/elastic_apm/opentracing.rb
144
147
  - lib/elastic_apm/rails.rb
145
148
  - lib/elastic_apm/railtie.rb
149
+ - lib/elastic_apm/sinatra.rb
146
150
  - lib/elastic_apm/span.rb
147
151
  - lib/elastic_apm/span/context.rb
148
152
  - lib/elastic_apm/span_helpers.rb