Skip to content

Instantly share code, notes, and snippets.

@srinivasiyer
Created June 16, 2022 03:38
Show Gist options
  • Save srinivasiyer/41213c6d1dc306c91d4cb79040553a54 to your computer and use it in GitHub Desktop.
Save srinivasiyer/41213c6d1dc306c91d4cb79040553a54 to your computer and use it in GitHub Desktop.
Dadadog Decorator for Repository File in Python
@tracer.wrap(
service=DatadogService.CHANNELS_CHAT_API.value,
name=DatadogOperation.API_CALL.value,
resource="AccountAgentsRepository.fetch_all",
)
async def fetch_all(
self, *, chat_account_id: int, api_access_token: str
) -> List[AccountAgentModel]:
url = f"{self.__chat_api_host}/api/v1/accounts/{chat_account_id}/agents"
span = tracer.current_span()
add_tag_to_span(span, "chat_account_id", chat_account_id)
add_tag_to_span(span, "api_access_token", api_access_token)
add_tag_to_span(span, "url", url)
async with self.__http_client.get(
url=url,
headers={API_ACCESS_TOKEN: api_access_token},
) as response:
try:
if response.status == 200:
response_list: List[Dict[str, Any]] = await response.json()
account_agent_models = []
for agent_map in response_list:
account_agent_models.append(AccountAgentModel(**agent_map))
return account_agent_models
else:
raise Exception(
"chat API Response Code was not 200", response.status
)
except Exception as e:
self.__log.error(
statement="FETCH_ACCOUNT_AGENTS_FAILED",
description="There was an exception fetching users on an account on chat",
error=e,
search_terms={
"chat_account_id": chat_account_id,
},
references={
"response_status": response.status,
"url": url,
"api_access_token": api_access_token,
},
)
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment