Skip to content

Commit aed20f0

Browse files
committed
Start collecting execution duration as custom property
1 parent f26babc commit aed20f0

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

app/analytics.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#
1010

1111
import os
12+
import time
13+
1214
from functools import wraps
1315
from hashlib import sha256
1416
from 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
},

0 commit comments

Comments
 (0)