Skip to content

Commit

Permalink
fix: consolidate duplicate logic to a common used func
Browse files Browse the repository at this point in the history
  • Loading branch information
sagivoululumigo committed Dec 25, 2023
1 parent c957d37 commit f7946ad
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/lumigo_opentelemetry/libs/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,32 @@ def get_description(self) -> str:
)


def does_endpoint_match_client_filtering_regexes(endpoint: str) -> bool:
regexes = _get_string_list_from_env_var(LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT)
def does_endpoint_match_env_var_filtering_regex(
endpoint: str, env_var_name: str
) -> bool:
regexes = _get_string_list_from_env_var(env_var_name)
if not regexes:
return False

return any(does_match_regex_safe(regex, endpoint) for regex in regexes)


def does_endpoint_match_server_filtering_regexes(endpoint: str) -> bool:
regexes = _get_string_list_from_env_var(LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER)
if not regexes:
return False
def does_endpoint_match_client_filtering_regexes(endpoint: str) -> bool:
return does_endpoint_match_env_var_filtering_regex(
endpoint, LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_CLIENT
)

return any(does_match_regex_safe(regex, endpoint) for regex in regexes)

def does_endpoint_match_server_filtering_regexes(endpoint: str) -> bool:
return does_endpoint_match_env_var_filtering_regex(
endpoint, LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX_SERVER
)

def does_endpoint_match_filtering_regexes(endpoint: str) -> bool:
regexes = _get_string_list_from_env_var(LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX)
if not regexes:
return False

return any(does_match_regex_safe(regex, endpoint) for regex in regexes)
def does_endpoint_match_filtering_regexes(endpoint: str) -> bool:
return does_endpoint_match_env_var_filtering_regex(
endpoint, LUMIGO_FILTER_HTTP_ENDPOINTS_REGEX
)


def does_match_regex_safe(regex: str, value: str) -> bool:
Expand Down

0 comments on commit f7946ad

Please sign in to comment.