From bbedba3810712319dc12ed2345bfc133e1656dd0 Mon Sep 17 00:00:00 2001 From: bcronin Date: Sun, 7 Aug 2016 18:30:07 -0700 Subject: [PATCH] Allow end time to be specified on finish --- lib/lightstep/tracer/client_span.rb | 6 +++++- spec/lightstep_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/lightstep/tracer/client_span.rb b/lib/lightstep/tracer/client_span.rb index 4efdce4..e735956 100644 --- a/lib/lightstep/tracer/client_span.rb +++ b/lib/lightstep/tracer/client_span.rb @@ -36,8 +36,12 @@ class ClientSpan @tracer.raw_log_record(record, fields[:payload]) end - def finish + def finish(fields = nil) + unless fields.nil? + set_end_micros(fields[:endTime] * 1000) unless fields[:endTime].nil? + end @tracer._finish_span(self) + self end # ---------------------------------------------------------------------------- diff --git a/spec/lightstep_spec.rb b/spec/lightstep_spec.rb index 4e230b2..43a7fa8 100644 --- a/spec/lightstep_spec.rb +++ b/spec/lightstep_spec.rb @@ -84,6 +84,14 @@ describe LightStep do expect(span3.end_micros).to eq(5678 * 1000) end + it 'should allow end time to be specified at finish time' do + tracer = init_test_tracer + + span = tracer.start_span('test') + span.finish(endTime: 54_321) + expect(span.end_micros).to eq(54_321 * 1000) + end + it 'should assign the same trace_guid to child spans as the parent' do tracer = init_test_tracer parent1 = tracer.start_span('parent1')