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: add signal for event-tracking emission #230

Merged
merged 8 commits into from
Nov 14, 2023
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
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)
Comment on lines +29 to +30
Copy link
Contributor Author

@Ian2012 Ian2012 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the event bus doesn't support dictionaries we are sending a JSON string version of the context and the extra data. It's expected that the event bus consumer to handle this information

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(
Ian2012 marked this conversation as resolved.
Show resolved Hide resolved
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"
}