This is an example to capture outgoing API calls to send to Moesif for API Analytics and monitoring.
Moesif is an API analytics platform. moesifpythonrequest a library to capture outgoing API calls to send to Moesif.
(optional, but highly recommended) (req, res) => string, a function that takes Requests request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically, but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.
(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the company id for this event.
(optional) (req, res) => dictionary, a function that takes Requests request and response, and returns a dictionary (must be able to be encoded into JSON). This allows to associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.
(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
(optional) boolean, default True, Set to False to remove logging request and response body.
(optional) (req, res) => boolean, a function that takes a Requests request and response, and returns true if you want to skip this particular event.
First you'll need to get the source of the project. Do this by cloning the repository:
# Get the project code
git clone https://github.com/Moesif/moesif-python-outgoing-example.git
NOTE: While working with Python, we would recommend to use virtual environment to keep all the project's dependencies isolated from other projects.
conda create -n outgoingrequest python=3.6 anaconda # Create the environment
source activate outgoingrequest # Activate the environment
pip install -r requirements.txt
moesif_settings = {
'APPLICATION_ID': 'Your Moesif Application Id'
}
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking API Keys.
python main.py
The data should be captured in the corresponding Moesif account.
Congratulations! If everything was done correctly, Moesif should now be tracking outgoing network requests. If you have any issues with set up, please reach out to [email protected].
To view more documentation on integration options, please visit the Integration Options Documentation.