elastic-apm 3.6.0 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/Jenkinsfile +72 -32
- data/.ci/downstreamTests.groovy +27 -20
- data/.ci/jobs/defaults.yml +1 -1
- data/.rubocop.yml +3 -0
- data/CHANGELOG.asciidoc +27 -0
- data/Gemfile +18 -0
- data/Rakefile +28 -1
- data/docs/configuration.asciidoc +80 -16
- data/docs/getting-started-rails.asciidoc +2 -0
- data/docs/images/dynamic-config.svg +1 -0
- data/docs/index.asciidoc +2 -1
- data/docs/introduction.asciidoc +2 -1
- data/docs/performance-tuning.asciidoc +106 -0
- data/docs/set-up.asciidoc +5 -2
- data/docs/supported-technologies.asciidoc +16 -0
- data/elastic-apm.gemspec +17 -0
- data/lib/elastic-apm.rb +17 -0
- data/lib/elastic_apm.rb +18 -1
- data/lib/elastic_apm/agent.rb +48 -2
- data/lib/elastic_apm/central_config.rb +27 -8
- data/lib/elastic_apm/central_config/cache_control.rb +17 -0
- data/lib/elastic_apm/child_durations.rb +17 -0
- data/lib/elastic_apm/config.rb +47 -2
- data/lib/elastic_apm/config/bytes.rb +17 -0
- data/lib/elastic_apm/config/duration.rb +17 -0
- data/lib/elastic_apm/config/options.rb +18 -1
- data/lib/elastic_apm/config/regexp_list.rb +17 -0
- data/lib/elastic_apm/config/wildcard_pattern_list.rb +17 -0
- data/lib/elastic_apm/context.rb +17 -0
- data/lib/elastic_apm/context/request.rb +17 -0
- data/lib/elastic_apm/context/request/socket.rb +17 -0
- data/lib/elastic_apm/context/request/url.rb +17 -0
- data/lib/elastic_apm/context/response.rb +17 -0
- data/lib/elastic_apm/context/user.rb +17 -0
- data/lib/elastic_apm/context_builder.rb +17 -0
- data/lib/elastic_apm/deprecations.rb +17 -0
- data/lib/elastic_apm/error.rb +17 -0
- data/lib/elastic_apm/error/exception.rb +17 -0
- data/lib/elastic_apm/error/log.rb +17 -0
- data/lib/elastic_apm/error_builder.rb +17 -0
- data/lib/elastic_apm/grape.rb +17 -0
- data/lib/elastic_apm/graphql.rb +17 -0
- data/lib/elastic_apm/grpc.rb +17 -0
- data/lib/elastic_apm/instrumenter.rb +29 -4
- data/lib/elastic_apm/internal_error.rb +17 -0
- data/lib/elastic_apm/logging.rb +17 -0
- data/lib/elastic_apm/metadata.rb +17 -0
- data/lib/elastic_apm/metadata/process_info.rb +17 -0
- data/lib/elastic_apm/metadata/service_info.rb +17 -0
- data/lib/elastic_apm/metadata/system_info.rb +17 -0
- data/lib/elastic_apm/metadata/system_info/container_info.rb +17 -0
- data/lib/elastic_apm/metrics.rb +33 -1
- data/lib/elastic_apm/metrics/breakdown_set.rb +17 -0
- data/lib/elastic_apm/metrics/cpu_mem_set.rb +17 -0
- data/lib/elastic_apm/metrics/metric.rb +17 -0
- data/lib/elastic_apm/metrics/set.rb +17 -0
- data/lib/elastic_apm/metrics/span_scoped_set.rb +17 -0
- data/lib/elastic_apm/metrics/transaction_set.rb +17 -0
- data/lib/elastic_apm/metrics/vm_set.rb +17 -0
- data/lib/elastic_apm/metricset.rb +17 -0
- data/lib/elastic_apm/middleware.rb +17 -0
- data/lib/elastic_apm/naively_hashable.rb +17 -0
- data/lib/elastic_apm/normalizers.rb +17 -0
- data/lib/elastic_apm/normalizers/grape.rb +17 -0
- data/lib/elastic_apm/normalizers/grape/endpoint_run.rb +18 -1
- data/lib/elastic_apm/normalizers/rails.rb +17 -0
- data/lib/elastic_apm/normalizers/rails/action_controller.rb +17 -0
- data/lib/elastic_apm/normalizers/rails/action_mailer.rb +17 -0
- data/lib/elastic_apm/normalizers/rails/action_view.rb +17 -0
- data/lib/elastic_apm/normalizers/rails/active_record.rb +17 -0
- data/lib/elastic_apm/opentracing.rb +17 -0
- data/lib/elastic_apm/rails.rb +17 -0
- data/lib/elastic_apm/railtie.rb +17 -0
- data/lib/elastic_apm/resque.rb +17 -0
- data/lib/elastic_apm/sinatra.rb +17 -0
- data/lib/elastic_apm/span.rb +17 -0
- data/lib/elastic_apm/span/context.rb +17 -0
- data/lib/elastic_apm/span/context/db.rb +17 -0
- data/lib/elastic_apm/span/context/destination.rb +17 -0
- data/lib/elastic_apm/span/context/http.rb +17 -0
- data/lib/elastic_apm/span_helpers.rb +17 -0
- data/lib/elastic_apm/spies.rb +17 -0
- data/lib/elastic_apm/spies/action_dispatch.rb +17 -0
- data/lib/elastic_apm/spies/delayed_job.rb +17 -0
- data/lib/elastic_apm/spies/elasticsearch.rb +17 -0
- data/lib/elastic_apm/spies/faraday.rb +17 -0
- data/lib/elastic_apm/spies/http.rb +17 -0
- data/lib/elastic_apm/spies/json.rb +17 -0
- data/lib/elastic_apm/spies/mongo.rb +17 -0
- data/lib/elastic_apm/spies/net_http.rb +17 -0
- data/lib/elastic_apm/spies/rake.rb +17 -0
- data/lib/elastic_apm/spies/redis.rb +17 -0
- data/lib/elastic_apm/spies/resque.rb +19 -9
- data/lib/elastic_apm/spies/sequel.rb +17 -0
- data/lib/elastic_apm/spies/shoryuken.rb +17 -0
- data/lib/elastic_apm/spies/sidekiq.rb +17 -0
- data/lib/elastic_apm/spies/sinatra.rb +17 -0
- data/lib/elastic_apm/spies/sneakers.rb +17 -0
- data/lib/elastic_apm/spies/sucker_punch.rb +54 -0
- data/lib/elastic_apm/spies/tilt.rb +17 -0
- data/lib/elastic_apm/sql.rb +17 -0
- data/lib/elastic_apm/sql/signature.rb +17 -0
- data/lib/elastic_apm/sql/tokenizer.rb +17 -0
- data/lib/elastic_apm/sql/tokens.rb +17 -0
- data/lib/elastic_apm/sql_summarizer.rb +17 -0
- data/lib/elastic_apm/stacktrace.rb +17 -0
- data/lib/elastic_apm/stacktrace/frame.rb +17 -0
- data/lib/elastic_apm/stacktrace_builder.rb +17 -0
- data/lib/elastic_apm/subscriber.rb +17 -0
- data/lib/elastic_apm/trace_context.rb +17 -0
- data/lib/elastic_apm/trace_context/traceparent.rb +17 -0
- data/lib/elastic_apm/trace_context/tracestate.rb +17 -0
- data/lib/elastic_apm/transaction.rb +33 -5
- data/lib/elastic_apm/transport/base.rb +39 -23
- data/lib/elastic_apm/transport/connection.rb +17 -0
- data/lib/elastic_apm/transport/connection/http.rb +17 -0
- data/lib/elastic_apm/transport/connection/proxy_pipe.rb +22 -0
- data/lib/elastic_apm/transport/filters.rb +17 -0
- data/lib/elastic_apm/transport/filters/secrets_filter.rb +17 -0
- data/lib/elastic_apm/transport/headers.rb +17 -0
- data/lib/elastic_apm/transport/serializers.rb +17 -0
- data/lib/elastic_apm/transport/serializers/context_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/error_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/metadata_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/span_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/transaction_serializer.rb +17 -0
- data/lib/elastic_apm/transport/user_agent.rb +17 -0
- data/lib/elastic_apm/transport/worker.rb +17 -0
- data/lib/elastic_apm/util.rb +17 -0
- data/lib/elastic_apm/util/inflector.rb +17 -0
- data/lib/elastic_apm/util/lru_cache.rb +17 -0
- data/lib/elastic_apm/util/throttle.rb +17 -0
- data/lib/elastic_apm/version.rb +18 -1
- metadata +5 -5
- data/.ci/prepare-git-context.sh +0 -27
- data/codecov.yml +0 -32
@@ -25,4 +25,6 @@ server_url: http://localhost:8200
|
|
25
25
|
secret_token: ''
|
26
26
|
----
|
27
27
|
|
28
|
+
Or if you prefer environment variables, skip the file and set `ELASTIC_APM_SERVER_URL` and `ELASTIC_APM_SECRET_TOKEN` in your local or server environment.
|
29
|
+
|
28
30
|
This automatically sets up error logging and performance tracking but of course there are knobs to turn if you'd like to. See <<configuration>>.
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="59" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="59" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#9f9f9f" d="M0 0h0v20H0z"/><path fill="#9f9f9f" d="M0 0h59v20H0z"/><path fill="url(#b)" d="M0 0h59v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="295" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="490">Dynamic</text><text x="295" y="140" transform="scale(.1)" textLength="490">Dynamic</text></g> </svg>
|
data/docs/index.asciidoc
CHANGED
data/docs/introduction.asciidoc
CHANGED
@@ -32,4 +32,5 @@ You can then use the APM app in Kibana to gain insight into latency issues and e
|
|
32
32
|
=== Additional Components
|
33
33
|
|
34
34
|
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].
|
35
|
-
|
35
|
+
The {apm-overview-ref-v}/index.html[APM Overview] provides details on how these components work together,
|
36
|
+
and provides a matrix outlining {apm-overview-ref-v}/agent-server-compatibility.html[Agent and Server compatibility].
|
@@ -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.
|
data/docs/set-up.asciidoc
CHANGED
@@ -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>>.
|
@@ -87,6 +87,7 @@ We automatically instrument background processing using:
|
|
87
87
|
- Shoryuken
|
88
88
|
- Sneakers (v2.12.0+) (Experimental, see https://github.com/elastic/apm-agent-ruby/pull/676[#676])
|
89
89
|
- Resque (v2.0.0+)
|
90
|
+
- SuckerPunch (v2.0.0+)
|
90
91
|
|
91
92
|
[float]
|
92
93
|
[[supported-technologies-resque]]
|
@@ -113,6 +114,21 @@ I, [XXX #81227] INFO -- : Running before_first_fork hooks
|
|
113
114
|
D, [XXX #81227] DEBUG -- : Starting ElasticAPM agent
|
114
115
|
----
|
115
116
|
|
117
|
+
Also be sure to set the Resque environment variable `RUN_AT_EXIT_HOOKS` to `true`. Otherwise, the fork may be
|
118
|
+
terminated before the agent has a chance to send all the fork's events to the APM server.
|
119
|
+
|
120
|
+
[float]
|
121
|
+
[[supported-technologies-sucker-punch]]
|
122
|
+
=== SuckerPunch
|
123
|
+
|
124
|
+
Asynchronously executed jobs in SuckerPunch are automatically instrumented.
|
125
|
+
|
126
|
+
Note that errors raised in the user-defined `JobClass#perform` method will be first handled by the SuckerPunch exception
|
127
|
+
handler before being handled by the agent. The handler is accessed/set via `SuckerPunch.exception_handler` in version
|
128
|
+
2.0. The agent transaction will be marked as successful unless you re-raise the error in the exception handler.
|
129
|
+
You can also explicitly report the error via <<api-agent-report,`ElasticAPM.report`>> in a custom SuckerPunch exception
|
130
|
+
handler.
|
131
|
+
|
116
132
|
[float]
|
117
133
|
[[supported-technologies-grpc]]
|
118
134
|
=== gRPC
|
data/elastic-apm.gemspec
CHANGED
@@ -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'
|
data/lib/elastic-apm.rb
CHANGED
@@ -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
|
data/lib/elastic_apm.rb
CHANGED
@@ -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)
|
data/lib/elastic_apm/agent.rb
CHANGED
@@ -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.
|
54
|
+
unless config.enabled?
|
38
55
|
config.logger.debug format(
|
39
|
-
"%sAgent disabled with `
|
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
|
-
|
101
|
+
@config.replace_options(update)
|
85
102
|
end
|
86
103
|
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
125
|
+
if update && update.any?
|
108
126
|
info 'Updated config from Kibana'
|
109
|
-
debug 'Modified: %s',
|
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
|