fix: Prevent OpenCensus integration from getting out of sync on upload commands
This commit is contained in:
parent
e3e97668b4
commit
29f9544b14
|
@ -385,6 +385,7 @@ module Google
|
||||||
return unless @opencensus_span
|
return unless @opencensus_span
|
||||||
return unless OpenCensus::Trace.span_context
|
return unless OpenCensus::Trace.span_context
|
||||||
|
|
||||||
|
if @http_res
|
||||||
if @http_res.body.respond_to? :bytesize
|
if @http_res.body.respond_to? :bytesize
|
||||||
@opencensus_span.put_message_event \
|
@opencensus_span.put_message_event \
|
||||||
OpenCensus::Trace::SpanBuilder::RECEIVED, 1, @http_res.body.bytesize
|
OpenCensus::Trace::SpanBuilder::RECEIVED, 1, @http_res.body.bytesize
|
||||||
|
@ -394,6 +395,7 @@ module Google
|
||||||
@opencensus_span.set_status map_http_status status
|
@opencensus_span.set_status map_http_status status
|
||||||
@opencensus_span.put_attribute "http.status_code", status
|
@opencensus_span.put_attribute "http.status_code", status
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
OpenCensus::Trace.end_span @opencensus_span
|
OpenCensus::Trace.end_span @opencensus_span
|
||||||
@opencensus_span = nil
|
@opencensus_span = nil
|
||||||
|
|
|
@ -177,6 +177,16 @@ RSpec.describe Google::Apis::Core::ResumableUploadCommand do
|
||||||
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals')
|
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals')
|
||||||
.with(body: 'Hello world')).to have_been_made
|
.with(body: 'Hello world')).to have_been_made
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'with retriable error on start' do
|
context 'with retriable error on start' do
|
||||||
|
|
Loading…
Reference in New Issue