FCSCOpendata / ckanext-fcscopendata

Theming extension for fcsc opendata platform
GNU Affero General Public License v3.0
0 stars 2 forks source link

Add Resource Download Stats #45

Open steveoni opened 2 years ago

steveoni commented 2 years ago

Acceptance

Task

steveoni commented 2 years ago

Analysis to see if it is possible to use azure application insight.

First, there was an investigation of how ckanext-googleanalytics works:

1) A track id is generated which is firstly added to the page header 2) Ckanext google analytics provides a custom function that is used to wrap all action functions and resource API 3) Each API events are stored as a dictionary and sent to gooogleanalytics 4) There is functionality to store event data from google analytics in package_stats and resource_stats table for easy query to enable download stats display

This investigation is used to guide what to look for in Azure application insight

To use azure application insight we need to:

1) Setup application insights resource 2) Obtain the credential key which will be used with Azure SDK 3) Download Opencesus Python SDK 4) Experiment with how to use this SDK to intercept API and emit results to the azure application monitor and also receive updates from the application monitor.

This link https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python shows how to use the Python SDK, but the example only shows how to use logger to emit log to azure to monitor the app.

Also after further investigation was able to obtain a version for the flask, which wrap the app with a flask middleware. This track all incoming request sent to our flask app https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python-request

ISSUES:

1) The flask middleware can track incoming requests sent to the app, but no doc to sure how to create a custom tracking event as it is possible in google analytics. The custom event enables us to store events like a dictionary since we have different packages with resources, the custom event makes it possible to receive data for each of these packages.

2) No detailed documentation, and no lot of examples on how to use the package. Google analytics seems to be the most used and easy to get more information on.

But with more experiments and testing we can figure out how to use it for our main purpose.