-
Notifications
You must be signed in to change notification settings - Fork 6
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
[#1185] Outgoing requests tracking #524
Conversation
I think this would be a neat way to do this. Couple of thoughts:
Looking further this only works for requests when making use of requests-sessions, correct? So this does mean that plain |
Requests library sends under the hood all requests through |
Compromise is to put this in src/external_api_logging/ to allow easier migration to a third-party Django app |
reqhdrs=self._formatHeaders(record.req.headers), | ||
reshdrs=self._formatHeaders(record.res.headers), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the header information for debugging, but I'm not sure if we can store that in logs. @alextreme can pitch in on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other headers should be fine, but I'd recommend to avoid logging the Authorization header
Codecov Report
@@ Coverage Diff @@
## develop #524 +/- ##
===========================================
+ Coverage 96.47% 96.52% +0.04%
===========================================
Files 527 538 +11
Lines 19023 19206 +183
===========================================
+ Hits 18353 18538 +185
+ Misses 670 668 -2
... and 11 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
blank=True, | ||
default="", | ||
help_text=_("The url of the outgoing request."), | ||
) | ||
hostname = models.CharField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put a comment here to note that .hostname
is obviously part of .url
but we also have it as a field so we can filter on it in the admin.
@cached_property | ||
def query_params(self): | ||
parsed_url = urlparse(self.url) | ||
return parsed_url.query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok for now since we only take the query, but if we'd want more url components you'd cache the urlparse()
result and access parts of it like so:
@cached_property
def url_parsed(self):
return urlparse(self.url)
@property
def query_params(self):
return self.url_parsed.query
@property
def scheme(self):
return self.url_parsed.scheme
This is an approach according to the fact that we already use requests library (same for the external libraries we use for the APIs), by adding a hook to each request (based on a session). Also this approach was discussed with Sergei and Bart at some point.
@Bartvaderkin @alextreme feel free to have a first look and if you agree I can continue with making this more stable.