Skip to content

Commit

Permalink
feat: add signal for event-tracking emission (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 authored Nov 14, 2023
1 parent 24ed9ce commit 39f1f67
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "9.0.1"
__version__ = "9.1.0"
6 changes: 6 additions & 0 deletions openedx_events/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""
30 changes: 30 additions & 0 deletions openedx_events/analytics/data.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions openedx_events/analytics/signals.py
Original file line number Diff line number Diff line change
@@ -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,
}
)
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 39f1f67

Please sign in to comment.