Skip to content

Commit

Permalink
feat: Allow truthy values for env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
chbndrhnns committed Mar 2, 2021
1 parent 45d0ba1 commit e16a946
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions prometheus_fastapi_instrumentator/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def instrument(self, app: FastAPI):

if (
self.should_respect_env_var
and os.environ.get(self.env_var_name, "false") != "true"
and not self._should_instrumentate()
):
return self

Expand Down Expand Up @@ -242,7 +242,7 @@ def expose(

if (
self.should_respect_env_var
and os.environ.get(self.env_var_name, "false") != "true"
and not self._should_instrumentate()
):
return self

Expand Down Expand Up @@ -324,6 +324,10 @@ def _get_handler(self, request: Request) -> Tuple[str, bool]:

# ==========================================================================

def _should_instrumentate(self):
"""Check if the environment variable is set to a truthy value"""
return os.getenv(self.env_var, 'False').lower() in ['true', '1']

def _is_handler_excluded(self, handler: str, is_templated: bool) -> bool:
"""Determines if the handler should be ignored.
Expand Down

0 comments on commit e16a946

Please sign in to comment.