MCPcopy Create free account
hub / github.com/apache/impala / __assert_attr

Function __assert_attr

tests/util/otel_trace.py:609–634  ·  view source on GitHub ↗

Helper function to assert that a specific OpenTelemetry attribute exists in a span.

(span_name, attributes, expected_key, expected_value,
    expected_type="stringValue")

Source from the content-addressed store, hash-verified

607
608
609def __assert_attr(span_name, attributes, expected_key, expected_value,
610 expected_type="stringValue"):
611 """
612 Helper function to assert that a specific OpenTelemetry attribute exists in a span.
613 """
614
615 assert expected_type in ("stringValue", "boolValue", "intValue"), "Invalid " \
616 "expected_type '{}', must be one of 'stringValue', 'boolValue', or 'intValue'" \
617 .format(expected_type)
618
619 val = attributes[expected_key]
620 assert val is not None, "Span '{}' attribute not found: '{}', actual attributes: {}" \
621 .format(span_name, expected_key, attributes)
622 assert val.value == expected_value, "Span '{}' attribute '{}' expected: '{}', " \
623 "actual: '{}'".format(span_name, expected_key, expected_value, val.value)
624
625 if expected_type == "boolValue":
626 expected_type = ATTR_VAL_TYPE_BOOL
627 elif expected_type == "intValue":
628 expected_type = ATTR_VAL_TYPE_INT
629 else:
630 expected_type = ATTR_VAL_TYPE_STRING
631
632 assert val.get_type() == expected_type, "Span '{}' attribute '{}' expected to be " \
633 "of type '{}', actual: '{}'".format(span_name, expected_key, expected_type,
634 val.get_type())
635
636
637def __assert_span_events(span, expected_events=[]):

Callers 6

__assert_rootspan_attrsFunction · 0.85
__assert_initspan_attrsFunction · 0.85

Calls 2

formatMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected