elastic-apm 3.3.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/.jenkins_exclude.yml +43 -24
- data/.ci/.jenkins_framework.yml +2 -2
- data/.ci/.jenkins_ruby.yml +1 -1
- data/.ci/Jenkinsfile +288 -170
- data/.ci/docker/jruby/11-jdk/Dockerfile +40 -0
- data/.ci/docker/jruby/12-jdk/Dockerfile +40 -0
- data/.ci/docker/jruby/13-jdk/Dockerfile +40 -0
- data/.ci/docker/jruby/7-jdk/Dockerfile +40 -0
- data/.ci/docker/jruby/8-jdk/Dockerfile +40 -0
- data/.ci/docker/jruby/README.md +31 -0
- data/.ci/docker/jruby/run.sh +73 -0
- data/.ci/docker/jruby/test.sh +13 -0
- data/.ci/jobs/apm-agent-ruby-downstream.yml +1 -0
- data/.ci/jobs/apm-agent-ruby-linting-mbp.yml +1 -0
- data/.ci/jobs/apm-agent-ruby-mbp.yml +1 -0
- data/.ci/jobs/defaults.yml +1 -1
- data/.ci/packer_cache.sh +16 -0
- data/.github/ISSUE_TEMPLATE/Bug_report.md +40 -0
- data/.github/ISSUE_TEMPLATE/Feature_request.md +17 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +60 -0
- data/.gitignore +8 -0
- data/.rspec +0 -1
- data/.rubocop.yml +18 -0
- data/CHANGELOG.asciidoc +104 -1
- data/CONTRIBUTING.md +6 -48
- data/Gemfile +38 -10
- data/README.md +62 -13
- data/Rakefile +37 -5
- data/bench/sql.rb +49 -0
- data/bin/build_docs +1 -1
- data/bin/run-tests +4 -1
- data/docker-compose.yml +7 -0
- data/docs/api.asciidoc +52 -3
- data/docs/configuration.asciidoc +171 -22
- data/docs/getting-started-rails.asciidoc +2 -0
- data/docs/graphql.asciidoc +23 -0
- data/docs/images/dynamic-config.svg +1 -0
- data/docs/index.asciidoc +6 -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 +86 -1
- data/docs/upgrading.asciidoc +45 -0
- data/elastic-apm.gemspec +17 -0
- data/lib/elastic-apm.rb +17 -0
- data/lib/elastic_apm.rb +58 -5
- data/lib/elastic_apm/agent.rb +55 -4
- 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 +26 -4
- data/lib/elastic_apm/config.rb +86 -5
- 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 +21 -5
- data/lib/elastic_apm/config/regexp_list.rb +17 -0
- data/lib/elastic_apm/config/wildcard_pattern_list.rb +20 -1
- 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 +27 -2
- 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 +91 -0
- data/lib/elastic_apm/grpc.rb +99 -0
- data/lib/elastic_apm/instrumenter.rb +49 -15
- 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 +22 -2
- 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 +23 -4
- 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 +20 -4
- 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 +29 -5
- data/lib/elastic_apm/opentracing.rb +66 -24
- data/lib/elastic_apm/rails.rb +18 -10
- data/lib/elastic_apm/railtie.rb +18 -1
- data/lib/elastic_apm/resque.rb +29 -0
- data/lib/elastic_apm/sinatra.rb +17 -0
- data/lib/elastic_apm/span.rb +20 -2
- data/lib/elastic_apm/span/context.rb +43 -44
- data/lib/elastic_apm/span/context/db.rb +43 -0
- data/lib/elastic_apm/span/context/destination.rb +77 -0
- data/lib/elastic_apm/span/context/http.rb +43 -0
- data/lib/elastic_apm/span_helpers.rb +17 -0
- data/lib/elastic_apm/spies.rb +33 -14
- 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 +49 -5
- data/lib/elastic_apm/spies/faraday.rb +53 -18
- data/lib/elastic_apm/spies/http.rb +35 -3
- data/lib/elastic_apm/spies/json.rb +17 -0
- data/lib/elastic_apm/spies/mongo.rb +23 -1
- data/lib/elastic_apm/spies/net_http.rb +50 -8
- 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 +53 -0
- data/lib/elastic_apm/spies/sequel.rb +52 -15
- data/lib/elastic_apm/spies/shoryuken.rb +65 -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 +74 -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 +36 -0
- data/lib/elastic_apm/sql/signature.rb +169 -0
- data/lib/elastic_apm/sql/tokenizer.rb +264 -0
- data/lib/elastic_apm/sql/tokens.rb +63 -0
- data/lib/elastic_apm/sql_summarizer.rb +18 -2
- data/lib/elastic_apm/stacktrace.rb +17 -0
- data/lib/elastic_apm/stacktrace/frame.rb +17 -0
- data/lib/elastic_apm/stacktrace_builder.rb +23 -1
- data/lib/elastic_apm/subscriber.rb +17 -0
- data/lib/elastic_apm/trace_context.rb +85 -49
- data/lib/elastic_apm/trace_context/traceparent.rb +113 -0
- data/lib/elastic_apm/trace_context/tracestate.rb +43 -0
- data/lib/elastic_apm/transaction.rb +43 -15
- 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 +24 -2
- data/lib/elastic_apm/transport/filters.rb +17 -0
- data/lib/elastic_apm/transport/filters/hash_sanitizer.rb +77 -0
- data/lib/elastic_apm/transport/filters/secrets_filter.rb +29 -53
- data/lib/elastic_apm/transport/headers.rb +21 -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 +44 -20
- data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +17 -0
- data/lib/elastic_apm/transport/serializers/span_serializer.rb +45 -8
- 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 +36 -7
- data/.ci/downstreamTests.groovy +0 -185
- data/.ci/prepare-git-context.sh +0 -24
- data/.github/workflows/main.yml +0 -14
- data/CHANGELOG.md +0 -1
@@ -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
|
@@ -19,17 +36,32 @@ module ElasticAPM
|
|
19
36
|
method = req.verb.to_s.upcase
|
20
37
|
host = req.uri.host
|
21
38
|
|
39
|
+
destination =
|
40
|
+
ElasticAPM::Span::Context::Destination.from_uri(req.uri)
|
41
|
+
context = ElasticAPM::Span::Context.new(
|
42
|
+
http: { url: req.uri, method: method },
|
43
|
+
destination: destination
|
44
|
+
)
|
45
|
+
|
22
46
|
name = "#{method} #{host}"
|
23
47
|
|
24
48
|
ElasticAPM.with_span(
|
25
49
|
name,
|
26
50
|
TYPE,
|
27
51
|
subtype: SUBTYPE,
|
28
|
-
action: method
|
52
|
+
action: method,
|
53
|
+
context: context
|
29
54
|
) do |span|
|
30
55
|
trace_context = span&.trace_context || transaction.trace_context
|
31
|
-
req[
|
32
|
-
|
56
|
+
trace_context.apply_headers { |key, value| req[key] = value }
|
57
|
+
|
58
|
+
result = perform_without_apm(req, options)
|
59
|
+
|
60
|
+
if (http = span&.context&.http)
|
61
|
+
http.status_code = result.status.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
result
|
33
65
|
end
|
34
66
|
end
|
35
67
|
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/span_helpers'
|
@@ -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
|
@@ -68,8 +85,8 @@ module ElasticAPM
|
|
68
85
|
end
|
69
86
|
|
70
87
|
def pop_event(event)
|
71
|
-
return unless (curr = ElasticAPM.current_span)
|
72
88
|
span = @events.delete(event.operation_id)
|
89
|
+
return unless (curr = ElasticAPM.current_span)
|
73
90
|
|
74
91
|
curr == span && ElasticAPM.end_span
|
75
92
|
end
|
@@ -81,6 +98,11 @@ module ElasticAPM
|
|
81
98
|
statement: event.command.to_s,
|
82
99
|
type: 'mongodb',
|
83
100
|
user: nil
|
101
|
+
},
|
102
|
+
destination: {
|
103
|
+
name: SUBTYPE,
|
104
|
+
resource: SUBTYPE,
|
105
|
+
type: TYPE
|
84
106
|
}
|
85
107
|
)
|
86
108
|
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
|
module ElasticAPM
|
@@ -8,6 +25,7 @@ module ElasticAPM
|
|
8
25
|
KEY = :__elastic_apm_net_http_disabled
|
9
26
|
TYPE = 'ext'
|
10
27
|
SUBTYPE = 'net_http'
|
28
|
+
|
11
29
|
class << self
|
12
30
|
def disabled=(disabled)
|
13
31
|
Thread.current[KEY] = disabled
|
@@ -28,6 +46,7 @@ module ElasticAPM
|
|
28
46
|
end
|
29
47
|
end
|
30
48
|
|
49
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
31
50
|
def install
|
32
51
|
Net::HTTP.class_eval do
|
33
52
|
alias request_without_apm request
|
@@ -36,30 +55,53 @@ module ElasticAPM
|
|
36
55
|
unless (transaction = ElasticAPM.current_transaction)
|
37
56
|
return request_without_apm(req, body, &block)
|
38
57
|
end
|
58
|
+
|
39
59
|
if ElasticAPM::Spies::NetHTTPSpy.disabled?
|
40
60
|
return request_without_apm(req, body, &block)
|
41
61
|
end
|
42
62
|
|
43
|
-
host
|
44
|
-
method = req.method
|
63
|
+
host = req['host']&.split(':')&.first || address
|
64
|
+
method = req.method.to_s.upcase
|
65
|
+
path, query = req.path.split('?')
|
66
|
+
|
67
|
+
url = use_ssl? ? +'https://' : +'http://'
|
68
|
+
url << host
|
69
|
+
url << ":#{port}" if port
|
70
|
+
url << path
|
71
|
+
url << "?#{query}" if query
|
72
|
+
uri = URI(url)
|
45
73
|
|
46
|
-
|
74
|
+
destination =
|
75
|
+
ElasticAPM::Span::Context::Destination.from_uri(uri)
|
47
76
|
|
48
|
-
|
77
|
+
context =
|
78
|
+
ElasticAPM::Span::Context.new(
|
79
|
+
http: { url: uri, method: method },
|
80
|
+
destination: destination
|
81
|
+
)
|
49
82
|
|
50
83
|
ElasticAPM.with_span(
|
51
|
-
|
84
|
+
"#{method} #{host}",
|
52
85
|
TYPE,
|
53
86
|
subtype: SUBTYPE,
|
54
|
-
action: method
|
87
|
+
action: method,
|
88
|
+
context: context
|
55
89
|
) do |span|
|
56
90
|
trace_context = span&.trace_context || transaction.trace_context
|
57
|
-
req[
|
58
|
-
|
91
|
+
trace_context.apply_headers { |key, value| req[key] = value }
|
92
|
+
|
93
|
+
result = request_without_apm(req, body, &block)
|
94
|
+
|
95
|
+
if (http = span&.context&.http)
|
96
|
+
http.status_code = result.code
|
97
|
+
end
|
98
|
+
|
99
|
+
result
|
59
100
|
end
|
60
101
|
end
|
61
102
|
end
|
62
103
|
end
|
104
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
63
105
|
end
|
64
106
|
|
65
107
|
register 'Net::HTTP', 'net/http', NetHTTPSpy.new
|
@@ -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
|
@@ -0,0 +1,53 @@
|
|
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 ElasticAPM
|
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
|
+
::Resque::Job.class_eval do
|
33
|
+
alias :perform_without_elastic_apm :perform
|
34
|
+
|
35
|
+
def perform
|
36
|
+
name = @payload && @payload['class']&.to_s
|
37
|
+
transaction = ElasticAPM.start_transaction(name, TYPE)
|
38
|
+
perform_without_elastic_apm
|
39
|
+
transaction.done 'success'
|
40
|
+
rescue ::Exception => e
|
41
|
+
ElasticAPM.report(e, handled: false)
|
42
|
+
transaction.done 'error' if transaction
|
43
|
+
raise
|
44
|
+
ensure
|
45
|
+
ElasticAPM.end_transaction
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
register 'Resque', 'resque', ResqueSpy.new
|
52
|
+
end
|
53
|
+
end
|
@@ -1,22 +1,34 @@
|
|
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 'elastic_apm/
|
20
|
+
require 'elastic_apm/sql'
|
4
21
|
|
5
22
|
module ElasticAPM
|
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
34
|
def install
|
@@ -25,16 +37,41 @@ module ElasticAPM
|
|
25
37
|
::Sequel::Database.class_eval do
|
26
38
|
alias log_connection_yield_without_apm log_connection_yield
|
27
39
|
|
28
|
-
def log_connection_yield(sql,
|
40
|
+
def log_connection_yield(sql, connection, args = nil, &block)
|
29
41
|
unless ElasticAPM.current_transaction
|
30
|
-
return log_connection_yield_without_apm(
|
42
|
+
return log_connection_yield_without_apm(
|
43
|
+
sql, connection, args, &block
|
44
|
+
)
|
31
45
|
end
|
32
46
|
|
33
|
-
|
34
|
-
name = summarizer.summarize sql
|
35
|
-
context = ElasticAPM::Spies::SequelSpy.build_context(sql, opts)
|
47
|
+
subtype = database_type.to_s
|
36
48
|
|
37
|
-
|
49
|
+
name =
|
50
|
+
ElasticAPM::Spies::SequelSpy.summarizer.summarize sql
|
51
|
+
|
52
|
+
context = ElasticAPM::Span::Context.new(
|
53
|
+
db: { statement: sql, type: 'sql', user: opts[:user] },
|
54
|
+
destination: { name: subtype, resource: subtype, type: TYPE }
|
55
|
+
)
|
56
|
+
|
57
|
+
span = ElasticAPM.start_span(
|
58
|
+
name,
|
59
|
+
TYPE,
|
60
|
+
subtype: subtype,
|
61
|
+
action: ACTION,
|
62
|
+
context: context
|
63
|
+
)
|
64
|
+
yield.tap do |result|
|
65
|
+
if name =~ /^(UPDATE|DELETE)/
|
66
|
+
if connection.respond_to?(:changes)
|
67
|
+
span.context.db.rows_affected = connection.changes
|
68
|
+
elsif result.is_a?(Integer)
|
69
|
+
span.context.db.rows_affected = result
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
ensure
|
74
|
+
ElasticAPM.end_span
|
38
75
|
end
|
39
76
|
end
|
40
77
|
end
|
@@ -0,0 +1,65 @@
|
|
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 ElasticAPM
|
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
|
+
ElasticAPM.start_transaction(
|
30
|
+
job_class(worker_instance, body),
|
31
|
+
'shoryuken.job'
|
32
|
+
)
|
33
|
+
|
34
|
+
ElasticAPM.set_label('shoryuken.id', sqs_msg.message_id)
|
35
|
+
ElasticAPM.set_label('shoryuken.queue', queue)
|
36
|
+
|
37
|
+
yield
|
38
|
+
|
39
|
+
transaction&.done :success
|
40
|
+
rescue ::Exception => e
|
41
|
+
ElasticAPM.report(e, handled: false)
|
42
|
+
transaction&.done :error
|
43
|
+
raise
|
44
|
+
ensure
|
45
|
+
ElasticAPM.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
|
+
::Shoryuken.server_middleware do |chain|
|
58
|
+
chain.add Middleware
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
register 'Shoryuken', 'shoryuken', ShoryukenSpy.new
|
64
|
+
end
|
65
|
+
end
|