elastic-apm 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of elastic-apm might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7026cd778a6226802c4bb0b0c384b67c86df3a60430a4283f7b48f45da16e8a6
4
- data.tar.gz: c415bff2b4c720a3a5b981a27c1ca91500233be95d6f1a73c6bb46ba5d2e2344
3
+ metadata.gz: 556f800e5882b54fe89a4249a6ca5ce98bdfe04b9148f813b75ff17087834c70
4
+ data.tar.gz: 073241c2a7c78fbebd32434791339a321548e12de242f72598bc11c9bda833b2
5
5
  SHA512:
6
- metadata.gz: 6e6db8df5ab8e2d7313813b3ca4524c8b32a11e9fe14940cb6d7b55483847015b0716bd760124be452ff4d17708a926edd242f715ab887820a5e0f24eb85d4ac
7
- data.tar.gz: 7a9e88ef324250a4715b7e60e7c5f32256eea3965556a3b77535c6bd6673dce72c3f8fea92dac321976f1a75ee81ab4174d4502b9655ddfcecabb114f518ee83
6
+ metadata.gz: b53f5c630ce8313593d4ecb0485d48bd3d552e672217409ce2cef9366aa06f881e633108c421d670b77df050fb2069eab09cb5b297a89a977ba0a7fcbe22b5e1
7
+ data.tar.gz: 7216c6d7628565b4e7295267ebba268461d693edecc5806fd83a92e9d2917aaf77ee075c0bcca20e0f67fdd9a90b3068d4fdabe5ddebbaa2a50353fd0a102169
data/.rubocop.yml CHANGED
@@ -63,5 +63,11 @@ Rails/Delegate:
63
63
  Style/NumericPredicate:
64
64
  Enabled: false
65
65
 
66
+ Style/PerlBackrefs:
67
+ Enabled: false
68
+
66
69
  Layout/EmptyLineAfterGuardClause:
67
70
  Enabled: false
71
+
72
+ Naming/MemoizedInstanceVariableName:
73
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.2.0 (2019-01-22)
8
+
9
+ ### Added
10
+
11
+ - Support for [OpenTracing](https://opentracing.io) ([#273](https://github.com/elastic/apm-agent-ruby/pull/273))
12
+ - Add capture_* options ([#279](https://github.com/elastic/apm-agent-ruby/pull/279))
13
+ - Evaluate the config file as ERB ([#288](https://github.com/elastic/apm-agent-ruby/pull/288))
14
+
15
+ ### Changed
16
+
17
+ - Rename `Traceparent` object to `TraceContext` ([#271](https://github.com/elastic/apm-agent-ruby/pull/271))
18
+
19
+ ### Fixed
20
+
21
+ - An issue where Spans would not get Stacktraces attached ([#282](https://github.com/elastic/apm-agent-ruby/pull/282))
22
+ - Skip `caller` unless needed ([#287](https://github.com/elastic/apm-agent-ruby/pull/283))
23
+
7
24
  ## 2.1.2 (2018-12-07)
8
25
 
9
26
  ### Fixed
data/Gemfile CHANGED
@@ -18,6 +18,7 @@ gem 'elasticsearch', require: nil
18
18
  gem 'fakeredis', require: nil
19
19
  gem 'json-schema', require: nil
20
20
  gem 'mongo', require: nil
21
+ gem 'opentracing', require: nil
21
22
  gem 'rake', require: nil
22
23
  gem 'sequel', require: nil
23
24
  gem 'sidekiq', require: nil
@@ -1,8 +1,16 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at
4
+ https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
5
+ endif::[]
6
+
1
7
  [[advanced]]
2
8
  == Advanced Topics
3
9
 
4
10
  * <<context>>
5
11
  * <<custom-instrumentation>>
12
+ * <<opentracing>>
6
13
 
7
14
  include::./context.asciidoc[]
8
- include::./custom-instrumentation.asciidoc[]
15
+ include::./custom-instrumentation.asciidoc[]
16
+ include::./opentracing.asciidoc[]
data/docs/api.asciidoc CHANGED
@@ -1,3 +1,9 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at
4
+ https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
5
+ endif::[]
6
+
1
7
  [[api]]
2
8
  == Public API
3
9
 
@@ -76,7 +82,7 @@ Arguments:
76
82
  * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
77
83
  * `context:`: An optional <<api-context,Context>> used to enrich the
78
84
  transaction with information about the current request.
79
- * `traceparent:`: An optional `Traceparent` object for Distributed Tracing.
85
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
80
86
 
81
87
  Returns the transaction.
82
88
 
@@ -111,7 +117,7 @@ Arguments:
111
117
  * `type`: A `type` for your transaction eg. `db.postgresql.sql`.
112
118
  * `context:`: An optional <<api-context,Context>> used to enrich the
113
119
  transaction with information about the current request.
114
- * `traceparent:`: An optional `Traceparent` object for Distributed Tracing.
120
+ * `trace_context:`: An optional `TraceContext` object for Distributed Tracing.
115
121
  * `&block`: A block to wrap. Optionally yields the transaction.
116
122
 
117
123
  Returns the return value of the given block.
@@ -1,3 +1,9 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at
4
+ https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
5
+ endif::[]
6
+
1
7
  [[configuration]]
2
8
  == Configuration
3
9
 
@@ -10,7 +16,7 @@ The recommended way to configure Elastic APM is to create a file
10
16
  ----
11
17
  ---
12
18
  server_url: 'http://localhost:8200'
13
- secret_token: 'very_very_secret'
19
+ secret_token: <%= ENV["VERY_SECRET_TOKEN"] %>
14
20
  ----
15
21
 
16
22
  Options are applied in the following order (last one wins):
@@ -70,6 +76,13 @@ eg `ELASTIC_APM_ENABLED_ENVIRONMENTS=development,production`.
70
76
 
71
77
  Path to the configuration YAML-file.
72
78
  Elastic APM will load config options from this if the file exists.
79
+ The file will be evaluated as ERB, so you can include `ENV` variables like in
80
+ your `database.yml`, eg:
81
+
82
+ [source,ruby]
83
+ ----
84
+ secret_token: <%= ENV['VERY_SECRET_TOKEN'] %>
85
+ ----
73
86
 
74
87
  [float]
75
88
  [[config-server-url]]
@@ -149,6 +162,36 @@ APM Server has its own limit of 30 seconds before it will close requests.
149
162
 
150
163
  It has to be provided in *<<config-format-duration, duration format>>*.
151
164
 
165
+ [float]
166
+ [[config-capture-body]]
167
+ ==== `capture_body`
168
+ |============
169
+ | Environment | `Config` key | Default
170
+ | `ELASTIC_APM_CAPTURE_BODY` | `capture_body` | `true`
171
+ |============
172
+
173
+ Whether or not to attach the request body to transactions and errors.
174
+
175
+ [float]
176
+ [[config-capture-headers]]
177
+ ==== `capture_headers`
178
+ |============
179
+ | Environment | `Config` key | Default
180
+ | `ELASTIC_APM_CAPTURE_HEADERS` | `capture_headers` | `true`
181
+ |============
182
+
183
+ Whether or not to attach the request headers to transactions and errors.
184
+
185
+ [float]
186
+ [[config-capture-env]]
187
+ ==== `capture_env`
188
+ |============
189
+ | Environment | `Config` key | Default
190
+ | `ELASTIC_APM_CAPTURE_ENV` | `capture_env` | `true`
191
+ |============
192
+
193
+ Whether or not to attach `ENV` from Rack to transactions and errors.
194
+
152
195
  [float]
153
196
  [[config-custom-key-filters]]
154
197
  ==== `custom_key_filters`
@@ -1,3 +1,9 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at
4
+ https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
5
+ endif::[]
6
+
1
7
  [[getting-started-rack]]
2
8
  == Getting started with Rack
3
9
 
@@ -1,3 +1,9 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at
4
+ https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
5
+ endif::[]
6
+
1
7
  [[getting-started-rails]]
2
8
  == Getting started with Rails
3
9
 
data/docs/index.asciidoc CHANGED
@@ -1,4 +1,5 @@
1
1
  :branch: current
2
+ :server-branch: 6.5
2
3
  include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
3
4
 
4
5
  ifdef::env-github[]
@@ -1,11 +1,11 @@
1
- [[introduction]]
2
-
3
1
  ifdef::env-github[]
4
2
  NOTE: For the best reading experience,
5
3
  please view this documentation at
6
4
  https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
7
5
  endif::[]
8
6
 
7
+ [[introduction]]
8
+
9
9
  == Introduction
10
10
 
11
11
  Welcome to the APM Ruby Agent documentation.
@@ -19,8 +19,8 @@ It has built-in support for <<getting-started-rails,Ruby on Rails>> and other
19
19
  [[additional-components]]
20
20
  === Additional Components
21
21
 
22
- APM Agents work in conjunction with the {apm-server-ref}/index.html[APM Server], {ref}/index.html[Elasticsearch], and {kibana-ref}/index.html[Kibana].
23
- Please view the {apm-get-started-ref}/index.html[APM Overview] for details on how these components work together.
22
+ APM Agents work in conjunction with the {apm-server-ref-v}/index.html[APM Server], {ref}/index.html[Elasticsearch], and {kibana-ref}/index.html[Kibana].
23
+ Please view the {apm-overview-ref-v}/index.html[APM Overview] for details on how these components work together.
24
24
 
25
25
  [float]
26
26
  [[framework-support]]
@@ -30,4 +30,4 @@ The Elastic APM Ruby Agent officially supports Ruby on Rails versions 4.x on
30
30
  onwards, see <<getting-started-rails,Getting started with Ruby on Rails>>.
31
31
 
32
32
  For Sinatra and other Rack compatible frameworks, see
33
- <<getting-started-rack,Getting started with Rack>>.
33
+ <<getting-started-rack,Getting started with Rack>>.
@@ -0,0 +1,94 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at https://www.elastic.co/guide/en/apm/agent/ruby[elastic.co]
4
+ endif::[]
5
+
6
+ [[opentracing]]
7
+ === OpenTracing bridge
8
+
9
+ The Elastic APM OpenTracing bridge allows to create Elastic APM `Transactions` and `Spans`,
10
+ using the OpenTracing API.
11
+ In other words,
12
+ it translates the calls to the OpenTracing API to Elastic APM and thus allows for reusing existing instrumentation.
13
+
14
+ The first span of a service will be converted to an Elastic APM `Transaction`,
15
+ subsequent spans are mapped to Elastic APM `Span`.
16
+
17
+ [float]
18
+ [[operation-modes]]
19
+ === Operation Modes
20
+
21
+ This bridge allows for different operation modes in combination with the Elastic APM Agent.
22
+
23
+ - Noop +
24
+ If no Elastic APM agent is running, the bridge is in noop mode and does not actually record and report spans.
25
+ - Mix and Match +
26
+ If you want to leverage the auto instrumentation of Elastic APM,
27
+ but also want do create custom spans or use the OpenTracing API to add custom tags to the spans created by Elastic APM,
28
+ you can just do that.
29
+ The OpenTracing bridge and the standard Elastic APM API interact seamlessly.
30
+ - Manual instrumentation +
31
+ If you don't want Elastic APM to auto-instrument known frameworks,
32
+ but instead only rely on manual instrumentation,
33
+ disable the auto instrumentation setting the configuration option <<config-instrument,`instrument`>> to `false`.
34
+
35
+ [float]
36
+ [[getting-started]]
37
+ === Getting started
38
+ Either `require 'elastic_apm/opentracing'` during the boot of your app or specify the `require:` argument to your `Gemfile`, eg. `gem 'elastic_apm', require: 'elastic_apm/opentracing'`.
39
+
40
+ [float]
41
+ [[init-tracer]]
42
+ === Set Elastic APM as the global tracer
43
+
44
+ [source,ruby]
45
+ ----
46
+ ::OpenTracing.global_tracer = ElasticAPM::OpenTracing::Tracer.new
47
+ ----
48
+
49
+ [float]
50
+ [[elastic-apm-tags]]
51
+ === Elastic APM specific tags
52
+
53
+ Elastic APM defines some tags which are not included in the OpenTracing API but are relevant in the context of Elastic APM.
54
+
55
+ - `type` - sets the type of the transaction,
56
+ for example `request`, `ext` or `db`
57
+ - `user.id` - sets the user id,
58
+ appears in the "User" tab in the transaction details in the Elastic APM UI
59
+ - `user.email` - sets the user email,
60
+ appears in the "User" tab in the transaction details in the Elastic APM UI
61
+ - `user.username` - sets the user name,
62
+ appears in the "User" tab in the transaction details in the Elastic APM UI
63
+ - `result` - sets the result of the transaction. Overrides the default value of `success`.
64
+ If the `error` tag is set to `true`, the default value is `error`.
65
+
66
+ [float]
67
+ [[unsupported]]
68
+ === Caveats
69
+ Not all features of the OpenTracing API are supported.
70
+
71
+ [float]
72
+ [[propagation]]
73
+ ==== Context propagation
74
+ This bridge only supports the format `OpenTracing::FORMAT_RACK`, using HTTP headers with capitalized names, prefixed with `HTTP_` as Rack does it.
75
+
76
+ `OpenTracing::FORMAT_BINARY` is currently not supported.
77
+
78
+ [float]
79
+ [[references]]
80
+ ==== Span References
81
+ Currently, this bridge only supports `child_of` references.
82
+ Other references,
83
+ like `follows_from` are not supported yet.
84
+
85
+ [float]
86
+ [[baggage]]
87
+ ==== Baggage
88
+ The `Span.set_baggage` method is not supported.
89
+ Baggage items are dropped with a warning log message.
90
+
91
+ [float]
92
+ [[logs]]
93
+ ==== Logs
94
+ Logs are currently not supported.
@@ -1,3 +1,8 @@
1
+ ifdef::env-github[]
2
+ NOTE: For the best reading experience,
3
+ please view this documentation at https://www.elastic.co/guide/en/apm/agent/ruby[elastic.co]
4
+ endif::[]
5
+
1
6
  [[supported-technologies]]
2
7
  == Supported technologies
3
8
 
data/lib/elastic_apm.rb CHANGED
@@ -84,6 +84,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
84
84
 
85
85
  deprecate :transaction, :with_transaction
86
86
 
87
+ # rubocop:disable Metrics/MethodLength
87
88
  # Start a new transaction
88
89
  #
89
90
  # @param name [String] A description of the transaction, eg
@@ -96,15 +97,23 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
96
97
  name = nil,
97
98
  type = nil,
98
99
  context: nil,
100
+ trace_context: nil,
99
101
  traceparent: nil
100
102
  )
103
+ if traceparent
104
+ trace_context ||= traceparent
105
+ warn "[ElasticAPM] [DEPRECATED] `start_transaction' with" \
106
+ "`traceparent:' has been renamed. Use `trace_context:' instead."
107
+ end
108
+
101
109
  agent&.start_transaction(
102
110
  name,
103
111
  type,
104
112
  context: context,
105
- traceparent: traceparent
113
+ trace_context: trace_context
106
114
  )
107
115
  end
116
+ # rubocop:enable Metrics/MethodLength
108
117
 
109
118
  # Ends the current transaction with `result`
110
119
  #
@@ -124,12 +133,24 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
124
133
  # @param context [Context] An optional [Context]
125
134
  # @yield [Transaction]
126
135
  # @return result of block
127
- def with_transaction(name = nil, type = nil, context: nil, traceparent: nil)
136
+ def with_transaction(
137
+ name = nil,
138
+ type = nil,
139
+ context: nil,
140
+ trace_context: nil,
141
+ traceparent: nil
142
+ )
128
143
  unless block_given?
129
144
  raise ArgumentError,
130
145
  'expected a block. Do you want `start_transaction\' instead?'
131
146
  end
132
147
 
148
+ if traceparent
149
+ trace_context ||= traceparent
150
+ warn "[ElasticAPM] [DEPRECATED] `with_transaction' with " \
151
+ "`traceparent:' has been renamed. Use `trace_context:' instead."
152
+ end
153
+
133
154
  return yield(nil) unless agent
134
155
 
135
156
  begin
@@ -138,7 +159,7 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
138
159
  name,
139
160
  type,
140
161
  context: context,
141
- traceparent: traceparent
162
+ trace_context: trace_context
142
163
  )
143
164
  yield transaction
144
165
  ensure
@@ -156,15 +177,20 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
156
177
  # @yield [Span] Optional block encapsulating span
157
178
  # @return [Span] Unless block given
158
179
  # @deprecated See `with_span` or `start_span`
159
- def span(name, type = nil, context: nil, include_stacktrace: true, &block)
180
+ def span(
181
+ name,
182
+ type = nil,
183
+ context: nil,
184
+ include_stacktrace: true,
185
+ &block
186
+ )
160
187
  return (block_given? ? yield : nil) unless agent
161
188
 
162
189
  if block_given?
163
190
  with_span(
164
191
  name,
165
192
  type,
166
- context:
167
- context,
193
+ context: context,
168
194
  include_stacktrace: include_stacktrace,
169
195
  &block
170
196
  )
@@ -188,13 +214,24 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
188
214
  # @param context [Span::Context] Context information about the span
189
215
  # @param include_stacktrace [Boolean] Whether or not to capture a stacktrace
190
216
  # @return [Span]
191
- def start_span(name, type = nil, context: nil, include_stacktrace: true)
217
+ def start_span(
218
+ name,
219
+ type = nil,
220
+ context: nil,
221
+ include_stacktrace: true,
222
+ trace_context: nil
223
+ )
192
224
  agent&.start_span(
193
225
  name,
194
226
  type,
195
227
  context: context,
196
- backtrace: include_stacktrace ? caller : nil
197
- )
228
+ trace_context: trace_context
229
+ ).tap do |span|
230
+ break unless span && include_stacktrace
231
+ break unless agent.config.span_frames_min_duration?
232
+
233
+ span.original_backtrace ||= caller
234
+ end
198
235
  end
199
236
 
200
237
  # Ends the current span
@@ -217,7 +254,8 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
217
254
  name,
218
255
  type = nil,
219
256
  context: nil,
220
- include_stacktrace: true
257
+ include_stacktrace: true,
258
+ trace_context: nil
221
259
  )
222
260
  unless block_given?
223
261
  raise ArgumentError,
@@ -229,7 +267,11 @@ module ElasticAPM # rubocop:disable Metrics/ModuleLength
229
267
  begin
230
268
  span =
231
269
  start_span(
232
- name, type, context: context, include_stacktrace: include_stacktrace
270
+ name,
271
+ type,
272
+ context: context,
273
+ include_stacktrace: include_stacktrace,
274
+ trace_context: trace_context
233
275
  )
234
276
  yield span
235
277
  ensure