Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 6d3c862

Browse files
irekatroszkoliyanhui1228
authored andcommitted
Fix jaeger_exporter to properly handle root spans and timestamps (#208)
1 parent 93dff73 commit 6d3c862

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

opencensus/trace/exporters/jaeger_exporter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ def translate_to_jaeger(self, span_datas):
178178
for span in span_datas:
179179
start_datetime = datetime.datetime.strptime(
180180
span.start_time, ISO_DATETIME_REGEX)
181-
start_microsec = calendar.timegm(start_datetime.timetuple()) * 1000
181+
start_microsec = calendar.timegm(start_datetime.timetuple()) \
182+
* 1e6 \
183+
+ start_datetime.microsecond
182184

183185
end_datetime = datetime.datetime.strptime(
184186
span.end_time, ISO_DATETIME_REGEX)
185-
end_microsec = calendar.timegm(end_datetime.timetuple()) * 1000
187+
end_microsec = calendar.timegm(end_datetime.timetuple()) \
188+
* 1e6 \
189+
+ end_datetime.microsecond
186190

187191
duration_microsec = end_microsec - start_microsec
188192

@@ -222,7 +226,7 @@ def translate_to_jaeger(self, span_datas):
222226
logs=logs,
223227
references=refs,
224228
flags=flags,
225-
parentSpanId=_convert_hex_str_to_int(parent_span_id))
229+
parentSpanId=_convert_hex_str_to_int(parent_span_id or '0'))
226230

227231
jaeger_spans.append(jaeger_span)
228232

tests/unit/trace/exporters/test_jaeger_exporter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def test_translate_to_jaeger(self):
269269
spanId=7929822056569588882,
270270
parentSpanId=1229782938247303441,
271271
operationName='test1',
272-
startTime=1502820146000,
273-
duration=10000,
272+
startTime=1502820146071158,
273+
duration=10000000,
274274
flags=1,
275275
tags=[
276276
jaeger.Tag(
@@ -331,8 +331,9 @@ def test_translate_to_jaeger(self):
331331
traceIdHigh=1846305573,
332332
traceIdLow=2112048274,
333333
spanId=7929822056569588882,
334-
startTime=1502820146000,
335-
duration=10000)
334+
parentSpanId=0,
335+
startTime=1502820146071158,
336+
duration=10000000)
336337
]
337338

338339
spans_json = [span.format_span_json() for span in spans]
@@ -372,6 +373,7 @@ def test_convert_hex_str_to_int(self):
372373
jaeger_exporter._convert_hex_str_to_int(invalid_id)
373374
valid_id = '290c63257de34c92'
374375
jaeger_exporter._convert_hex_str_to_int(valid_id)
376+
self.assertIsNone(jaeger_exporter._convert_hex_str_to_int(None))
375377

376378

377379
class MockBatch(object):

0 commit comments

Comments
 (0)