Skip to content

Commit

Permalink
Merge pull request #15 from bigcommerce/PEN-2031
Browse files Browse the repository at this point in the history
Ensure error span tag is always set when an exception is raised
  • Loading branch information
splittingred authored Oct 29, 2020
2 parents b33f0b1 + 537aeac commit 49694c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Changelog for the gruf-lightstep gem.

### Pending Release

- Ensure `error` span tag is always set when an exception is raised
- Move from whitelist -> allowlist in server interceptor

### 1.3.0
Expand Down
6 changes: 4 additions & 2 deletions lib/gruf/lightstep/server_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module Lightstep
# Intercepts inbound calls to provide LightStep tracing
#
class ServerInterceptor < Gruf::Interceptors::ServerInterceptor
DEFAULT_ERROR_CLASSES = %w[GRPC::Unknown GRPC::Internal GRPC::DataLoss GRPC::FailedPrecondition GRPC::Unavailable GRPC::DeadlineExceeded GRPC::Cancelled].freeze

##
# Handle the gruf around hook and trace sampled requests
#
Expand All @@ -44,7 +46,7 @@ def call(&_block)
begin
result = yield
rescue StandardError => e
span.set_tag('error', true) if error?(e)
span.set_tag('error', error?(e))
span.set_tag('grpc.error', true)
span.set_tag('grpc.error_code', code_for(e))
span.set_tag('grpc.error_class', e.class)
Expand Down Expand Up @@ -104,7 +106,7 @@ def error?(exception)
# @return [Array]
#
def error_classes
options.fetch(:error_classes, %w[GRPC::Unknown GRPC::Internal GRPC::DataLoss GRPC::FailedPrecondition GRPC::Unavailable GRPC::DeadlineExceeded GRPC::Cancelled])
@error_classes ||= (options.fetch(:error_classes, nil) || DEFAULT_ERROR_CLASSES)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/gruf/lightstep/server_interceptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
it 'should trace the request as a grpc error but not a span error' do
expect {
expect(tracer).to receive(:start_span).once.and_yield(span)
expect(span).to_not receive(:set_tag).with('error', true)
expect(span).to receive(:set_tag).with('error', false)
expect(span).to receive(:set_tag).with('grpc.error', true).ordered
expect(span).to receive(:set_tag).with('grpc.error_code', exception.code).ordered
expect(span).to receive(:set_tag).with('grpc.error_class', exception.class).ordered
Expand All @@ -101,7 +101,7 @@
it 'should trace the request as a non grpc error' do
expect {
expect(tracer).to receive(:start_span).once.and_yield(span)
expect(span).to_not receive(:set_tag).with('error', true)
expect(span).to receive(:set_tag).with('error', false)
expect(span).to receive(:set_tag).with('grpc.error', true).ordered
expect(span).to receive(:set_tag).with('grpc.error_code', ::Gruf::Lightstep.default_error_code).ordered
expect(span).to receive(:set_tag).with('grpc.error_class', exception.class).ordered
Expand Down

0 comments on commit 49694c4

Please sign in to comment.