Skip to content

Commit

Permalink
fix: Prevent OpenCensus integration from getting out of sync on uploa…
Browse files Browse the repository at this point in the history
…d commands
  • Loading branch information
dazuma authored Nov 26, 2019
1 parent e3e9766 commit 29f9544
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/google/apis/core/http_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ def opencensus_end_span
return unless @opencensus_span
return unless OpenCensus::Trace.span_context

if @http_res.body.respond_to? :bytesize
@opencensus_span.put_message_event \
OpenCensus::Trace::SpanBuilder::RECEIVED, 1, @http_res.body.bytesize
end
status = @http_res.status.to_i
if status > 0
@opencensus_span.set_status map_http_status status
@opencensus_span.put_attribute "http.status_code", status
if @http_res
if @http_res.body.respond_to? :bytesize
@opencensus_span.put_message_event \
OpenCensus::Trace::SpanBuilder::RECEIVED, 1, @http_res.body.bytesize
end
status = @http_res.status.to_i
if status > 0
@opencensus_span.set_status map_http_status status
@opencensus_span.put_attribute "http.status_code", status
end
end

OpenCensus::Trace.end_span @opencensus_span
Expand Down
10 changes: 10 additions & 0 deletions spec/google/apis/core/upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals')
.with(body: 'Hello world')).to have_been_made
end

it 'should generate a proper opencensus span' do
OpenCensus::Trace.start_request_trace do |span_context|
command.execute(client)
spans = span_context.build_contained_spans
expect(spans.size).to eql 1
span = spans.first
expect(span.name.value).to eql '/zoo/animals'
end
end
end

context 'with retriable error on start' do
Expand Down

0 comments on commit 29f9544

Please sign in to comment.