Helper function to assert that a specific OpenTelemetry attribute exists in a span.
(span_name, attributes, expected_key, expected_value,
expected_type="stringValue")
| 607 | |
| 608 | |
| 609 | def __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 | |
| 637 | def __assert_span_events(span, expected_events=[]): |
no test coverage detected