Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device, user and app version to feedback logs #82

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def setup_logs(log_dir: str) -> logging.Logger:
return logger


def get_device(user_agent) -> str:
"""Explicitly give the device of a user-agent object
"""
if user_agent.is_mobile:
return "mobile"
elif user_agent.is_pc:
return "pc"
elif user_agent.is_tablet:
return "tablet"
else:
return "other"


####################
# SETUP #
####################
Expand Down Expand Up @@ -219,18 +232,11 @@ async def imageupload(

# prepare content logs
user_agent = parse(request.headers.get("user-agent"))
device = "other"
if user_agent.is_mobile:
device = "mobile"
elif user_agent.is_pc:
device = "pc"
elif user_agent.is_tablet:
device = "tablet"
extras_logging = {
"bg_date": datetime.now().isoformat(),
"bg_upload_time": round(time.time()-date, 2),
"bg_geolocation": geolocation,
"bg_device": device,
"bg_device": get_device(user_agent),
"bg_device_family": user_agent.device.family,
"bg_device_os": user_agent.os.family,
"bg_device_browser": user_agent.browser.family,
Expand Down Expand Up @@ -282,15 +288,23 @@ async def imageupload(


@app.post("/feedback")
async def log_feedback(request: Request):
async def log_feedback(request: Request, user_id: Union[str, None] = Cookie(None)):
res = await request.json()
user_agent = parse(request.headers.get("user-agent"))

extras_logging = {
"bg_date": datetime.now().isoformat(),
"bg_image_url": res["image_url"],
"bg_feedback_bool": res["feedback"],
"bg_confidence": res["confidence"],
"bg_label": res["label"],
"bg_confidence_level": res["confidence_level"]
"bg_confidence": res["confidence"],
"bg_confidence_level": res["confidence_level"],
"bg_user_id": user_id,
"bg_device": get_device(user_agent),
"bg_device_family": user_agent.device.family,
"bg_device_os": user_agent.os.family,
"bg_device_browser": user_agent.browser.family,
"bg_version": APP_VERSION,
}
logger.info("Identification feedback", extra=extras_logging)
return
6 changes: 6 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_feedback_and_logs(self):
r = requests.get(self.url + "/logs")
self.assertEqual(r.status_code, 200)
log = r.json()[0]
self.assertEqual(
set(log.keys()),
set({'timestamp', '_bg_device', 'host', '_bg_feedback_bool', 'version', '_bg_device_os', '_bg_device_family',
'short_message', '_bg_confidence', '_bg_confidence_level', '_bg_date', '_bg_user_id', '_bg_label', '_bg_image_url',
'level', '_bg_device_browser', '_bg_version'})
)
self.assertEqual(log["level"], 6)
self.assertEqual(log["short_message"], "Identification feedback")
self.assertEqual(log["_bg_image_url"], "test")
Expand Down