diff --git a/.gitignore b/.gitignore index 9896b7ed0..4f069a670 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ benchmark-*.error benchmark-*.raw .ci/docker/jruby/output.log +/.ruby-version diff --git a/.rubocop.yml b/.rubocop.yml index 2deb6008c..277b4c4be 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,6 +32,12 @@ Lint/RescueException: Lint/SuppressedException: Enabled: false +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + # Metrics / Metrics/AbcSize: diff --git a/Rakefile b/Rakefile index 1dd45e893..1bc0e6e88 100644 --- a/Rakefile +++ b/Rakefile @@ -2,9 +2,10 @@ require 'bundler/gem_tasks' -desc """Post release action: +desc "Post release action: Update `3.x` branch to be at released commit and push it to GitHub. -""" +" + namespace :release do task :update_branch do `git checkout 3.x && diff --git a/lib/elastic_apm/config.rb b/lib/elastic_apm/config.rb index e50e460fb..91755ef83 100644 --- a/lib/elastic_apm/config.rb +++ b/lib/elastic_apm/config.rb @@ -222,9 +222,10 @@ def disabled_instrumentations=(value) self.disable_instrumentations = value end - def use_experimental_sql_parser=(value) - warn '[DEPRECATED] The new SQL parser is now the default. To use the old one, ' - 'use use_legacy_sql_parser and please report why you wish to do so.' + def use_experimental_sql_parser=(_value) + warn '[DEPRECATED] The new SQL parser is now the default. ' \ + 'To use the old one, use use_legacy_sql_parser and please ' \ + 'report why you wish to do so.' end private diff --git a/lib/elastic_apm/opentracing.rb b/lib/elastic_apm/opentracing.rb index 42a918336..44005b8d5 100644 --- a/lib/elastic_apm/opentracing.rb +++ b/lib/elastic_apm/opentracing.rb @@ -61,8 +61,8 @@ def log_kv(timestamp: nil, **fields) ElasticAPM.report_message message end end - # rubocop:enable Lint/UnusedMethodArgument + def finish(clock_end: Util.monotonic_micros, end_time: nil) return unless (agent = ElasticAPM.agent) @@ -271,26 +271,28 @@ def start_span( Span.new(elastic_span, span_context) end - # rubocop:enable Metrics/ParameterLists def inject(span_context, format, carrier) case format - when ::OpenTracing::FORMAT_RACK + when ::OpenTracing::FORMAT_RACK, ::OpenTracing::FORMAT_TEXT_MAP carrier['elastic-apm-traceparent'] = span_context.traceparent.to_header else - warn 'Only injection via HTTP headers and Rack is available' + warn 'Only injection via FORMAT_TEXT_MAP or via HTTP headers and ' \ + 'FORMAT_RACK is available' end end def extract(format, carrier) case format - when ::OpenTracing::FORMAT_RACK + when ::OpenTracing::FORMAT_RACK, ::OpenTracing::FORMAT_TEXT_MAP ElasticAPM::TraceContext - .parse(carrier['HTTP_ELASTIC_APM_TRACEPARENT']) + .parse(carrier['HTTP_ELASTIC_APM_TRACEPARENT'] || + carrier['elastic-apm-traceparent']) else - warn 'Only extraction from HTTP headers via Rack is available' + warn 'Only extraction via FORMAT_TEXT_MAP or via HTTP headers and ' \ + 'FORMAT_RACK is available' nil end rescue ElasticAPM::TraceContext::InvalidTraceparentHeader @@ -327,7 +329,7 @@ def context_from_references(references) def context_from_active_scope(ignore_active_scope) if ignore_active_scope ElasticAPM.agent&.config&.logger&.warn( - 'ignore_active_scope might lead to unexpeced results' + 'ignore_active_scope might lead to unexpected results' ) return end diff --git a/spec/elastic_apm/grpc_spec.rb b/spec/elastic_apm/grpc_spec.rb index 515ee83b3..cc0782a92 100644 --- a/spec/elastic_apm/grpc_spec.rb +++ b/spec/elastic_apm/grpc_spec.rb @@ -2,7 +2,7 @@ if !defined?(JRUBY_VERSION) && RUBY_VERSION < '2.7' require 'grpc' - + module ElasticAPM RSpec.describe GRPC, :intercept do class GreeterServer < Helloworld::Greeter::Service diff --git a/spec/elastic_apm/instrumenter_spec.rb b/spec/elastic_apm/instrumenter_spec.rb index 613fb041d..f8d7c17c9 100644 --- a/spec/elastic_apm/instrumenter_spec.rb +++ b/spec/elastic_apm/instrumenter_spec.rb @@ -147,7 +147,7 @@ module ElasticAPM ) expect(txn_self_time.span).to match(type: 'app', subtype: nil) - #spn_self_time + # spn_self_time expect(spn_self_time.samples[:'span.self_time.sum.us']).to eq 100 expect(spn_self_time.samples[:'span.self_time.count']).to eq 1 expect(spn_self_time.transaction).to match( diff --git a/spec/integration/opentracing_spec.rb b/spec/integration/opentracing_spec.rb index 1ac1be561..85965999f 100644 --- a/spec/integration/opentracing_spec.rb +++ b/spec/integration/opentracing_spec.rb @@ -123,6 +123,16 @@ end end + context 'Text map' do + let(:format) { ::OpenTracing::FORMAT_TEXT_MAP } + + it 'sets a header' do + subject + expect(carrier['elastic-apm-traceparent']) + .to eq context.traceparent.to_header + end + end + context 'Binary' do let(:format) { ::OpenTracing::FORMAT_BINARY } @@ -134,15 +144,27 @@ end describe '#extract' do - let(:carrier) do - { 'HTTP_ELASTIC_APM_TRACEPARENT' => - '00-11111111111111111111111111111111-2222222222222222-00' } - end - subject { ::OpenTracing.extract(format, carrier) } context 'Rack' do let(:format) { ::OpenTracing::FORMAT_RACK } + let(:carrier) do + { 'HTTP_ELASTIC_APM_TRACEPARENT' => + '00-11111111111111111111111111111111-2222222222222222-00' } + end + + it 'returns a trace context' do + expect(subject).to be_a ElasticAPM::TraceContext + expect(subject.trace_id).to eq '11111111111111111111111111111111' + end + end + + context 'Text map' do + let(:format) { ::OpenTracing::FORMAT_TEXT_MAP } + let(:carrier) do + { 'elastic-apm-traceparent' => + '00-11111111111111111111111111111111-2222222222222222-00' } + end it 'returns a trace context' do expect(subject).to be_a ElasticAPM::TraceContext @@ -152,9 +174,10 @@ context 'Binary' do let(:format) { ::OpenTracing::FORMAT_BINARY } + let(:carrier) { {} } it 'warns about lack of support' do - expect(tracer).to receive(:warn).with(/Only extraction from/) + expect(tracer).to receive(:warn).with(/Only extraction via/) subject end end