Skip to content

Commit

Permalink
inject and extract with FORMAT_TEXT_MAP
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-christian committed Apr 1, 2020
1 parent 471ece0 commit 3391aee
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ benchmark-*.error
benchmark-*.raw

.ci/docker/jruby/output.log
/.ruby-version
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Lint/RescueException:
Lint/SuppressedException:
Enabled: false

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

# Metrics /

Metrics/AbcSize:
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
7 changes: 4 additions & 3 deletions lib/elastic_apm/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions lib/elastic_apm/opentracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/elastic_apm/grpc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/elastic_apm/instrumenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 29 additions & 6 deletions spec/integration/opentracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3391aee

Please sign in to comment.