Skip to content

Commit f85036b

Browse files
authored
fix: pagerduty oauth2 logs (#4540)
1 parent 98236b1 commit f85036b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

keep/providers/pagerduty_provider/pagerduty_provider.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import hashlib
44
import json
5+
import logging
56
import os
67
import time
78
import typing
@@ -28,6 +29,8 @@
2829
# Todo: think about splitting in to PagerdutyIncidentsProvider and PagerdutyAlertsProvider
2930
# Read this: https://community.pagerduty.com/forum/t/create-incident-using-python/3596/3
3031

32+
logger = logging.getLogger(__name__)
33+
3134

3235
@pydantic.dataclasses.dataclass
3336
class PagerdutyProviderAuthConfig:
@@ -248,16 +251,25 @@ def oauth2_logic(**payload) -> dict:
248251
"grant_type": "authorization_code",
249252
}
250253

254+
access_token_response = requests.post(
255+
url=f"{PagerdutyProvider.BASE_OAUTH_URL}/oauth/token",
256+
data=access_token_params,
257+
headers={"Content-Type": "application/x-www-form-urlencoded"},
258+
)
251259
try:
252-
access_token_response = requests.post(
253-
url=f"{PagerdutyProvider.BASE_OAUTH_URL}/oauth/token",
254-
data=access_token_params,
255-
headers={"Content-Type": "application/x-www-form-urlencoded"},
256-
)
257260
access_token_response.raise_for_status()
258261
access_token_response = access_token_response.json()
259-
except Exception as e:
260-
raise Exception(e)
262+
except Exception:
263+
response_text = access_token_response.text
264+
response_status = access_token_response.status_code
265+
logger.exception(
266+
"Failed to get access token",
267+
extra={
268+
"response_text": response_text,
269+
"response_status": response_status,
270+
},
271+
)
272+
raise
261273

262274
access_token = access_token_response.get("access_token")
263275
if not access_token:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "keep"
3-
version = "0.41.21"
3+
version = "0.41.22"
44
description = "Alerting. for developers, by developers."
55
authors = ["Keep Alerting LTD"]
66
packages = [{include = "keep"}]

0 commit comments

Comments
 (0)