|
101 | 101 | _headers = {} |
102 | 102 |
|
103 | 103 |
|
| 104 | +def decode_id(span, value): |
| 105 | + if value in ["trace_id", "span_id"]: |
| 106 | + return hexlify(getattr(span, value)).decode("utf-8") |
| 107 | + return value |
| 108 | + |
| 109 | + |
104 | 110 | def span_attr(span, attr, atype): |
105 | 111 | for value in (atrb.value for atrb in span.attributes if atrb.key == attr): |
106 | 112 | return getattr(value, atype) |
@@ -442,10 +448,7 @@ def test_variables( |
442 | 448 | ): |
443 | 449 | if http_ver == 0: |
444 | 450 | pytest.skip("no headers support") |
445 | | - value = value[idx] |
446 | | - if type(value) is str and value in ["trace_id", "span_id"]: |
447 | | - value = hexlify(getattr(span, value)).decode("utf-8") |
448 | | - assert headers.get(name) == value |
| 451 | + assert headers.get(name) == decode_id(span, value[idx]) |
449 | 452 |
|
450 | 453 | @pytest.mark.xfail(reason="otel variables are present when trace is off") |
451 | 454 | @pytest.mark.parametrize("idx", [10, 11], ids=["no context", "context"]) |
@@ -505,13 +508,6 @@ def test_trace_context( |
505 | 508 | if http_ver == 0: |
506 | 509 | pytest.skip("no headers support") |
507 | 510 | value = value[idx - 2] |
508 | | - if type(value) is str: |
509 | | - value = "-".join( |
510 | | - ( |
511 | | - hexlify(getattr(span, val)).decode("utf-8") |
512 | | - if val in ["trace_id", "span_id"] |
513 | | - else val |
514 | | - ) |
515 | | - for val in value.split("-") |
516 | | - ) |
| 511 | + if value is not None: |
| 512 | + value = "-".join(decode_id(span, val) for val in value.split("-")) |
517 | 513 | assert headers.get(name) == value |
0 commit comments