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
|
require 'elastic_apm'
|
@@ -22,7 +39,7 @@ module ElasticAPM
|
|
22
39
|
@span_context
|
23
40
|
end
|
24
41
|
|
25
|
-
def
|
42
|
+
def set_tag(key, val)
|
26
43
|
if elastic_span.is_a?(Transaction)
|
27
44
|
case key.to_s
|
28
45
|
when 'type'
|
@@ -37,6 +54,8 @@ module ElasticAPM
|
|
37
54
|
else
|
38
55
|
elastic_span.context.labels[key] = val
|
39
56
|
end
|
57
|
+
|
58
|
+
self
|
40
59
|
end
|
41
60
|
|
42
61
|
def set_baggage_item(_key, _value)
|
@@ -61,18 +80,12 @@ module ElasticAPM
|
|
61
80
|
ElasticAPM.report_message message
|
62
81
|
end
|
63
82
|
end
|
64
|
-
|
65
83
|
# rubocop:enable Lint/UnusedMethodArgument
|
66
|
-
def finish(clock_end: Util.monotonic_micros, end_time: nil)
|
67
|
-
return unless (agent = ElasticAPM.agent)
|
68
84
|
|
69
|
-
|
70
|
-
|
71
|
-
'`Time` is deprecated. Use `clock_end:` and monotonic time instead.'
|
72
|
-
clock_end = end_time
|
73
|
-
end
|
85
|
+
def finish(end_time: Time.now)
|
86
|
+
return unless (agent = ElasticAPM.agent)
|
74
87
|
|
75
|
-
elastic_span.done clock_end:
|
88
|
+
elastic_span.done clock_end: Util.micros(end_time)
|
76
89
|
|
77
90
|
case elastic_span
|
78
91
|
when ElasticAPM::Transaction
|
@@ -97,6 +110,8 @@ module ElasticAPM
|
|
97
110
|
|
98
111
|
# @api private
|
99
112
|
class SpanContext
|
113
|
+
extend Forwardable
|
114
|
+
|
100
115
|
def initialize(trace_context:, baggage: nil)
|
101
116
|
if baggage
|
102
117
|
ElasticAPM.agent.config.logger.warn(
|
@@ -108,10 +123,27 @@ module ElasticAPM
|
|
108
123
|
end
|
109
124
|
|
110
125
|
attr_accessor :trace_context
|
126
|
+
def_delegators :trace_context, :trace_id, :id, :parent_id
|
127
|
+
|
128
|
+
def self.from_header(header)
|
129
|
+
return unless header
|
130
|
+
|
131
|
+
trace_context = ElasticAPM::TraceContext.parse(header)
|
132
|
+
return unless trace_context
|
133
|
+
|
134
|
+
trace_context.traceparent.id = trace_context.parent_id
|
135
|
+
trace_context.traceparent.parent_id = nil
|
136
|
+
|
137
|
+
from_trace_context(trace_context)
|
138
|
+
end
|
111
139
|
|
112
140
|
def self.from_trace_context(trace_context)
|
113
141
|
new(trace_context: trace_context)
|
114
142
|
end
|
143
|
+
|
144
|
+
def child
|
145
|
+
self.class.from_trace_context(trace_context.child)
|
146
|
+
end
|
115
147
|
end
|
116
148
|
|
117
149
|
# @api private
|
@@ -193,7 +225,7 @@ module ElasticAPM
|
|
193
225
|
child_of: nil,
|
194
226
|
references: nil,
|
195
227
|
start_time: Time.now,
|
196
|
-
|
228
|
+
tags: {},
|
197
229
|
ignore_active_scope: false,
|
198
230
|
finish_on_close: true,
|
199
231
|
**
|
@@ -203,14 +235,14 @@ module ElasticAPM
|
|
203
235
|
child_of: child_of,
|
204
236
|
references: references,
|
205
237
|
start_time: start_time,
|
206
|
-
|
238
|
+
tags: tags,
|
207
239
|
ignore_active_scope: ignore_active_scope
|
208
240
|
)
|
209
241
|
scope = scope_manager.activate(span, finish_on_close: finish_on_close)
|
210
242
|
|
211
243
|
if block_given?
|
212
244
|
begin
|
213
|
-
yield scope
|
245
|
+
return yield scope
|
214
246
|
ensure
|
215
247
|
scope.close
|
216
248
|
end
|
@@ -226,7 +258,7 @@ module ElasticAPM
|
|
226
258
|
child_of: nil,
|
227
259
|
references: nil,
|
228
260
|
start_time: Time.now,
|
229
|
-
|
261
|
+
tags: {},
|
230
262
|
ignore_active_scope: false,
|
231
263
|
**
|
232
264
|
)
|
@@ -263,7 +295,7 @@ module ElasticAPM
|
|
263
295
|
span_context ||=
|
264
296
|
SpanContext.from_trace_context(elastic_span.trace_context)
|
265
297
|
|
266
|
-
|
298
|
+
tags.each do |key, value|
|
267
299
|
elastic_span.context.labels[key] = value
|
268
300
|
end
|
269
301
|
|
@@ -276,8 +308,9 @@ module ElasticAPM
|
|
276
308
|
|
277
309
|
def inject(span_context, format, carrier)
|
278
310
|
case format
|
279
|
-
when ::OpenTracing::FORMAT_RACK
|
280
|
-
carrier['elastic-apm-traceparent'] =
|
311
|
+
when ::OpenTracing::FORMAT_RACK, ::OpenTracing::FORMAT_TEXT_MAP
|
312
|
+
carrier['elastic-apm-traceparent'] =
|
313
|
+
span_context.traceparent.to_header
|
281
314
|
else
|
282
315
|
warn 'Only injection via HTTP headers and Rack is available'
|
283
316
|
end
|
@@ -286,10 +319,16 @@ module ElasticAPM
|
|
286
319
|
def extract(format, carrier)
|
287
320
|
case format
|
288
321
|
when ::OpenTracing::FORMAT_RACK
|
289
|
-
|
290
|
-
|
322
|
+
SpanContext.from_header(
|
323
|
+
carrier['HTTP_ELASTIC_APM_TRACEPARENT']
|
324
|
+
)
|
325
|
+
when ::OpenTracing::FORMAT_TEXT_MAP
|
326
|
+
SpanContext.from_header(
|
327
|
+
carrier['elastic-apm-traceparent']
|
328
|
+
)
|
291
329
|
else
|
292
|
-
warn 'Only extraction from HTTP headers via Rack
|
330
|
+
warn 'Only extraction from HTTP headers via Rack or in ' \
|
331
|
+
'text map format are available'
|
293
332
|
nil
|
294
333
|
end
|
295
334
|
rescue ElasticAPM::TraceContext::InvalidTraceparentHeader
|
@@ -303,9 +342,12 @@ module ElasticAPM
|
|
303
342
|
references:,
|
304
343
|
ignore_active_scope:
|
305
344
|
)
|
306
|
-
context_from_child_of(child_of) ||
|
307
|
-
|
308
|
-
|
345
|
+
context = context_from_child_of(child_of) ||
|
346
|
+
context_from_references(references) ||
|
347
|
+
context_from_active_scope(ignore_active_scope)
|
348
|
+
return context.child if context&.respond_to?(:child)
|
349
|
+
|
350
|
+
context
|
309
351
|
end
|
310
352
|
|
311
353
|
def context_from_child_of(child_of)
|
@@ -326,7 +368,7 @@ module ElasticAPM
|
|
326
368
|
def context_from_active_scope(ignore_active_scope)
|
327
369
|
if ignore_active_scope
|
328
370
|
ElasticAPM.agent&.config&.logger&.warn(
|
329
|
-
'ignore_active_scope might lead to
|
371
|
+
'ignore_active_scope might lead to unexpected results'
|
330
372
|
)
|
331
373
|
return
|
332
374
|
end
|
data/lib/elastic_apm/rails.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/railtie'
|
@@ -9,7 +26,6 @@ module ElasticAPM
|
|
9
26
|
# It is recommended to use the Railtie instead.
|
10
27
|
module Rails
|
11
28
|
extend self
|
12
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
13
29
|
# Start the ElasticAPM agent and hook into Rails.
|
14
30
|
# Note that the agent won't be started if the Rails console is being used.
|
15
31
|
#
|
@@ -31,13 +47,6 @@ module ElasticAPM
|
|
31
47
|
attach_subscriber(agent)
|
32
48
|
end
|
33
49
|
|
34
|
-
if ElasticAPM.running? &&
|
35
|
-
!ElasticAPM.agent.config.disabled_instrumentations.include?(
|
36
|
-
'action_dispatch'
|
37
|
-
)
|
38
|
-
require 'elastic_apm/spies/action_dispatch'
|
39
|
-
end
|
40
|
-
|
41
50
|
ElasticAPM.running?
|
42
51
|
rescue StandardError => e
|
43
52
|
if config.disable_start_message?
|
@@ -48,12 +57,11 @@ module ElasticAPM
|
|
48
57
|
puts "Backtrace:\n" + e.backtrace.join("\n")
|
49
58
|
end
|
50
59
|
end
|
51
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
52
60
|
|
53
61
|
private
|
54
62
|
|
55
63
|
def should_skip?(_config)
|
56
|
-
if ::Rails.const_defined?
|
64
|
+
if ::Rails.const_defined?('Console', false)
|
57
65
|
return 'Rails console'
|
58
66
|
end
|
59
67
|
|
data/lib/elastic_apm/railtie.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 ElasticAPM
|
@@ -7,7 +24,7 @@ module ElasticAPM
|
|
7
24
|
|
8
25
|
Config.schema.each do |key, args|
|
9
26
|
next unless args.length > 1
|
10
|
-
config.elastic_apm[key] = args
|
27
|
+
config.elastic_apm[key] = args[:default]
|
11
28
|
end
|
12
29
|
|
13
30
|
initializer 'elastic_apm.initialize' do |app|
|
@@ -0,0 +1,29 @@
|
|
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
|
+
# Defines a before_first_fork hook for starting the ElasticAPM agent
|
22
|
+
# with Resque.
|
23
|
+
module Resque
|
24
|
+
::Resque.before_first_fork do
|
25
|
+
::Resque.logger.debug('Starting ElasticAPM agent')
|
26
|
+
ElasticAPM.start
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/elastic_apm/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 ElasticAPM
|
data/lib/elastic_apm/span.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/span/context'
|
@@ -20,7 +37,8 @@ module ElasticAPM
|
|
20
37
|
subtype: nil,
|
21
38
|
action: nil,
|
22
39
|
context: nil,
|
23
|
-
stacktrace_builder: nil
|
40
|
+
stacktrace_builder: nil,
|
41
|
+
sync: nil
|
24
42
|
)
|
25
43
|
@name = name
|
26
44
|
|
@@ -36,7 +54,7 @@ module ElasticAPM
|
|
36
54
|
@parent = parent
|
37
55
|
@trace_context = trace_context || parent.trace_context.child
|
38
56
|
|
39
|
-
@context = context || Span::Context.new
|
57
|
+
@context = context || Span::Context.new(sync: sync)
|
40
58
|
@stacktrace_builder = stacktrace_builder
|
41
59
|
end
|
42
60
|
# rubocop:enable Metrics/ParameterLists
|
@@ -1,56 +1,55 @@
|
|
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
|
4
21
|
class Span
|
5
22
|
# @api private
|
6
23
|
class Context
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
|
10
|
-
|
24
|
+
def initialize(
|
25
|
+
db: nil,
|
26
|
+
destination: nil,
|
27
|
+
http: nil,
|
28
|
+
labels: {},
|
29
|
+
sync: nil
|
30
|
+
)
|
31
|
+
@sync = sync
|
32
|
+
@db = db && Db.new(**db)
|
33
|
+
@http = http && Http.new(**http)
|
34
|
+
@destination =
|
35
|
+
case destination
|
36
|
+
when Destination then destination
|
37
|
+
when Hash then Destination.new(**destination)
|
38
|
+
end
|
11
39
|
@labels = labels
|
12
40
|
end
|
13
41
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@type = type
|
22
|
-
@user = user
|
23
|
-
end
|
24
|
-
|
25
|
-
attr_accessor :instance, :statement, :type, :user
|
26
|
-
end
|
27
|
-
|
28
|
-
# @api private
|
29
|
-
class Http
|
30
|
-
def initialize(url: nil, status_code: nil, method: nil)
|
31
|
-
@url = sanitize_url(url)
|
32
|
-
@status_code = status_code
|
33
|
-
@method = method
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_accessor :url, :status_code, :method
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def sanitize_url(url)
|
41
|
-
uri = URI(url)
|
42
|
-
|
43
|
-
return url unless uri.userinfo
|
44
|
-
|
45
|
-
format(
|
46
|
-
'%s://%s@%s%s',
|
47
|
-
uri.scheme,
|
48
|
-
uri.user,
|
49
|
-
uri.hostname,
|
50
|
-
uri.path
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
42
|
+
attr_reader(
|
43
|
+
:db,
|
44
|
+
:destination,
|
45
|
+
:http,
|
46
|
+
:labels,
|
47
|
+
:sync
|
48
|
+
)
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
52
|
+
|
53
|
+
require 'elastic_apm/span/context/db'
|
54
|
+
require 'elastic_apm/span/context/http'
|
55
|
+
require 'elastic_apm/span/context/destination'
|