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 5 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
58 changes: 40 additions & 18 deletions metadata-ingestion/src/datahub/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,15 @@ 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:
Expand All @@ -154,7 +152,7 @@ def ping(
# send event
try:
logger.info("Sending Telemetry")
self.mp.track(self.client_id, action, properties)
self.mp.track(self.client_id, event_name, properties)

except Exception as e:
logger.debug(f"Error reporting telemetry: {e}")
Expand Down Expand Up @@ -183,37 +181,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:
kevinhu marked this conversation as resolved.
Show resolved Hide resolved
telemetry_instance.ping(f"{action}:result", {"status": "completed"})
telemetry_instance.ping(
"function-call",
{
"function": function,
"status": "completed",
},
)
sys.exit(0)
kevinhu marked this conversation as resolved.
Show resolved Hide resolved
# 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)
kevinhu marked this conversation as resolved.
Show resolved Hide resolved
# Catch SIGINTs
except KeyboardInterrupt:
telemetry_instance.ping(f"{action}:result", {"status": "cancelled"})
telemetry_instance.ping(
kevinhu marked this conversation as resolved.
Show resolved Hide resolved
"function-call",
{"function": function, "status": "cancelled"},
)
sys.exit(0)
kevinhu marked this conversation as resolved.
Show resolved Hide resolved

# 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