atatus 1.3.0 → 1.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +72 -22
- data/LICENSE +1 -1
- data/atatus.gemspec +2 -2
- data/lib/atatus.rb +76 -16
- data/lib/atatus/agent.rb +78 -29
- data/lib/atatus/central_config.rb +72 -27
- data/lib/atatus/central_config/cache_control.rb +18 -1
- data/lib/atatus/child_durations.rb +64 -0
- data/lib/atatus/collector/base.rb +61 -29
- data/lib/atatus/collector/builder.rb +46 -2
- data/lib/atatus/collector/hist.rb +54 -0
- data/lib/atatus/collector/transport.rb +41 -11
- data/lib/atatus/config.rb +129 -28
- data/lib/atatus/config/bytes.rb +17 -0
- data/lib/atatus/config/duration.rb +17 -0
- data/lib/atatus/config/options.rb +29 -9
- data/lib/atatus/config/regexp_list.rb +17 -0
- data/lib/atatus/config/wildcard_pattern_list.rb +64 -0
- data/lib/atatus/context.rb +32 -1
- data/lib/atatus/context/request.rb +17 -0
- data/lib/atatus/context/request/socket.rb +18 -1
- data/lib/atatus/context/request/url.rb +17 -0
- data/lib/atatus/context/response.rb +27 -2
- data/lib/atatus/context/user.rb +17 -0
- data/lib/atatus/context_builder.rb +19 -4
- data/lib/atatus/deprecations.rb +17 -0
- data/lib/atatus/error.rb +27 -0
- data/lib/atatus/error/exception.rb +24 -0
- data/lib/atatus/error/log.rb +17 -0
- data/lib/atatus/error_builder.rb +17 -2
- data/lib/atatus/grape.rb +62 -0
- data/lib/atatus/graphql.rb +91 -0
- data/lib/atatus/grpc.rb +99 -0
- data/lib/atatus/instrumenter.rb +135 -30
- data/lib/atatus/internal_error.rb +17 -0
- data/lib/atatus/logging.rb +17 -2
- data/lib/atatus/metadata.rb +17 -0
- data/lib/atatus/metadata/process_info.rb +17 -0
- data/lib/atatus/metadata/service_info.rb +21 -6
- data/lib/atatus/metadata/system_info.rb +22 -3
- data/lib/atatus/metadata/system_info/container_info.rb +49 -10
- data/lib/atatus/metadata/system_info/hw_info.rb +1 -1
- data/lib/atatus/metrics.rb +69 -27
- data/lib/atatus/metrics/breakdown_set.rb +31 -0
- data/lib/atatus/metrics/{cpu_mem.rb → cpu_mem_set.rb} +110 -63
- data/lib/atatus/metrics/metric.rb +140 -0
- data/lib/atatus/metrics/set.rb +123 -0
- data/lib/atatus/metrics/span_scoped_set.rb +56 -0
- data/lib/atatus/metrics/transaction_set.rb +26 -0
- data/lib/atatus/metrics/vm_set.rb +58 -0
- data/lib/atatus/metricset.rb +48 -4
- data/lib/atatus/middleware.rb +28 -8
- data/lib/atatus/naively_hashable.rb +17 -0
- data/lib/atatus/normalizers.rb +23 -9
- data/lib/atatus/normalizers/grape.rb +22 -0
- data/lib/atatus/normalizers/grape/endpoint_run.rb +65 -0
- data/lib/atatus/normalizers/rails.rb +27 -0
- data/lib/atatus/normalizers/rails/action_controller.rb +44 -0
- data/lib/atatus/normalizers/rails/action_mailer.rb +43 -0
- data/lib/atatus/normalizers/{action_view.rb → rails/action_view.rb} +17 -0
- data/lib/atatus/normalizers/rails/active_record.rb +80 -0
- data/lib/atatus/opentracing.rb +75 -42
- data/lib/atatus/rails.rb +29 -13
- data/lib/atatus/railtie.rb +19 -6
- data/lib/atatus/resque.rb +29 -0
- data/lib/atatus/sinatra.rb +53 -0
- data/lib/atatus/span.rb +44 -15
- data/lib/atatus/span/context.rb +43 -28
- data/lib/atatus/span/context/db.rb +43 -0
- data/lib/atatus/span/context/destination.rb +77 -0
- data/lib/atatus/span/context/http.rb +43 -0
- data/lib/atatus/span_helpers.rb +18 -1
- data/lib/atatus/spies.rb +33 -15
- data/lib/atatus/spies/action_dispatch.rb +27 -6
- data/lib/atatus/spies/delayed_job.rb +26 -5
- data/lib/atatus/spies/dynamo_db.rb +62 -0
- data/lib/atatus/spies/elasticsearch.rb +53 -7
- data/lib/atatus/spies/faraday.rb +54 -20
- data/lib/atatus/spies/http.rb +36 -6
- data/lib/atatus/spies/json.rb +18 -0
- data/lib/atatus/spies/mongo.rb +41 -10
- data/lib/atatus/spies/net_http.rb +52 -11
- data/lib/atatus/spies/rake.rb +42 -23
- data/lib/atatus/spies/redis.rb +17 -0
- data/lib/atatus/spies/resque.rb +57 -0
- data/lib/atatus/spies/sequel.rb +54 -17
- data/lib/atatus/spies/shoryuken.rb +69 -0
- data/lib/atatus/spies/sidekiq.rb +46 -25
- data/lib/atatus/spies/sinatra.rb +20 -4
- data/lib/atatus/spies/sneakers.rb +74 -0
- data/lib/atatus/spies/sucker_punch.rb +58 -0
- data/lib/atatus/spies/tilt.rb +20 -1
- data/lib/atatus/sql.rb +36 -0
- data/lib/atatus/sql/signature.rb +169 -0
- data/lib/atatus/sql/tokenizer.rb +264 -0
- data/lib/atatus/sql/tokens.rb +63 -0
- data/lib/atatus/sql_summarizer.rb +24 -6
- data/lib/atatus/stacktrace.rb +17 -0
- data/lib/atatus/stacktrace/frame.rb +17 -3
- data/lib/atatus/stacktrace_builder.rb +23 -3
- data/lib/atatus/subscriber.rb +23 -4
- data/lib/atatus/trace_context.rb +84 -51
- data/lib/atatus/trace_context/traceparent.rb +111 -0
- data/lib/atatus/trace_context/tracestate.rb +148 -0
- data/lib/atatus/transaction.rb +74 -18
- data/lib/atatus/transport/base.rb +44 -27
- data/lib/atatus/transport/connection.rb +28 -72
- data/lib/atatus/transport/connection/http.rb +58 -35
- data/lib/atatus/transport/connection/proxy_pipe.rb +24 -5
- data/lib/atatus/transport/filters.rb +18 -1
- data/lib/atatus/transport/filters/hash_sanitizer.rb +77 -0
- data/lib/atatus/transport/filters/secrets_filter.rb +30 -55
- data/lib/atatus/transport/headers.rb +83 -0
- data/lib/atatus/transport/serializers.rb +17 -5
- data/lib/atatus/transport/serializers/context_serializer.rb +30 -3
- data/lib/atatus/transport/serializers/error_serializer.rb +17 -2
- data/lib/atatus/transport/serializers/metadata_serializer.rb +44 -22
- data/lib/atatus/transport/serializers/metricset_serializer.rb +34 -6
- data/lib/atatus/transport/serializers/span_serializer.rb +47 -12
- data/lib/atatus/transport/serializers/transaction_serializer.rb +18 -2
- data/lib/atatus/transport/user_agent.rb +48 -0
- data/lib/atatus/transport/worker.rb +31 -7
- data/lib/atatus/util.rb +18 -1
- data/lib/atatus/util/inflector.rb +17 -0
- data/lib/atatus/util/lru_cache.rb +17 -0
- data/lib/atatus/util/throttle.rb +17 -0
- data/lib/atatus/version.rb +19 -1
- metadata +46 -26
- data/Rakefile +0 -19
- data/bench/.gitignore +0 -2
- data/bench/app.rb +0 -53
- data/bench/benchmark.rb +0 -36
- data/bench/report.rb +0 -55
- data/bench/rubyprof.rb +0 -39
- data/bench/stackprof.rb +0 -23
- data/bin/build_docs +0 -5
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/bin/with_framework +0 -7
- data/lib/atatus/metrics/vm.rb +0 -60
- data/lib/atatus/normalizers/action_controller.rb +0 -27
- data/lib/atatus/normalizers/action_mailer.rb +0 -26
- data/lib/atatus/normalizers/active_record.rb +0 -45
- data/lib/atatus/util/prefixed_logger.rb +0 -18
- data/vendor/.gitkeep +0 -0
data/lib/atatus/spies/redis.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
|
module Atatus
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
|
|
18
|
+
# frozen_string_literal: true
|
|
19
|
+
|
|
20
|
+
module Atatus
|
|
21
|
+
# @api private
|
|
22
|
+
module Spies
|
|
23
|
+
# @api private
|
|
24
|
+
class ResqueSpy
|
|
25
|
+
TYPE = 'Resque'
|
|
26
|
+
|
|
27
|
+
def install
|
|
28
|
+
install_perform_spy
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def install_perform_spy
|
|
32
|
+
if defined?(::Resque) && defined?(::Resque::Job)
|
|
33
|
+
|
|
34
|
+
::Resque::Job.class_eval do
|
|
35
|
+
alias :perform_without_atatus :perform
|
|
36
|
+
|
|
37
|
+
def perform
|
|
38
|
+
name = @payload && @payload['class']&.to_s
|
|
39
|
+
transaction = Atatus.start_transaction(name, TYPE)
|
|
40
|
+
perform_without_atatus
|
|
41
|
+
transaction.done 'success'
|
|
42
|
+
rescue ::Exception => e
|
|
43
|
+
Atatus.report(e, handled: false)
|
|
44
|
+
transaction.done 'error' if transaction
|
|
45
|
+
raise
|
|
46
|
+
ensure
|
|
47
|
+
Atatus.end_transaction
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
register 'Resque', 'resque', ResqueSpy.new
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/atatus/spies/sequel.rb
CHANGED
|
@@ -1,47 +1,84 @@
|
|
|
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
|
-
require 'atatus/
|
|
20
|
+
require 'atatus/sql'
|
|
4
21
|
|
|
5
22
|
module Atatus
|
|
6
23
|
# @api private
|
|
7
24
|
module Spies
|
|
8
25
|
# @api private
|
|
9
26
|
class SequelSpy
|
|
10
|
-
TYPE = 'db
|
|
27
|
+
TYPE = 'db'
|
|
28
|
+
ACTION = 'query'
|
|
11
29
|
|
|
12
30
|
def self.summarizer
|
|
13
|
-
@summarizer ||=
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.build_context(sql, opts)
|
|
17
|
-
Span::Context.new(
|
|
18
|
-
db: { statement: sql, type: 'sql', user: opts[:user] }
|
|
19
|
-
)
|
|
31
|
+
@summarizer ||= Sql.summarizer
|
|
20
32
|
end
|
|
21
33
|
|
|
22
|
-
# rubocop:disable Metrics/MethodLength
|
|
23
34
|
def install
|
|
24
35
|
require 'sequel/database/logging'
|
|
25
36
|
|
|
26
37
|
if defined?(::Sequel) && defined?(::Sequel::Database)
|
|
38
|
+
|
|
27
39
|
::Sequel::Database.class_eval do
|
|
28
40
|
alias log_connection_yield_without_apm log_connection_yield
|
|
29
41
|
|
|
30
|
-
def log_connection_yield(sql,
|
|
42
|
+
def log_connection_yield(sql, connection, args = nil, &block)
|
|
31
43
|
unless Atatus.current_transaction
|
|
32
|
-
return log_connection_yield_without_apm(
|
|
44
|
+
return log_connection_yield_without_apm(
|
|
45
|
+
sql, connection, args, &block
|
|
46
|
+
)
|
|
33
47
|
end
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
name = summarizer.summarize sql
|
|
37
|
-
context = Atatus::Spies::SequelSpy.build_context(sql, opts)
|
|
49
|
+
subtype = database_type.to_s
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
name =
|
|
52
|
+
Atatus::Spies::SequelSpy.summarizer.summarize sql
|
|
53
|
+
|
|
54
|
+
context = Atatus::Span::Context.new(
|
|
55
|
+
db: { statement: sql, type: 'sql', user: opts[:user] },
|
|
56
|
+
destination: { name: subtype, resource: subtype, type: TYPE }
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
span = Atatus.start_span(
|
|
60
|
+
name,
|
|
61
|
+
TYPE,
|
|
62
|
+
subtype: subtype,
|
|
63
|
+
action: ACTION,
|
|
64
|
+
context: context
|
|
65
|
+
)
|
|
66
|
+
yield.tap do |result|
|
|
67
|
+
if name =~ /^(UPDATE|DELETE)/
|
|
68
|
+
if connection.respond_to?(:changes)
|
|
69
|
+
span.context.db.rows_affected = connection.changes
|
|
70
|
+
elsif result.is_a?(Integer)
|
|
71
|
+
span.context.db.rows_affected = result
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
ensure
|
|
76
|
+
Atatus.end_span
|
|
40
77
|
end
|
|
41
78
|
end
|
|
79
|
+
|
|
42
80
|
end
|
|
43
81
|
end
|
|
44
|
-
# rubocop:enable Metrics/MethodLength
|
|
45
82
|
end
|
|
46
83
|
|
|
47
84
|
register 'Sequel', 'sequel', SequelSpy.new
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
|
|
18
|
+
# frozen_string_literal: true
|
|
19
|
+
|
|
20
|
+
module Atatus
|
|
21
|
+
# @api private
|
|
22
|
+
module Spies
|
|
23
|
+
# @api private
|
|
24
|
+
class ShoryukenSpy
|
|
25
|
+
# @api private
|
|
26
|
+
class Middleware
|
|
27
|
+
def call(worker_instance, queue, sqs_msg, body)
|
|
28
|
+
transaction =
|
|
29
|
+
Atatus.start_transaction(
|
|
30
|
+
job_class(worker_instance, body),
|
|
31
|
+
'shoryuken.job'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
Atatus.set_label('shoryuken.id', sqs_msg.message_id)
|
|
35
|
+
Atatus.set_label('shoryuken.queue', queue)
|
|
36
|
+
|
|
37
|
+
yield
|
|
38
|
+
|
|
39
|
+
transaction&.done :success
|
|
40
|
+
rescue ::Exception => e
|
|
41
|
+
Atatus.report(e, handled: false)
|
|
42
|
+
transaction&.done :error
|
|
43
|
+
raise
|
|
44
|
+
ensure
|
|
45
|
+
Atatus.end_transaction
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def job_class(worker_instance, body)
|
|
51
|
+
klass = body['job_class'] if body.is_a?(Hash)
|
|
52
|
+
klass || worker_instance.class.name
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def install
|
|
57
|
+
if defined?(::Shoryuken)
|
|
58
|
+
|
|
59
|
+
::Shoryuken.server_middleware do |chain|
|
|
60
|
+
chain.add Middleware
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
register 'Shoryuken', 'shoryuken', ShoryukenSpy.new
|
|
68
|
+
end
|
|
69
|
+
end
|
data/lib/atatus/spies/sidekiq.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
|
module Atatus
|
|
@@ -10,7 +27,6 @@ module Atatus
|
|
|
10
27
|
|
|
11
28
|
# @api private
|
|
12
29
|
class Middleware
|
|
13
|
-
# rubocop:disable Metrics/MethodLength
|
|
14
30
|
def call(_worker, job, queue)
|
|
15
31
|
name = SidekiqSpy.name_for(job)
|
|
16
32
|
transaction = Atatus.start_transaction(name, 'Sidekiq')
|
|
@@ -18,15 +34,14 @@ module Atatus
|
|
|
18
34
|
|
|
19
35
|
yield
|
|
20
36
|
|
|
21
|
-
transaction
|
|
37
|
+
transaction&.done :success
|
|
22
38
|
rescue ::Exception => e
|
|
23
39
|
Atatus.report(e, handled: false)
|
|
24
|
-
transaction
|
|
40
|
+
transaction&.done :error
|
|
25
41
|
raise
|
|
26
42
|
ensure
|
|
27
43
|
Atatus.end_transaction
|
|
28
44
|
end
|
|
29
|
-
# rubocop:enable Metrics/MethodLength
|
|
30
45
|
end
|
|
31
46
|
|
|
32
47
|
def self.name_for(job)
|
|
@@ -41,42 +56,48 @@ module Atatus
|
|
|
41
56
|
end
|
|
42
57
|
|
|
43
58
|
def install_middleware
|
|
44
|
-
Sidekiq
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
if defined?(::Sidekiq)
|
|
60
|
+
|
|
61
|
+
Sidekiq.configure_server do |config|
|
|
62
|
+
config.server_middleware do |chain|
|
|
63
|
+
chain.add Middleware
|
|
64
|
+
end
|
|
47
65
|
end
|
|
66
|
+
|
|
48
67
|
end
|
|
49
68
|
end
|
|
50
69
|
|
|
51
|
-
# rubocop:disable Metrics/MethodLength
|
|
52
70
|
def install_processor
|
|
53
71
|
require 'sidekiq/processor'
|
|
54
72
|
|
|
55
|
-
Sidekiq::Processor
|
|
56
|
-
alias start_without_apm start
|
|
57
|
-
alias terminate_without_apm terminate
|
|
73
|
+
if defined?(::Sidekiq) && defined?(::Sidekiq::Processor)
|
|
58
74
|
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
Sidekiq::Processor.class_eval do
|
|
76
|
+
alias start_without_apm start
|
|
77
|
+
alias terminate_without_apm terminate
|
|
61
78
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Atatus.agent.config.logger = Sidekiq.logger
|
|
65
|
-
else
|
|
66
|
-
Atatus.start
|
|
67
|
-
end
|
|
79
|
+
def start
|
|
80
|
+
result = start_without_apm
|
|
68
81
|
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
# Already running from Railtie if Rails
|
|
83
|
+
if Atatus.running?
|
|
84
|
+
Atatus.agent.config.logger = Sidekiq.logger
|
|
85
|
+
else
|
|
86
|
+
Atatus.start
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
result
|
|
90
|
+
end
|
|
71
91
|
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
def terminate
|
|
93
|
+
terminate_without_apm
|
|
74
94
|
|
|
75
|
-
|
|
95
|
+
Atatus.stop
|
|
96
|
+
end
|
|
76
97
|
end
|
|
98
|
+
|
|
77
99
|
end
|
|
78
100
|
end
|
|
79
|
-
# rubocop:enable Metrics/MethodLength
|
|
80
101
|
|
|
81
102
|
def install
|
|
82
103
|
install_processor
|
data/lib/atatus/spies/sinatra.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
|
module Atatus
|
|
@@ -5,11 +22,10 @@ module Atatus
|
|
|
5
22
|
module Spies
|
|
6
23
|
# @api private
|
|
7
24
|
class SinatraSpy
|
|
8
|
-
# rubocop:disable Metrics/MethodLength
|
|
9
25
|
def install
|
|
10
|
-
if defined?(::Sinatra) &&
|
|
26
|
+
if defined?(::Sinatra) &&
|
|
11
27
|
defined?(::Sinatra::Base) &&
|
|
12
|
-
::Sinatra::Base.private_method_defined?(:dispatch!) &&
|
|
28
|
+
::Sinatra::Base.private_method_defined?(:dispatch!) &&
|
|
13
29
|
::Sinatra::Base.private_method_defined?(:compile_template)
|
|
14
30
|
|
|
15
31
|
::Sinatra::Base.class_eval do
|
|
@@ -35,9 +51,9 @@ module Atatus
|
|
|
35
51
|
compile_template_without_apm(engine, data, opts, *args, &block)
|
|
36
52
|
end
|
|
37
53
|
end
|
|
54
|
+
|
|
38
55
|
end
|
|
39
56
|
end
|
|
40
|
-
# rubocop:enable Metrics/MethodLength
|
|
41
57
|
end
|
|
42
58
|
|
|
43
59
|
register 'Sinatra::Base', 'sinatra/base', SinatraSpy.new
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
|
|
18
|
+
# frozen_string_literal: true
|
|
19
|
+
|
|
20
|
+
module Atatus
|
|
21
|
+
# @api private
|
|
22
|
+
module Spies
|
|
23
|
+
# @api private
|
|
24
|
+
class SneakersSpy
|
|
25
|
+
include Logging
|
|
26
|
+
|
|
27
|
+
def self.supported_version?
|
|
28
|
+
Gem.loaded_specs['sneakers'].version >= Gem::Version.create('2.12.0')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def install
|
|
32
|
+
unless SneakersSpy.supported_version?
|
|
33
|
+
warn(
|
|
34
|
+
'Sneakers version is below 2.12.0. Sneakers spy installation failed'
|
|
35
|
+
)
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Sneakers.middleware.use(Middleware, nil)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @api private
|
|
43
|
+
class Middleware
|
|
44
|
+
def initialize(app, *args)
|
|
45
|
+
@app = app
|
|
46
|
+
@args = args
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def call(deserialized_msg, delivery_info, metadata, handler)
|
|
50
|
+
transaction =
|
|
51
|
+
Atatus.start_transaction(
|
|
52
|
+
delivery_info.consumer.queue.name,
|
|
53
|
+
'Sneakers'
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
Atatus.set_label(:routing_key, delivery_info.routing_key)
|
|
57
|
+
|
|
58
|
+
res = @app.call(deserialized_msg, delivery_info, metadata, handler)
|
|
59
|
+
transaction&.done(:success)
|
|
60
|
+
|
|
61
|
+
res
|
|
62
|
+
rescue ::Exception => e
|
|
63
|
+
Atatus.report(e, handled: false)
|
|
64
|
+
transaction&.done(:error)
|
|
65
|
+
raise
|
|
66
|
+
ensure
|
|
67
|
+
Atatus.end_transaction
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
register 'Sneakers', 'sneakers', SneakersSpy.new
|
|
73
|
+
end
|
|
74
|
+
end
|