From 39f1f6720e0b9cf9bb9d0d69f19773cc2a0658d7 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Tue, 14 Nov 2023 11:04:05 -0500 Subject: [PATCH] feat: add signal for event-tracking emission (#230) --- CHANGELOG.rst | 6 ++++ openedx_events/__init__.py | 2 +- openedx_events/analytics/__init__.py | 6 ++++ openedx_events/analytics/data.py | 30 +++++++++++++++++ openedx_events/analytics/signals.py | 23 +++++++++++++ ...tics+tracking+event+emitted+v1_schema.avsc | 33 +++++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 openedx_events/analytics/__init__.py create mode 100644 openedx_events/analytics/data.py create mode 100644 openedx_events/analytics/signals.py create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+analytics+tracking+event+emitted+v1_schema.avsc diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8b462fed..b5368db9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,12 @@ Change Log Unreleased ---------- +[9.1.0] - 2023-11-07 +-------------------- +Added +~~~~~~~ +* Added new event TRACKING_EVENT_EMITTED. + [9.0.1] - 2023-10-31 -------------------- Changed diff --git a/openedx_events/__init__.py b/openedx_events/__init__.py index c2a68c7f..55536ae4 100644 --- a/openedx_events/__init__.py +++ b/openedx_events/__init__.py @@ -5,4 +5,4 @@ more information about the project. """ -__version__ = "9.0.1" +__version__ = "9.1.0" diff --git a/openedx_events/analytics/__init__.py b/openedx_events/analytics/__init__.py new file mode 100644 index 00000000..5410a5f4 --- /dev/null +++ b/openedx_events/analytics/__init__.py @@ -0,0 +1,6 @@ +""" +Package where events related to the analytics subdomain are implemented. + +The analytics subdomain corresponds to {Architecture Subdomain} defined in +the OEP-41. +""" diff --git a/openedx_events/analytics/data.py b/openedx_events/analytics/data.py new file mode 100644 index 00000000..801ebdd5 --- /dev/null +++ b/openedx_events/analytics/data.py @@ -0,0 +1,30 @@ +""" +Data attributes for events within the architecture subdomain ``analytics``. + +These attributes follow the form of attr objects specified in OEP-49 data +pattern. +""" + +from datetime import datetime + +import attr + + +@attr.s(frozen=True) +class TrackingLogData: + """ + Data describing tracking events. + + Arguments: + name (str): event name + timestamp (datetime): timestamp of the event + data (str): json string representation of a dictionary with extra data (optional), + e.g. {"course_id": "course-v1:edX+DemoX+Demo_Course"} + context (dict): json string representation of a dictionary of context data + defined in https://edx.readthedocs.io/projects/devdata/en/latest/internal_data_formats/tracking_logs/ + """ + + name = attr.ib(type=str) + timestamp = attr.ib(type=datetime) + data = attr.ib(type=str) + context = attr.ib(type=str) diff --git a/openedx_events/analytics/signals.py b/openedx_events/analytics/signals.py new file mode 100644 index 00000000..6bbb2fd4 --- /dev/null +++ b/openedx_events/analytics/signals.py @@ -0,0 +1,23 @@ +""" +Standardized signals definitions for events within the architecture subdomain ``analytics``. + +All signals defined in this module must follow the name and versioning +conventions specified in OEP-41. + +They also must comply with the payload definition specified in +docs/decisions/0003-events-payload.rst +""" + +from openedx_events.analytics.data import TrackingLogData +from openedx_events.tooling import OpenEdxPublicSignal + +# .. event_type: org.openedx.analytics.tracking.event.emitted.v1 +# .. event_name: TRACKING_EVENT_EMITTED +# .. event_description: emitted when a tracking log is created. +# .. event_data: TrackingLogData +TRACKING_EVENT_EMITTED = OpenEdxPublicSignal( + event_type="org.openedx.analytics.tracking.event.emitted.v1", + data={ + "tracking_log": TrackingLogData, + } +) diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+analytics+tracking+event+emitted+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+analytics+tracking+event+emitted+v1_schema.avsc new file mode 100644 index 00000000..365d4697 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+analytics+tracking+event+emitted+v1_schema.avsc @@ -0,0 +1,33 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "tracking_log", + "type": { + "name": "TrackingLogData", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "timestamp", + "type": "string" + }, + { + "name": "data", + "type": "string" + }, + { + "name": "context", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.analytics.tracking.event.emitted.v1" +}