-
Notifications
You must be signed in to change notification settings - Fork 628
Expand file tree
/
Copy pathevent_utils.py
More file actions
32 lines (26 loc) · 924 Bytes
/
event_utils.py
File metadata and controls
32 lines (26 loc) · 924 Bytes
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
"""
Utility for tracking custom events to Application Insights.
"""
import os
import logging
logger = logging.getLogger(__name__)
def track_event_if_configured(event_name: str, event_data: dict):
"""Track custom event to Application Insights if configured.
Args:
event_name: Name of the event to track
event_data: Dictionary of event properties
"""
if os.getenv("APPLICATIONINSIGHTS_ENABLED", "false").lower() == "true":
try:
from azure.monitor.events.extension import track_event
track_event(event_name, event_data)
except ImportError:
logger.warning(
"azure-monitor-events-extension not installed. Skipping track_event for %s",
event_name,
)
else:
logger.debug(
"Skipping track_event for %s: Application Insights is not enabled",
event_name,
)