Skip to content

Introduce the send event once to the IterativeTelemetryLogger class #59

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

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def safety(session: nox.Session) -> None:
session.install(".[dev]")
session.install("safety")
# Ignore https://github.com/pytest-dev/py/issues/287
session.run("safety", "check", "--full-report", "-i", "51457")
# Ignore https://bugzilla.redhat.com/show_bug.cgi?id=1677653#c4
session.run(
"safety", "check", "--full-report", "-i", "51457", "-i", "70612"
)


@nox.session
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tests =
pytest-cov==3.0.0
pytest-mock==3.8.2
pylint==2.15.0
mypy==0.971
mypy==1.11.2
types-requests
dev =
%(tests)s
Expand Down
36 changes: 32 additions & 4 deletions src/iterative_telemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TelemetryEvent:


class IterativeTelemetryLogger:
# pylint: disable=R0902

def __init__(
self,
tool_name,
Expand All @@ -60,6 +62,8 @@ def __init__(
logger.debug("IterativeTelemetryLogger is in debug mode")
self._current_event: Optional[TelemetryEvent] = None

self._event_sent = False

def log_param(self, key: str, value):
if self._current_event:
self._current_event.kwargs[key] = value
Expand All @@ -79,8 +83,8 @@ def event_scope(
def log(
self,
interface: str,
action: str = None,
skip: Union[bool, Callable[[TelemetryEvent], bool]] = None,
action: Optional[str] = None,
skip: Union[bool, Callable[[TelemetryEvent], bool], None] = None,
):
def decorator(func):
@wraps(func)
Expand Down Expand Up @@ -110,14 +114,16 @@ def inner(*args, **kwargs):

return decorator

def send_cli_call(self, cmd_name: str, error: str = None, **kwargs):
def send_cli_call(
self, cmd_name: str, error: Optional[str] = None, **kwargs
):
self.send_event("cli", cmd_name, error=error, **kwargs)

def send_event(
self,
interface: str,
action: str,
error: str = None,
error: Optional[str] = None,
use_thread: bool = False,
use_daemon: bool = True,
**kwargs,
Expand All @@ -133,6 +139,28 @@ def send_event(
use_daemon=use_daemon,
)

def send_event_once(
self,
interface: str,
action: str,
error: Optional[str] = None,
use_thread: bool = False,
use_daemon: bool = True,
**kwargs,
):
if self._event_sent:
return

self.send_event(
interface,
action,
error=error,
use_thread=use_thread,
use_daemon=use_daemon,
**kwargs,
)
self._event_sent = True

def is_enabled(self):
return (
os.environ.get(DO_NOT_TRACK_ENV, None) is None and self.enabled()
Expand Down
Loading