Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingest): simplify event IDs for function invocations #4398

Merged
merged 9 commits into from
Mar 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions metadata-ingestion/src/datahub/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import os
import platform
import sys
import uuid
from functools import wraps
from pathlib import Path
Expand Down Expand Up @@ -138,26 +137,24 @@ def init_tracking(self) -> None:

def ping(
self,
action: str,
event_name: str,
properties: Optional[Dict[str, Any]] = None,
) -> None:
"""
Send a single telemetry event.

Args:
category (str): category for the event
action (str): action taken
label (Optional[str], optional): label for the event
value (Optional[int], optional): value for the event
event_name (str): name of the event to send.
properties (Optional[Dict[str, Any]]): metadata for the event
"""

if not self.enabled or self.mp is None:
return

# send event
try:
logger.debug("Sending Telemetry")
self.mp.track(self.client_id, action, properties)
logger.info("Sending Telemetry")
self.mp.track(self.client_id, event_name, properties)

except Exception as e:
logger.debug(f"Error reporting telemetry: {e}")
Expand Down Expand Up @@ -186,37 +183,61 @@ def with_telemetry(func: Callable[..., T]) -> Callable[..., T]:
@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:

action = f"function:{func.__module__}.{func.__name__}"
function = f"{func.__module__}.{func.__name__}"

telemetry_instance.init_tracking()
telemetry_instance.ping(action)
telemetry_instance.ping(
"function-call", {"function": function, "status": "start"}
)
try:
res = func(*args, **kwargs)
telemetry_instance.ping(f"{action}:result", {"status": "completed"})
return res
# Catch general exceptions
except Exception as e:
telemetry_instance.ping(
f"{action}:result", {"status": "error", "error": get_full_class_name(e)}
"function-call",
{"function": function, "status": "completed"},
)
raise e
return res
# System exits (used in ingestion and Docker commands) are not caught by the exception handler,
# so we need to catch them here.
except SystemExit as e:
# Forward successful exits
if e.code == 0:
telemetry_instance.ping(f"{action}:result", {"status": "completed"})
sys.exit(0)
# 0 or None imply success
if not e.code:
telemetry_instance.ping(
"function-call",
{
"function": function,
"status": "completed",
},
)
# Report failed exits
else:
telemetry_instance.ping(
f"{action}:result",
{"status": "error", "error": get_full_class_name(e)},
"function-call",
{
"function": function,
"status": "error",
"error": get_full_class_name(e),
},
)
sys.exit(e.code)
raise e
# Catch SIGINTs
except KeyboardInterrupt:
telemetry_instance.ping(f"{action}:result", {"status": "cancelled"})
sys.exit(0)
except KeyboardInterrupt as e:
telemetry_instance.ping(
kevinhu marked this conversation as resolved.
Show resolved Hide resolved
"function-call",
{"function": function, "status": "cancelled"},
)
raise e

# Catch general exceptions
except Exception as e:
telemetry_instance.ping(
"function-call",
{
"function": function,
"status": "error",
"error": get_full_class_name(e),
},
)
raise e

return wrapper