elastic-apm 3.6.0 → 3.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/Jenkinsfile +183 -100
  3. data/.ci/jobs/defaults.yml +1 -1
  4. data/.ci/packer_cache.sh +12 -10
  5. data/.rspec +0 -1
  6. data/.rubocop.yml +3 -0
  7. data/CHANGELOG.asciidoc +84 -0
  8. data/Gemfile +22 -1
  9. data/Rakefile +28 -1
  10. data/bin/run-tests +4 -1
  11. data/docker-compose.yml +2 -0
  12. data/docs/configuration.asciidoc +117 -16
  13. data/docs/debugging.asciidoc +14 -0
  14. data/docs/getting-started-rails.asciidoc +2 -0
  15. data/docs/images/dynamic-config.svg +1 -0
  16. data/docs/index.asciidoc +2 -1
  17. data/docs/introduction.asciidoc +2 -1
  18. data/docs/performance-tuning.asciidoc +106 -0
  19. data/docs/set-up.asciidoc +5 -2
  20. data/docs/supported-technologies.asciidoc +18 -1
  21. data/elastic-apm.gemspec +17 -0
  22. data/lib/elastic-apm.rb +17 -0
  23. data/lib/elastic_apm.rb +18 -1
  24. data/lib/elastic_apm/agent.rb +48 -2
  25. data/lib/elastic_apm/central_config.rb +27 -8
  26. data/lib/elastic_apm/central_config/cache_control.rb +17 -0
  27. data/lib/elastic_apm/child_durations.rb +17 -0
  28. data/lib/elastic_apm/config.rb +52 -2
  29. data/lib/elastic_apm/config/bytes.rb +17 -0
  30. data/lib/elastic_apm/config/duration.rb +17 -0
  31. data/lib/elastic_apm/config/options.rb +18 -1
  32. data/lib/elastic_apm/config/regexp_list.rb +17 -0
  33. data/lib/elastic_apm/config/wildcard_pattern_list.rb +28 -1
  34. data/lib/elastic_apm/context.rb +17 -0
  35. data/lib/elastic_apm/context/request.rb +17 -0
  36. data/lib/elastic_apm/context/request/socket.rb +17 -0
  37. data/lib/elastic_apm/context/request/url.rb +17 -0
  38. data/lib/elastic_apm/context/response.rb +17 -0
  39. data/lib/elastic_apm/context/user.rb +17 -0
  40. data/lib/elastic_apm/context_builder.rb +18 -1
  41. data/lib/elastic_apm/deprecations.rb +17 -0
  42. data/lib/elastic_apm/error.rb +17 -0
  43. data/lib/elastic_apm/error/exception.rb +17 -0
  44. data/lib/elastic_apm/error/log.rb +17 -0
  45. data/lib/elastic_apm/error_builder.rb +17 -0
  46. data/lib/elastic_apm/grape.rb +17 -0
  47. data/lib/elastic_apm/graphql.rb +17 -0
  48. data/lib/elastic_apm/grpc.rb +19 -2
  49. data/lib/elastic_apm/instrumenter.rb +29 -4
  50. data/lib/elastic_apm/internal_error.rb +17 -0
  51. data/lib/elastic_apm/logging.rb +17 -0
  52. data/lib/elastic_apm/metadata.rb +17 -0
  53. data/lib/elastic_apm/metadata/process_info.rb +17 -0
  54. data/lib/elastic_apm/metadata/service_info.rb +22 -2
  55. data/lib/elastic_apm/metadata/system_info.rb +22 -3
  56. data/lib/elastic_apm/metadata/system_info/container_info.rb +45 -4
  57. data/lib/elastic_apm/metrics.rb +33 -1
  58. data/lib/elastic_apm/metrics/breakdown_set.rb +17 -0
  59. data/lib/elastic_apm/metrics/cpu_mem_set.rb +17 -0
  60. data/lib/elastic_apm/metrics/metric.rb +17 -0
  61. data/lib/elastic_apm/metrics/set.rb +17 -0
  62. data/lib/elastic_apm/metrics/span_scoped_set.rb +17 -0
  63. data/lib/elastic_apm/metrics/transaction_set.rb +17 -0
  64. data/lib/elastic_apm/metrics/vm_set.rb +17 -0
  65. data/lib/elastic_apm/metricset.rb +17 -0
  66. data/lib/elastic_apm/middleware.rb +25 -2
  67. data/lib/elastic_apm/naively_hashable.rb +17 -0
  68. data/lib/elastic_apm/normalizers.rb +17 -0
  69. data/lib/elastic_apm/normalizers/grape.rb +17 -0
  70. data/lib/elastic_apm/normalizers/grape/endpoint_run.rb +18 -1
  71. data/lib/elastic_apm/normalizers/rails.rb +17 -0
  72. data/lib/elastic_apm/normalizers/rails/action_controller.rb +17 -0
  73. data/lib/elastic_apm/normalizers/rails/action_mailer.rb +17 -0
  74. data/lib/elastic_apm/normalizers/rails/action_view.rb +17 -0
  75. data/lib/elastic_apm/normalizers/rails/active_record.rb +17 -0
  76. data/lib/elastic_apm/opentracing.rb +64 -23
  77. data/lib/elastic_apm/rails.rb +17 -0
  78. data/lib/elastic_apm/railtie.rb +17 -0
  79. data/lib/elastic_apm/resque.rb +17 -0
  80. data/lib/elastic_apm/sinatra.rb +17 -0
  81. data/lib/elastic_apm/span.rb +20 -2
  82. data/lib/elastic_apm/span/context.rb +17 -0
  83. data/lib/elastic_apm/span/context/db.rb +17 -0
  84. data/lib/elastic_apm/span/context/destination.rb +17 -0
  85. data/lib/elastic_apm/span/context/http.rb +17 -0
  86. data/lib/elastic_apm/span_helpers.rb +17 -0
  87. data/lib/elastic_apm/spies.rb +33 -14
  88. data/lib/elastic_apm/spies/action_dispatch.rb +17 -0
  89. data/lib/elastic_apm/spies/delayed_job.rb +17 -0
  90. data/lib/elastic_apm/spies/dynamo_db.rb +58 -0
  91. data/lib/elastic_apm/spies/elasticsearch.rb +37 -2
  92. data/lib/elastic_apm/spies/faraday.rb +17 -0
  93. data/lib/elastic_apm/spies/http.rb +17 -0
  94. data/lib/elastic_apm/spies/json.rb +17 -0
  95. data/lib/elastic_apm/spies/mongo.rb +18 -1
  96. data/lib/elastic_apm/spies/net_http.rb +23 -2
  97. data/lib/elastic_apm/spies/rake.rb +17 -0
  98. data/lib/elastic_apm/spies/redis.rb +17 -0
  99. data/lib/elastic_apm/spies/resque.rb +19 -9
  100. data/lib/elastic_apm/spies/sequel.rb +18 -1
  101. data/lib/elastic_apm/spies/shoryuken.rb +17 -0
  102. data/lib/elastic_apm/spies/sidekiq.rb +17 -0
  103. data/lib/elastic_apm/spies/sinatra.rb +17 -0
  104. data/lib/elastic_apm/spies/sneakers.rb +17 -0
  105. data/lib/elastic_apm/spies/sucker_punch.rb +54 -0
  106. data/lib/elastic_apm/spies/tilt.rb +17 -0
  107. data/lib/elastic_apm/sql.rb +17 -0
  108. data/lib/elastic_apm/sql/signature.rb +17 -0
  109. data/lib/elastic_apm/sql/tokenizer.rb +17 -0
  110. data/lib/elastic_apm/sql/tokens.rb +17 -0
  111. data/lib/elastic_apm/sql_summarizer.rb +17 -0
  112. data/lib/elastic_apm/stacktrace.rb +17 -0
  113. data/lib/elastic_apm/stacktrace/frame.rb +17 -0
  114. data/lib/elastic_apm/stacktrace_builder.rb +17 -0
  115. data/lib/elastic_apm/subscriber.rb +17 -0
  116. data/lib/elastic_apm/trace_context.rb +17 -0
  117. data/lib/elastic_apm/trace_context/traceparent.rb +17 -0
  118. data/lib/elastic_apm/trace_context/tracestate.rb +17 -0
  119. data/lib/elastic_apm/transaction.rb +33 -5
  120. data/lib/elastic_apm/transport/base.rb +39 -23
  121. data/lib/elastic_apm/transport/connection.rb +17 -0
  122. data/lib/elastic_apm/transport/connection/http.rb +17 -0
  123. data/lib/elastic_apm/transport/connection/proxy_pipe.rb +22 -0
  124. data/lib/elastic_apm/transport/filters.rb +17 -0
  125. data/lib/elastic_apm/transport/filters/hash_sanitizer.rb +77 -0
  126. data/lib/elastic_apm/transport/filters/secrets_filter.rb +30 -56
  127. data/lib/elastic_apm/transport/headers.rb +17 -0
  128. data/lib/elastic_apm/transport/serializers.rb +17 -0
  129. data/lib/elastic_apm/transport/serializers/context_serializer.rb +17 -0
  130. data/lib/elastic_apm/transport/serializers/error_serializer.rb +17 -0
  131. data/lib/elastic_apm/transport/serializers/metadata_serializer.rb +44 -20
  132. data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +17 -0
  133. data/lib/elastic_apm/transport/serializers/span_serializer.rb +17 -0
  134. data/lib/elastic_apm/transport/serializers/transaction_serializer.rb +17 -0
  135. data/lib/elastic_apm/transport/user_agent.rb +17 -0
  136. data/lib/elastic_apm/transport/worker.rb +21 -0
  137. data/lib/elastic_apm/util.rb +17 -0
  138. data/lib/elastic_apm/util/inflector.rb +17 -0
  139. data/lib/elastic_apm/util/lru_cache.rb +17 -0
  140. data/lib/elastic_apm/util/throttle.rb +17 -0
  141. data/lib/elastic_apm/version.rb +18 -1
  142. metadata +12 -11
  143. data/.ci/downstreamTests.groovy +0 -185
  144. data/.ci/prepare-git-context.sh +0 -27
  145. data/codecov.yml +0 -32
@@ -0,0 +1,106 @@
1
+ [[tuning-and-overhead]]
2
+ == Performance tuning
3
+
4
+ Using any APM solution comes with trade-offs, and the Elastic APM Ruby Agent is no different.
5
+ Instrumenting your code, using timers, recording context data, etc., uses resources—for example:
6
+
7
+ * CPU time
8
+ * Memory
9
+ * Bandwidth
10
+ * Elasticsearch storage
11
+
12
+ We invest a lot of effort to ensure that the Ruby Agent is suitable for production code
13
+ and that its overhead remains as low as possible.
14
+ However, because every application is different, there are some knobs you can turn and tweak to adapt the Agent to your specific needs.
15
+
16
+ [float]
17
+ [[tuning-sample-rate]]
18
+ === Transaction sample rate
19
+
20
+ By default, the Agent samples every transaction.
21
+ The easiest way to reduce both the overhead of the agent and storage requirements,
22
+ is to tell it to do less, i.e., sample fewer transactions.
23
+ To do this, set the <<config-transaction-sample-rate,`transaction_sample_rate`>>
24
+ to a value between `0.0` and `1.0`—the percentage of transactions you'd like to randomly sample.
25
+ The Agent will still record the overall time and result of unsampled transactions,
26
+ but not context information, tags, or spans.
27
+
28
+ [float]
29
+ [[tuning-frame-context]]
30
+ === Collecting frame context
31
+
32
+ The Agent automatically captures several lines of source code around each frame location in the stack trace.
33
+ This enables the APM app to provide greater insight into exactly where an error or span is occurring in your code.
34
+ This insight does come at a cost—in terms of performance, stack trace collection is the most expensive thing the Agent does.
35
+
36
+ There are settings you can modify to control this behavior:
37
+
38
+ 1. Disable stack trace frame collection for short-duration spans by setting
39
+ <<config-span-frames-min-duration-ms,`span_frames_min_duration`>> to `0`.
40
+
41
+ 2. Modify the number of source code lines collected.
42
+ These settings are divided between app frames, which represent your application code,
43
+ and library frames, which represent the code of your dependencies.
44
+ Each of these categories are further split into separate error and span settings.
45
+ +
46
+ * <<config-source-lines-error-app-frames, `source_lines_error_app_frames`>>
47
+ * <<config-source-lines-error-library-frames,`source_lines_error_library_frames`>>
48
+ * <<config-source-lines-span-app-frames,`source_lines_span_app_frames`>>
49
+ * <<config-source-lines-span-library-frames,`source_lines_span_library_frames`>>
50
+
51
+ 3. If you're using the API to create a custom span, you can disable stack trace collection with the
52
+ <<api-agent-start_span,`include_stacktrace` argument>>.
53
+
54
+ Reading source files inside a running application can cause a lot of disk I/O,
55
+ and sending up source lines for each frame will have a network and storage cost that is quite high.
56
+ Turning these limits down will prevent storing excessive amounts of data in Elasticsearch.
57
+
58
+ [float]
59
+ [[tuning-queue]]
60
+ === Transaction queue
61
+
62
+ The Agent does not send every transaction as it happens.
63
+ Instead, to reduce load on the APM Server, the Agent uses a queue.
64
+ The queue is flushed periodically, or when it reaches a maximum size.
65
+
66
+ While this reduces the load on the APM Server, holding on to transaction data in a queue uses memory.
67
+ If you notice a large increase in memory use, try adjusting these settings:
68
+
69
+ * <<config-api-request-time,`api_request_time`>> to reduce the duration of a single streaming request.
70
+ This setting is helpful if you have a sustained high number of transactions.
71
+ * <<config-api-request-size,`api_request_size`>> to reduce the maximum size of one request.
72
+ This setting can help if you experience transaction peaks (a large number in a short period of time).
73
+
74
+ Keep in mind that reducing the value of either setting will cause the agent to send more HTTP requests to the APM Server,
75
+ potentially causing a higher load.
76
+
77
+ [float]
78
+ [[tuning-max-spans]]
79
+ === Spans per transaction
80
+
81
+ The number of spans per transaction will influence both how much time the agent spends in each transaction collecting contextual data,
82
+ and how much storage space is needed in Elasticsearch.
83
+ In our experience, most _usual_ transactions should have well below 100 spans.
84
+ In some cases, however, the number of spans can explode—for example:
85
+
86
+ * Long-running transactions
87
+ * Unoptimized code, e.g., doing hundreds of SQL queries in a loop
88
+
89
+ To avoid these edge cases which overload both the Agent and the APM Server,
90
+ the Agent will stop recording spans when a specified limit is reached.
91
+ This limit is configurable with <<config-transaction-max-spans,`transaction_max_spans`>>.
92
+
93
+ [float]
94
+ [[tuning-body-headers]]
95
+ === Capturing headers and request body
96
+
97
+ You can configure the Agent to capture headers and request bodies with
98
+ <<config-capture-headers,`capture_headers`>> and <<config-capture-body,`capture_body`>>.
99
+ By default, headers are captured and request bodies are not.
100
+
101
+ Depending on the nature of your POST requests, capturing request bodies for transactions may introduce noticeable overhead,
102
+ as well as increased storage use.
103
+ In most scenarios, we advise against enabling request body capturing for transactions, and only enabling it if necessary for errors.
104
+
105
+ Capturing request/response headers has less overhead on the agent than capturing request bodies,
106
+ but can have an impact on storage use.
@@ -9,8 +9,11 @@ endif::[]
9
9
 
10
10
  To get you off the ground, we’ve prepared guides for setting up the Agent with different frameworks:
11
11
 
12
+ * <<getting-started-rails,Rails>>
13
+ * <<getting-started-rack,Rack>>
14
+
15
+ For custom instrumentation, see the <<api>>.
16
+
12
17
  include::./getting-started-rails.asciidoc[]
13
18
 
14
19
  include::./getting-started-rack.asciidoc[]
15
-
16
- For custom instrumentation, see the <<api>>.
@@ -60,6 +60,7 @@ See <<getting-started-grape>>.
60
60
  We automatically instrument database actions using:
61
61
 
62
62
  - ActiveRecord (v4.2+)
63
+ - DynamoDB (v1.0+)
63
64
  - Elasticsearch (v0.9+)
64
65
  - Mongo (v2.1+)
65
66
  - Redis (v3.1+)
@@ -87,6 +88,7 @@ We automatically instrument background processing using:
87
88
  - Shoryuken
88
89
  - Sneakers (v2.12.0+) (Experimental, see https://github.com/elastic/apm-agent-ruby/pull/676[#676])
89
90
  - Resque (v2.0.0+)
91
+ - SuckerPunch (v2.0.0+)
90
92
 
91
93
  [float]
92
94
  [[supported-technologies-resque]]
@@ -113,6 +115,21 @@ I, [XXX #81227] INFO -- : Running before_first_fork hooks
113
115
  D, [XXX #81227] DEBUG -- : Starting ElasticAPM agent
114
116
  ----
115
117
 
118
+ Also be sure to set the Resque environment variable `RUN_AT_EXIT_HOOKS` to `true`. Otherwise, the fork may be
119
+ terminated before the agent has a chance to send all the fork's events to the APM server.
120
+
121
+ [float]
122
+ [[supported-technologies-sucker-punch]]
123
+ === SuckerPunch
124
+
125
+ Asynchronously executed jobs in SuckerPunch are automatically instrumented.
126
+
127
+ Note that errors raised in the user-defined `JobClass#perform` method will be first handled by the SuckerPunch exception
128
+ handler before being handled by the agent. The handler is accessed/set via `SuckerPunch.exception_handler` in version
129
+ 2.0. The agent transaction will be marked as successful unless you re-raise the error in the exception handler.
130
+ You can also explicitly report the error via <<api-agent-report,`ElasticAPM.report`>> in a custom SuckerPunch exception
131
+ handler.
132
+
116
133
  [float]
117
134
  [[supported-technologies-grpc]]
118
135
  === gRPC
@@ -135,4 +152,4 @@ To instrument a server, add the `ElasticAPM::GRPC::ServerInterceptor`.
135
152
  [source,ruby]
136
153
  ----
137
154
  GRPC::RpcServer.new(interceptors: [ElasticAPM::GRPC::ServerInterceptor.new])
138
- ----
155
+ ----
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  lib = File.expand_path('../lib', __FILE__)
2
19
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
20
  require 'elastic_apm/version'
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  # Make bundler auto-require work
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'erb'
@@ -51,7 +68,7 @@ module ElasticAPM
51
68
  # one, if it is provided.
52
69
  # Starts the agent if it is not running.
53
70
  # Stops and starts the agent if it is running.
54
- def restart(config = {})
71
+ def restart(config = nil)
55
72
  config ||= agent&.config
56
73
  stop if running?
57
74
  start(config)
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'elastic_apm/error'
@@ -34,9 +51,9 @@ module ElasticAPM
34
51
  LOCK.synchronize do
35
52
  return @instance if @instance
36
53
 
37
- unless config.active?
54
+ unless config.enabled?
38
55
  config.logger.debug format(
39
- "%sAgent disabled with `active: false'",
56
+ "%sAgent disabled with `enabled: false'",
40
57
  Logging::PREFIX
41
58
  )
42
59
  return
@@ -72,6 +89,7 @@ module ElasticAPM
72
89
  metrics: metrics,
73
90
  stacktrace_builder: stacktrace_builder
74
91
  ) { |event| enqueue event }
92
+ @pid = Process.pid
75
93
  end
76
94
 
77
95
  attr_reader(
@@ -145,6 +163,9 @@ module ElasticAPM
145
163
  context: nil,
146
164
  trace_context: nil
147
165
  )
166
+ return unless config.recording?
167
+ detect_forking!
168
+
148
169
  instrumenter.start_transaction(
149
170
  name,
150
171
  type,
@@ -170,6 +191,12 @@ module ElasticAPM
170
191
  parent: nil,
171
192
  sync: nil
172
193
  )
194
+ detect_forking!
195
+
196
+ # We don't check config.recording? because the span
197
+ # will not be created if there's no transaction.
198
+ # We want to use the recording value from the config
199
+ # that existed when start_transaction was called. ~estolfo
173
200
  instrumenter.start_span(
174
201
  name,
175
202
  type,
@@ -207,6 +234,8 @@ module ElasticAPM
207
234
  # errors
208
235
 
209
236
  def report(exception, context: nil, handled: true)
237
+ return unless config.recording?
238
+ detect_forking!
210
239
  return if config.filter_exception_types.include?(exception.class.to_s)
211
240
 
212
241
  error = @error_builder.build_exception(
@@ -219,6 +248,9 @@ module ElasticAPM
219
248
  end
220
249
 
221
250
  def report_message(message, context: nil, backtrace: nil, **attrs)
251
+ return unless config.recording?
252
+ detect_forking!
253
+
222
254
  error = @error_builder.build_log(
223
255
  message,
224
256
  context: context,
@@ -240,5 +272,19 @@ module ElasticAPM
240
272
  def inspect
241
273
  super.split.first + '>'
242
274
  end
275
+
276
+ def detect_forking!
277
+ return if @pid == Process.pid
278
+
279
+ config.logger.debug "Detected forking,
280
+ restarting threads in process [PID:#{Process.pid}]"
281
+
282
+ central_config.handle_forking!
283
+ transport.handle_forking!
284
+ instrumenter.handle_forking!
285
+ metrics.handle_forking!
286
+
287
+ @pid = Process.pid
288
+ end
243
289
  end
244
290
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'elastic_apm/central_config/cache_control'
@@ -81,15 +98,16 @@ module ElasticAPM
81
98
  update[key] = @modified_options.delete(key)
82
99
  end
83
100
 
84
- update_config(update)
101
+ @config.replace_options(update)
85
102
  end
86
103
 
87
- private
88
-
89
- def update_config(new_options)
90
- @config = config.dup.tap { |new_config| new_config.assign(new_options) }
104
+ def handle_forking!
105
+ stop
106
+ start
91
107
  end
92
108
 
109
+ private
110
+
93
111
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
94
112
  def handle_success(resp)
95
113
  if (etag = resp.headers['Etag'])
@@ -104,9 +122,10 @@ module ElasticAPM
104
122
  assign(update)
105
123
  end
106
124
 
107
- if @modified_options.any?
125
+ if update && update.any?
108
126
  info 'Updated config from Kibana'
109
- debug 'Modified: %s', @modified_options.inspect
127
+ debug 'Modified: %s', update.inspect
128
+ debug 'Modified original options: %s', @modified_options.inspect
110
129
  end
111
130
  end
112
131
 
@@ -151,7 +170,7 @@ module ElasticAPM
151
170
  def schedule_next_fetch(resp = nil)
152
171
  headers = resp&.headers
153
172
  seconds =
154
- if headers['Cache-Control']
173
+ if headers && headers['Cache-Control']
155
174
  CacheControl.new(headers['Cache-Control']).max_age
156
175
  else
157
176
  DEFAULT_MAX_AGE
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'elastic_apm/config/options'
@@ -19,13 +36,13 @@ module ElasticAPM
19
36
  option :secret_token, type: :string
20
37
  option :api_key, type: :string
21
38
 
22
- option :active, type: :bool, default: true
23
39
  option :api_buffer_size, type: :int, default: 256
24
40
  option :api_request_size, type: :bytes, default: '750kb', converter: Bytes.new
25
41
  option :api_request_time, type: :float, default: '10s', converter: Duration.new
26
42
  option :breakdown_metrics, type: :bool, default: true
27
43
  option :capture_body, type: :string, default: 'off'
28
44
  option :capture_headers, type: :bool, default: true
45
+ option :capture_elasticsearch_queries, type: :bool, default: false
29
46
  option :capture_env, type: :bool, default: true
30
47
  option :central_config, type: :bool, default: true
31
48
  option :current_user_email_method, type: :string, default: 'email'
@@ -38,6 +55,7 @@ module ElasticAPM
38
55
  option :disable_start_message, type: :bool, default: false
39
56
  option :disable_instrumentations, type: :list, default: %w[json]
40
57
  option :disabled_spies, type: :list, default: []
58
+ option :enabled, type: :bool, default: true
41
59
  option :environment, type: :string, default: ENV['RAILS_ENV'] || ENV['RACK_ENV']
42
60
  option :framework_name, type: :string
43
61
  option :framework_version, type: :string
@@ -57,9 +75,11 @@ module ElasticAPM
57
75
  option :proxy_password, type: :string
58
76
  option :proxy_port, type: :int
59
77
  option :proxy_username, type: :string
78
+ option :recording, type: :bool, default: true
60
79
  option :sanitize_field_names, type: :list, default: [], converter: WildcardPatternList.new
61
80
  option :server_ca_cert, type: :string
62
81
  option :service_name, type: :string
82
+ option :service_node_name, type: :string
63
83
  option :service_version, type: :string
64
84
  option :source_lines_error_app_frames, type: :int, default: 5
65
85
  option :source_lines_error_library_frames, type: :int, default: 0
@@ -67,6 +87,7 @@ module ElasticAPM
67
87
  option :source_lines_span_library_frames, type: :int, default: 0
68
88
  option :span_frames_min_duration, type: :float, default: '5ms', converter: Duration.new(default_unit: 'ms')
69
89
  option :stack_trace_limit, type: :int, default: 999_999
90
+ option :transaction_ignore_urls, type: :list, default: [], converter: WildcardPatternList.new
70
91
  option :transaction_max_spans, type: :int, default: 500
71
92
  option :transaction_sample_rate, type: :float, default: 1.0
72
93
  option :use_elastic_traceparent_header, type: :bool, default: true
@@ -111,6 +132,7 @@ module ElasticAPM
111
132
  %w[
112
133
  action_dispatch
113
134
  delayed_job
135
+ dynamo_db
114
136
  elasticsearch
115
137
  faraday
116
138
  http
@@ -125,6 +147,7 @@ module ElasticAPM
125
147
  sidekiq
126
148
  sinatra
127
149
  sneakers
150
+ sucker_punch
128
151
  tilt
129
152
  ]
130
153
  end
@@ -138,6 +161,15 @@ module ElasticAPM
138
161
  warn "The option `#{name}' has been removed."
139
162
  end
140
163
 
164
+ def replace_options(new_options)
165
+ return if new_options.nil? || new_options.empty?
166
+ options_copy = @options.dup
167
+ new_options.each do |key, value|
168
+ options_copy.fetch(key.to_sym).set(value)
169
+ end
170
+ @options = options_copy
171
+ end
172
+
141
173
  def app=(app)
142
174
  case app_type?(app)
143
175
  when :sinatra
@@ -203,6 +235,13 @@ module ElasticAPM
203
235
  self.default_labels = value
204
236
  end
205
237
 
238
+ def ignore_url_patterns=(value)
239
+ warn '[DEPRECATED] The option ignore_url_patterns is being removed. ' \
240
+ 'Consider using transaction_ignore_urls instead.'
241
+
242
+ set(:ignore_url_patterns, value)
243
+ end
244
+
206
245
  def custom_key_filters=(value)
207
246
  unless value == self.class.schema[:custom_key_filters][:default]
208
247
  warn '[DEPRECATED] The option custom_key_filters is being removed. ' \
@@ -216,6 +255,11 @@ module ElasticAPM
216
255
  disable_instrumentations
217
256
  end
218
257
 
258
+ def active
259
+ enabled
260
+ end
261
+ alias active? active
262
+
219
263
  def disabled_instrumentations=(value)
220
264
  warn '[DEPRECATED] The option disabled_instrumentations has been ' \
221
265
  'renamed to disable_instrumentations to align with other agents.'
@@ -227,6 +271,12 @@ module ElasticAPM
227
271
  'use use_legacy_sql_parser and please report why you wish to do so.'
228
272
  end
229
273
 
274
+ def active=(value)
275
+ warn '[DEPRECATED] The option active has been renamed to enabled ' \
276
+ 'to align with other agents and with the remote config.'
277
+ self.enabled = value
278
+ end
279
+
230
280
  private
231
281
 
232
282
  def load_config_file
@@ -276,7 +326,7 @@ module ElasticAPM
276
326
  self.logger ||= ::Rails.logger
277
327
 
278
328
  self.__root_path = ::Rails.root.to_s
279
- self.__view_paths = app.config.paths['app/views'].existent
329
+ self.__view_paths = app.config.paths['app/views'].existent + [::Rails.root.to_s]
280
330
  end
281
331
 
282
332
  def rails_app_name(app)