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

Ability to track API requests and their source (frontend/human/other) #2069

Open
szabozoltan69 opened this issue Mar 13, 2024 · 2 comments
Open
Assignees
Labels

Comments

@szabozoltan69
Copy link
Contributor

szabozoltan69 commented Mar 13, 2024

The API requests to the Django backend should be logged. (The default Django log also shows the endpoints, but it's not enough.) This task has some overlapping parts with #2065

The source of the requests would be also good to know: is it a ...

  • frontend request (the most of the requests)
  • ad-hoc human or human-driven requests out of GO frontend (Postman, curl...)
  • other (like Googlebot or other bot or scraper)

The frontend should send the requests with something like headers: {'X-Request-Source': 'frontend-app' }, this would make backend's life easier. (At least easier than gathering "Frontend IP-Addresses".)

  • the Googlebot and other bots give their name on the requests
  • all the others are the ad-hoc requests.

Let's make an opportunity to have an overview on these.

@szabozoltan69
Copy link
Contributor Author

szabozoltan69 commented Mar 13, 2024

After the front-end change this code could be implemented:

def my_view(request):
  if request.method == 'POST' and 'source' in request.data and request.data['source'] == 'frontend-app':
    source = "Frontend"
  elif "Googlebot" in something or "bot" in something:
    source = "Bot"
  else:
    source = "Ad-hoc"
  # Log the request details along with the source
  logger.info(f"Request from {request.META['REMOTE_ADDR']} (source: {source})")

@nanometrenat
Copy link
Contributor

nanometrenat commented Mar 15, 2024

xref previous tickets around logging API requests #572 (comment) and #1154

and also #1853 re implementing API keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants