-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from Zsailer/fine-grained-data-collection
Fine grained data collection
- Loading branch information
Showing
10 changed files
with
528 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.. _adding-telemetry: | ||
|
||
Adding telemetry to an application | ||
================================== | ||
|
||
Jupyter Telemetry enables you to log events from your running application. (It's designed to work best with traitlet's `Application` object for simple configuration.) To use telemetry, begin by creating an instance of ``EventLog``: | ||
|
||
.. code-block:: python | ||
from jupyter_telemetry import EventLog | ||
class MyApplication: | ||
def __init__(self): | ||
... | ||
# The arguments | ||
self.eventlog = EventLog( | ||
... | ||
# Either pass the traits (see below) here, | ||
# or enable users of your application to configure | ||
# the EventLog's traits. | ||
) | ||
EventLog has two configurable traits: | ||
|
||
- ``handlers``: a list of Python's logging handlers that handle the recording of incoming events. | ||
- ``allowed_schemas``: a dictionary of options for each schema describing what data should be collected. | ||
|
||
Next, you'll need to register event schemas for your application. You can register schemas using the ``register_schema_file`` (JSON or YAML format) or ``register_schema`` methods. | ||
|
||
|
||
Once your have an instance of ``EventLog`` and your registered schemas, you can use the ``record_event`` method to log that event. | ||
|
||
.. code-block:: python | ||
# Record an example event. | ||
event = {'name': 'example event'} | ||
self.eventlog.record_event( | ||
schema_id='url.to.event.schema', | ||
version=1, | ||
event=event | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. _using-telemetry: | ||
|
||
Using telemetry in Jupyter applications | ||
======================================= | ||
|
||
Most people will use ``jupyter_telemetry`` to log events data from Jupyter applications, (e.g. JupyterLab, Jupyter Server, JupyterHub, etc). | ||
|
||
In this case, you'll be able to record events provided by schemas within those applications. To start, you'll need to configure each application's ``EventLog`` object. | ||
|
||
This usually means two things: | ||
|
||
1. Define a set of ``logging`` handlers (from Python's standard library) to tell telemetry where to send your event data (e.g. file, remote storage, etc.) | ||
2. List the names of events to collect and the properties/categories to collect from each of those events. (see the example below for more details). | ||
|
||
Here is an example of a Jupyter configuration file, e.g. ``jupyter_config.d``, that demonstrates how to configure an eventlog. | ||
|
||
.. code-block:: python | ||
from logging import FileHandler | ||
# Log events to a local file on disk. | ||
handler = FileHandler('events.txt') | ||
# Explicitly list the types of events | ||
# to record and what properties or what categories | ||
# of data to begin collecting. | ||
allowed_schemas = { | ||
"uri.to.schema": { | ||
"allowed_properties": ["name", "email"], | ||
"allowed_categories": ["category.jupyter.org/user-identifier"] | ||
} | ||
} | ||
c.EventLog.handlers = [handler] | ||
c.EventLog.allowed_schemas = allowed_schemas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.