From e146b1cad82c0b4c783a3a77872d816156c06dde Mon Sep 17 00:00:00 2001 From: Michael Booth Date: Tue, 6 Nov 2018 13:46:42 +0000 Subject: [PATCH] Calculate and set seconds and nanos for Span's Timestamp proto --- lightstep/constants.py | 1 + lightstep/http_converter.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lightstep/constants.py b/lightstep/constants.py index f4de806..443e5ce 100755 --- a/lightstep/constants.py +++ b/lightstep/constants.py @@ -26,6 +26,7 @@ # utils constants SECONDS_TO_MICRO = 1000000 +SECONDS_TO_NANOS = 1000000000 # Recorder constants MAX_LOG_MEMORY = 1024 diff --git a/lightstep/http_converter.py b/lightstep/http_converter.py index 598d307..851fe93 100644 --- a/lightstep/http_converter.py +++ b/lightstep/http_converter.py @@ -1,4 +1,5 @@ from lightstep.collector_pb2 import Auth, ReportRequest, Span, Reporter, KeyValue, Reference, SpanContext +from lightstep.constants import SECONDS_TO_NANOS from lightstep.converter import Converter from . import util from . import version as tracer_version @@ -39,9 +40,11 @@ def create_runtime(self, component_name, tags, guid): def create_span_record(self, span, guid): span_context = SpanContext(trace_id=span.context.trace_id, span_id=span.context.span_id) + seconds = int(span.start_time) + nanos = int((span.start_time - seconds) * SECONDS_TO_NANOS) span_record = Span(span_context=span_context, operation_name=util._coerce_str(span.operation_name), - start_timestamp=Timestamp(seconds=int(span.start_time)), + start_timestamp=Timestamp(seconds=seconds, nanos=nanos), duration_micros=int(util._time_to_micros(span.duration))) if span.parent_id is not None: reference = span_record.references.add()