Closed Bug 1186918 Opened 9 years ago Closed 9 years ago

Set a custom user-agent for python client requests

Categories

(Tree Management Graveyard :: Treeherder: Client Libraries, defect, P2)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mdoglio, Assigned: emorley)

References

Details

Attachments

(1 file)

So that we can look at the logs and tell who is using what.
An example of such user-agent could "treeherder-py/1.x.x".
Great idea :-)

Perhaps with optional project name that can be added?

eg: "treeherder-py/1.x.x Autophone"
Once I complete the work on the new auth system we will be able to identify a client via either the access token or the api key.
Yeah I was just thinking of the apache/gunicorn logs where the user presumably will be in the POST body, not the query string as is at present. But we should still be able to see the headers in the new relic transactions I guess :-)
Blocks: 1188398
Assignee: nobody → emorley
Status: NEW → ASSIGNED
Priority: -- → P2
Summary: Set a custom user-agent in the client requests → Set a custom user-agent for python client requests
I'm open to suggestions for the client name given in the user agent. On that note, once we have the nodejs client in the Treeherder repo we may want to rename some of the python client directories, so having something consistent might make sense.
Attachment #8643750 - Flags: review?(wlachance)
Comment on attachment 8643750 [details] [review]
Set a custom user-agent for python client requests

This all looks fine to me. treeherder-pyclient sounds like a fine agent name.
Attachment #8643750 - Flags: review?(wlachance) → review+
Commits pushed to master at https://github.com/mozilla/treeherder

https://github.com/mozilla/treeherder/commit/91824400b638c5fc6874c5474803e94d63f382f9
Bug 1186918 - Python client: Make the version available at runtime

So we can use it in the User-Agent later. Uses the suggestion from:
https://packaging.python.org/en/latest/single_source_version.html

https://github.com/mozilla/treeherder/commit/220d9ef8c216825cf341a25e53db197b3b0fab1c
Bug 1186918 - Python client: Use a constant for request headers

In the next commit we'll be adding a custom user agent header, which
will increase duplication. Therefore let's define the headers only once
to avoid this. The Content-Type header is redundant for post() since
one is set automatically when using the `json` param:
https://github.com/kennethreitz/requests/blob/f5dacf84468ab7e0631cc61a3f1431a32e3e143c/requests/models.py#L418

https://github.com/mozilla/treeherder/commit/15e43e94c76e20b6dddcdfcd6cfb54ae0032e46e
Bug 1186918 - Python client: List client name+version in the User-Agent

So we can more easily see which API requests are coming from which
client type, and know how many people are on older versions of the
client.
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Product: Tree Management → Tree Management Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: