Skip to content

Commit

Permalink
Add more files that need updating WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Dec 11, 2019
1 parent 0db0bc4 commit 6299dcd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ def extract(
@classmethod
def inject(
cls,
context: trace.SpanContext,
span: trace.Span,
set_in_carrier: httptextformat.Setter[_T],
carrier: _T,
) -> None:
if context == trace.INVALID_SPAN_CONTEXT:

context = span.get_context()

if context() == trace.INVALID_SPAN_CONTEXT:
return
traceparent_string = "00-{:032x}-{:016x}-{:02x}".format(
context.trace_id, context.span_id, context.trace_options
context.trace_id,
context.span_id,
context.trace_options
)
set_in_carrier(
carrier, cls._TRACEPARENT_HEADER_NAME, traceparent_string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def inject(
should know how to set header values on the carrier.
"""
get_global_httptextformat().inject(
tracer.get_current_span().get_context(), set_in_carrier, carrier
tracer.get_current_span(), set_in_carrier, carrier
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_no_traceparent_header(self):
RFC 4.2.2:
If no traceparent header is received, the vendor creates a new trace-id and parent-id that represents the current request.
If no traceparent header is received, the vendor creates a new
trace-id and parent-id that represents the current request.
"""
output = {} # type:typing.Dict[str, typing.List[str]]
span_context = FORMAT.extract(get_as_list, output)
Expand Down Expand Up @@ -81,13 +82,16 @@ def test_invalid_trace_id(self):
RFC 3.2.2.3
If the trace-id value is invalid (for example if it contains non-allowed characters or all
zeros), vendors MUST ignore the traceparent.
If the trace-id value is invalid (for example if it contains
non-allowed characters or all zeros), vendors MUST ignore the
traceparent.
RFC 3.3
If the vendor failed to parse traceparent, it MUST NOT attempt to parse tracestate.
Note that the opposite is not true: failure to parse tracestate MUST NOT affect the parsing of traceparent.
If the vendor failed to parse traceparent, it MUST NOT attempt to
parse tracestate.
Note that the opposite is not true: failure to parse tracestate MUST
NOT affect the parsing of traceparent.
"""
span_context = FORMAT.extract(
get_as_list,
Expand All @@ -101,19 +105,22 @@ def test_invalid_trace_id(self):
self.assertEqual(span_context, trace.INVALID_SPAN_CONTEXT)

def test_invalid_parent_id(self):
"""If the parent id is invalid, we must ignore the full traceparent header.
"""If the parent id is invalid, we must ignore the full traceparent
header.
Also ignore any tracestate.
RFC 3.2.2.3
Vendors MUST ignore the traceparent when the parent-id is invalid (for example,
if it contains non-lowercase hex characters).
Vendors MUST ignore the traceparent when the parent-id is invalid (for
example, if it contains non-lowercase hex characters).
RFC 3.3
If the vendor failed to parse traceparent, it MUST NOT attempt to parse tracestate.
Note that the opposite is not true: failure to parse tracestate MUST NOT affect the parsing of traceparent.
If the vendor failed to parse traceparent, it MUST NOT attempt to parse
tracestate.
Note that the opposite is not true: failure to parse tracestate MUST
NOT affect the parsing of traceparent.
"""
span_context = FORMAT.extract(
get_as_list,
Expand All @@ -131,8 +138,8 @@ def test_no_send_empty_tracestate(self):
RFC 3.3.1.1
Empty and whitespace-only list members are allowed. Vendors MUST accept empty
tracestate headers but SHOULD avoid sending them.
Empty and whitespace-only list members are allowed. Vendors MUST accept
empty tracestate headers but SHOULD avoid sending them.
"""
output = {} # type:typing.Dict[str, str]
FORMAT.inject(
Expand All @@ -155,22 +162,23 @@ def test_format_not_supported(self):
get_as_list,
{
"traceparent": [
"00-12345678901234567890123456789012-1234567890123456-00-residue"
"00-12345678901234567890123456789012-"
"1234567890123456-00-residue"
],
"tracestate": ["foo=1,bar=2,foo=3"],
},
)
self.assertEqual(span_context, trace.INVALID_SPAN_CONTEXT)

def test_propagate_invalid_context(self):
"""Do not propagate invalid trace context.
"""
"""Do not propagate invalid trace context."""
output = {} # type:typing.Dict[str, str]
FORMAT.inject(trace.INVALID_SPAN_CONTEXT, dict.__setitem__, output)
self.assertFalse("traceparent" in output)

def test_tracestate_empty_header(self):
"""Test tracestate with an additional empty header (should be ignored)"""
"""Test tracestate with an additional empty header (should be ignored)
"""
span_context = FORMAT.extract(
get_as_list,
{
Expand Down

0 comments on commit 6299dcd

Please sign in to comment.