Skip to content

Commit 30a58e2

Browse files
authored
add tagging for demo notebooks (#793)
But it can be used for tagging other stuff, too.
1 parent fa419ae commit 30a58e2

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lineapy/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from lineapy.editors.ipython import start, stop, visualize
1818
from lineapy.execution.context import get_context
1919
from lineapy.instrumentation.tracer import Tracer
20+
from lineapy.utils.analytics.usage_tracking import tag
2021
from lineapy.utils.config import options
2122
from lineapy.utils.lineabuiltins import db, file_system
2223
from lineapy.utils.version import __version__
@@ -41,9 +42,11 @@
4142
"db",
4243
"file_system",
4344
"options",
45+
"tag",
4446
"__version__",
4547
]
4648

49+
4750
# Create an ipython extension that starts and stops tracing
4851
# https://ipython.readthedocs.io/en/stable/config/extensions/index.html#writing-extensions
4952
# Can be used like %load_ext lineapy

lineapy/utils/analytics/event_schemas.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ class CyclicGraphEvent:
7474
dummy_entry: str # dummy entry, may populate with extra information later
7575

7676

77-
AllEvents = Union[
77+
@dataclass
78+
class TagEvent:
79+
tag: str # dummy entry, may populate with extra information later
80+
81+
82+
TrackingEvent = Union[
7883
CatalogEvent,
7984
LibImportEvent,
8085
ExceptionEvent,
@@ -85,4 +90,5 @@ class CyclicGraphEvent:
8590
GetValueEvent,
8691
GetVersionEvent,
8792
CyclicGraphEvent,
93+
TagEvent,
8894
]

lineapy/utils/analytics/usage_tracking.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import requests
1919
from IPython import get_ipython
2020

21-
from lineapy.utils.analytics.event_schemas import AllEvents
21+
from lineapy.utils.analytics.event_schemas import TagEvent, TrackingEvent
2222
from lineapy.utils.config import options
2323
from lineapy.utils.version import __version__
2424

@@ -116,7 +116,7 @@ def _send_amplitude_event(event_type: str, event_properties: dict):
116116
logger.debug(f"Tracking Error: {str(err)}")
117117

118118

119-
def track(event: AllEvents):
119+
def track(event: TrackingEvent):
120120
""" """
121121
if do_not_track():
122122
return
@@ -128,3 +128,14 @@ def track(event: AllEvents):
128128
event_properties["runtime"] = _runtime()
129129

130130
return _send_amplitude_event(event.__class__.__name__, event_properties)
131+
132+
133+
def tag(tag_name: str):
134+
# This can be used by adding `lineapy.tag('tag_name')` before do_not_track
135+
# conditions are triggered, e.g., by `lineapy.options.set("is_demo", True)`
136+
#
137+
# Put these two lines at the top of demo notebooks:
138+
# lineapy.tag("demo_name") # change "demo_name" with actual demo name.
139+
# lineapy.options.set("is_demo", True)
140+
141+
track(TagEvent(tag_name))

0 commit comments

Comments
 (0)