Skip to content

Commit

Permalink
Merge pull request #1 from ASUS-AICS/appinsights
Browse files Browse the repository at this point in the history
Appinsights
  • Loading branch information
whelan9453 authored Dec 11, 2019
2 parents 62c2e15 + 5b837f2 commit ce7f3fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
alembic==1.0.11 # via flask-migrate
amqp==2.5.0 # via kombu
apispec[yaml]==1.3.3 # via flask-appbuilder
applicationinsights==0.11.9
asn1crypto==0.24.0 # via cryptography
attrs==19.1.0 # via jsonschema
babel==2.7.0 # via flask-babel
Expand Down Expand Up @@ -82,3 +83,6 @@ webencodings==0.5.1 # via bleach
werkzeug==0.15.5 # via flask, flask-jwt-extended
wtforms-json==0.3.3
wtforms==2.2.1 # via flask-wtf, wtforms-json

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def get_git_sha():
"sqlalchemy-utils>=0.33.2",
"sqlparse>=0.3.0,<0.4",
"wtforms-json",
"applicationinsights",
],
extras_require={
"bigquery": ["pybigquery>=0.4.10", "pandas_gbq>=0.10.0"],
Expand Down
12 changes: 11 additions & 1 deletion superset/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=C,R,W
import os
import functools
import inspect
import json
Expand All @@ -26,6 +27,8 @@

from flask import current_app, g, request

from applicationinsights import TelemetryClient


class AbstractEventLogger(ABC):
@abstractmethod
Expand Down Expand Up @@ -125,8 +128,14 @@ def get_event_logger_from_cfg_value(cfg_value: object) -> AbstractEventLogger:
logging.info(f"Configured event logger of type {type(result)}")
return cast(AbstractEventLogger, result)


INSTRUMENTATION_KEY=os.environ.get('INSTRUMENTATION_KEY')
tc = TelemetryClient(INSTRUMENTATION_KEY)
class DBEventLogger(AbstractEventLogger):
def appinsights(self, data):
print(f'appinsights triggerd with {data}')
tc.track_event('medical.superset', data)
tc.flush()

def log(self, user_id, action, *args, **kwargs):
from superset.models.core import Log

Expand All @@ -152,6 +161,7 @@ def log(self, user_id, action, *args, **kwargs):
user_id=user_id,
)
logs.append(log)
self.appinsights({'level': 'info', 'success': 'true', 'state':'finish', 'function': action, 'json': json_string, 'duration': duration_ms, 'referrer': referrer, 'user_id': user_id})

sesh = current_app.appbuilder.get_session
sesh.bulk_save_objects(logs)
Expand Down

0 comments on commit ce7f3fd

Please sign in to comment.