def add_execution_tag(key: str, value: str, should_log_errors: bool = True) -> bool: """ Use this function to add an execution_tag to your function with a dynamic value. This value can be searched within the Lumigo platform. The maximum number of tags is 50. :param key: Length should be between 1 and 50. :param value: Length should be between 1 and 70. :param should_log_errors: Should a log message be printed in case the tag can't be added. """ try: key = str(key) value = str(value) tags_len = SpansContainer.get_span().get_tags_len() if validate_tag(key, value, tags_len, should_log_errors): SpansContainer.get_span().add_tag(key, value) else: return False except Exception: if should_log_errors: warn_client(ADD_TAG_ERROR_MSG_PREFIX) return False return True
def validate_tag(key, value, tags_len, should_log_errors): value = str(value) if not key or len(key) >= MAX_TAG_KEY_LEN: if should_log_errors: warn_client( f"{ADD_TAG_ERROR_MSG_PREFIX}: key length should be between 1 and {MAX_TAG_KEY_LEN}: {key} - {value}" ) return False if not value or len(value) >= MAX_TAG_VALUE_LEN: if should_log_errors: warn_client( f"{ADD_TAG_ERROR_MSG_PREFIX}: value length should be between 1 and {MAX_TAG_VALUE_LEN}: {key} - {value}" ) return False if tags_len >= MAX_TAGS: if should_log_errors: warn_client( f"{ADD_TAG_ERROR_MSG_PREFIX}: maximum number of tags is {MAX_TAGS}: {key} - {value}" ) return False return True
def test_warn_client_dont_print(capsys, monkeypatch): monkeypatch.setenv("LUMIGO_WARNINGS", "off") warn_client("message") assert capsys.readouterr().out == ""
def test_warn_client_print(capsys): warn_client("message") assert capsys.readouterr().out.startswith(f"{WARN_CLIENT_PREFIX}: message")