This solution enables the collection of usage data for Copilot for Business clients using mitmproxy.
sample.py
is used as the mitmproxy script.copilot-usage.py
is used to collect Copilot usage data.copilotchat-usage.py
is used to collect Copilot chat usage data.copilot-prompt.py
is used to collect all prompts, including Copilot and chat.
Ensure the following prerequisites are met:
- Mitmproxy version 8.0.0
- Python version 3.8.10
- Linux-5.15.0-1050-azure-x86_64-with-glibc2.29 platform
Configure GitHub Copilot proxy settings by referring to the GitHub Copilot Proxy Config documentation.
Install and configure Elasticsearch on AKS or use an existing Elasticsearch cluster. To install Elasticsearch on AKS, follow the steps in the Install Elasticsearch on AKS guide.
Install mitmproxy on your server and download the required Python libraries. For more information, refer to the mitmproxy documentation.
Follow these steps to use the solution:
-
Start mitmproxy with the desired parameters. Choose from the following options:
-
mitmproxy
,mitmdump
, andmitmweb
are three different models of mitmproxy. -
Examples of starting the proxy server:
mitmproxy --listen-host 0.0.0.0 --set block_global=false -s <your script file path> -p <port>
mitmweb --web-host 0.0.0.0 --listen-host 0.0.0.0 --set block_global=false -s <script.py>
(The default port for the proxy is 8080, and the default web port is 8081.)mitmdump --listen-host 0.0.0.0 --set block_global=false -s <your script file path> -p <port>
-
After starting the proxy server, configure your browser to use the proxy and access http://mitm.it to download the certificate.
-
-
Additional information:
- For VS Code users:
- Install the
win-ca
extension to make the customized proxy certificate work. - To collect data, the proxy server address should be:
http://<user>@<server_address>:<port>
, no password is required.
- Install the
- For JetBrains users:
- Enable the option 'accept non-trusted certificates automatically' in
Settings -> Tools -> Server Certificates
. - Fill in the 'host name', 'port number', choose 'Proxy authentication', and enter your username in 'Login'. No password is required.
- Enable the option 'accept non-trusted certificates automatically' in
- For VS Code users:
-
Provide your own information to start the proxy server, including:
allowed_users.txt
file with a list of usernames. For example:user1 user2 ... usern
- Config file containing Elasticsearch information.
-
Start the proxy server using the provided command.
-
Run
copilot-usage.py
or other file to obtain a CSV file. You can then perform any desired actions using a spreadsheet.
If you encounter an error message indicating compatibility issues between mitmproxy and Python 3.8, you may need to reinstall certain packages with specific versions as prompted.