Skip to content

Example using Moesif API Analytics with Moesif Python Request library

Notifications You must be signed in to change notification settings

Moesif/moesif-python-outgoing-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Moesif Outgoing Example for Python

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.

Configuration options

IDENTIFY_USER_OUTGOING

(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.

IDENTIFY_COMPANY_OUTGOING

(optional) (req, res) => string, a function that takes Requests request and response, and returns a string that is the company id for this event.

GET_METADATA_OUTGOING

(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.

GET_SESSION_TOKEN_OUTGOING

(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.

LOG_BODY_OUTGOING

(optional) boolean, default True, Set to False to remove logging request and response body.

SKIP_OUTGOING

(optional) (req, res) => boolean, a function that takes a Requests request and response, and returns true if you want to skip this particular event.

How to run this example.

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.

Create your local environment
conda create -n outgoingrequest python=3.6 anaconda # Create the environment
source activate outgoingrequest # Activate the environment
Install dependencies
pip install -r requirements.txt
Be sure to edit the main.py to include your own application id.
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.

Start the application
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].

Other integrations

To view more documentation on integration options, please visit the Integration Options Documentation.

About

Example using Moesif API Analytics with Moesif Python Request library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages