File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99#
1010
1111import os
12+ import time
13+
1214from functools import wraps
1315from hashlib import sha256
1416from http import HTTPStatus
@@ -28,24 +30,25 @@ def analyze(event_id):
2830 def decorator (function ):
2931 @wraps (function )
3032 def wrapper (* args , ** kwargs ):
33+ start = time .time ()
3134 result = function (* args , ** kwargs )
35+ duration_in_secs = round (time .time () - start )
3236
3337 # record the analytics *after* a function is done
34- post (event_id )
38+ post (event_id , duration_in_secs )
3539 return result
3640
3741 return wrapper
3842
3943 return decorator
4044
4145
42- def post (event_id ):
46+ def post (event_id , duration_in_secs ):
4347 """
4448 Collect anonymous analytics via Plausible.io
4549
4650 event_id - str - similar to a page URL, e.g. `pull_request_comment`
47- referrer - str - e.g. https://github.com
48- actor_id - str or int - account ID which triggered the event
51+ duration_in_secs - int - rounded up duration of this event
4952 """
5053 if not strtobool (os .environ .get ("INPUT_ANONYMOUS-ANALYTICS" , "true" )):
5154 if strtobool (os .environ .get ("INPUT_DEBUG" , "false" )):
@@ -78,6 +81,7 @@ def post(event_id):
7881 "referrer" : referrer ,
7982 "domain" : "kiwitcms-gitops" ,
8083 "props" : {
84+ "duration" : duration_in_secs ,
8185 "version" : __version__ ,
8286 },
8387 },
You can’t perform that action at this time.
0 commit comments