aboutsummaryrefslogtreecommitdiff
path: root/R2R/r2r/telemetry/events.py
blob: 5bd7528bd566476e7995730b6797ed3331b8c347 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import uuid
from typing import Any, Dict


class BaseTelemetryEvent:
    def __init__(self, event_type: str, properties: Dict[str, Any]):
        self.event_type = event_type
        self.properties = properties
        self.event_id = str(uuid.uuid4())


class DailyActiveUserEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str):
        super().__init__("DailyActiveUser", {"user_id": user_id})


class FeatureUsageEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str, feature: str):
        super().__init__(
            "FeatureUsage", {"user_id": user_id, "feature": feature}
        )


class ErrorEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str, endpoint: str, error_message: str):
        super().__init__(
            "Error",
            {
                "user_id": user_id,
                "endpoint": endpoint,
                "error_message": error_message,
            },
        )


class RequestLatencyEvent(BaseTelemetryEvent):
    def __init__(self, endpoint: str, latency: float):
        super().__init__(
            "RequestLatency", {"endpoint": endpoint, "latency": latency}
        )


class GeographicDistributionEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str, country: str):
        super().__init__(
            "GeographicDistribution", {"user_id": user_id, "country": country}
        )


class SessionDurationEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str, duration: float):
        super().__init__(
            "SessionDuration", {"user_id": user_id, "duration": duration}
        )


class UserPathEvent(BaseTelemetryEvent):
    def __init__(self, user_id: str, path: str):
        super().__init__("UserPath", {"user_id": user_id, "path": path})