Skip to content

Commit

Permalink
fix(grpc): pass error_handler from config to interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
rfwroo committed Aug 31, 2023
1 parent 85ff055 commit 22d20fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def analytics_sample_rate
end

def error_handler
datadog_configuration[:error_handler]
Datadog.configuration_for(self, :error_handler) || datadog_configuration[:error_handler]
end

# Allows interceptors to define settings using methods instead of `[]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def trace(keywords)
options = {
span_type: Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND,
service: service_name, # Maintain client-side service name configuration
resource: formatter.resource_name
resource: formatter.resource_name,
on_error: error_handler
}

Tracing.trace(Ext::SPAN_CLIENT, **options) do |span, trace|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,58 @@

let(:original_metadata) { { some: 'datum' } }

let(:request_response) do
subject.request_response(**keywords) { :returned_object }
end
context 'without an error' do
let(:request_response) do
subject.request_response(**keywords) { :returned_object }
end

before do
request_response
before { request_response }

it_behaves_like 'span data contents'

it_behaves_like 'inject distributed tracing metadata'

it 'actually returns the client response' do
expect(request_response).to be(:returned_object)
end
end

it_behaves_like 'span data contents'
context 'with an error' do
let(:request_response) do
subject.request_response(**keywords) { raise error_class, 'test error' }
end

it_behaves_like 'inject distributed tracing metadata'
let(:error_class) { stub_const('TestError', Class.new(StandardError)) }

context 'without an error handler' do
it do
expect { request_response }.to raise_error('test error')

expect(span).to have_error
expect(span).to have_error_message('test error')
expect(span).to have_error_type('TestError')
expect(span).to have_error_stack(include('client_spec.rb'))
expect(span.get_tag('rpc.system')).to eq('grpc')
expect(span.get_tag('span.kind')).to eq('client')
end
end

it 'actually returns the client response' do
expect(request_response).to be(:returned_object)
context 'with an error handler' do
let(:configuration_options) { { service_name: 'rspec', error_handler: error_handler } }

let(:error_handler) do
->(span, error) { span.set_tag('custom.handler', "Got error #{error}, but ignored it") }
end

it do
expect { request_response }.to raise_error('test error')

expect(span).not_to have_error
expect(span.get_tag('custom.handler')).to eq('Got error test error, but ignored it')
expect(span.get_tag('rpc.system')).to eq('grpc')
expect(span.get_tag('span.kind')).to eq('client')
end
end
end
end

Expand Down

0 comments on commit 22d20fb

Please sign in to comment.