Skip to content

Commit 3f2bc2c

Browse files
author
Andrey Slotin
committed
Return an empty synthetic span context even if there was no trace context found
1 parent 482efdf commit 3f2bc2c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

instana/http_propagator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def extract(self, carrier): # noqa
108108
baggage={},
109109
sampled=True,
110110
synthetic=synthetic)
111+
elif synthetic:
112+
ctx = SpanContext(synthetic=synthetic)
113+
111114
return ctx
112115

113116
except Exception:

instana/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def start_span(self,
8484
# Assemble the child ctx
8585
gid = generate_id()
8686
ctx = SpanContext(span_id=gid)
87-
if parent_ctx is not None:
87+
if parent_ctx is not None and parent_ctx.trace_id is not None:
8888
if parent_ctx._baggage is not None:
8989
ctx._baggage = parent_ctx._baggage.copy()
9090
ctx.trace_id = parent_ctx.trace_id

tests/clients/test_urllib3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def test_client_error(self):
509509
self.assertEqual(1, urllib3_span.ec)
510510

511511
def test_requestspkg_get(self):
512+
self.recorder.clear_spans()
513+
512514
with tracer.start_active_span('test'):
513515
r = requests.get(testenv["wsgi_server"] + '/', timeout=2)
514516

tests/opentracing/test_ot_propagators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def test_http_mixed_case_extract():
7171
assert not ctx.synthetic
7272

7373

74+
def test_http_extract_synthetic_only():
75+
ot.tracer = InstanaTracer()
76+
77+
carrier = {'X-Instana-Synthetic': '1'}
78+
ctx = ot.tracer.extract(ot.Format.HTTP_HEADERS, carrier)
79+
80+
assert isinstance(ctx, span.SpanContext)
81+
assert ctx.trace_id is None
82+
assert ctx.span_id is None
83+
assert ctx.synthetic
84+
85+
7486
def test_http_no_context_extract():
7587
ot.tracer = InstanaTracer()
7688

0 commit comments

Comments
 (0)