Skip to content

Commit c307a8d

Browse files
committed
Add docs on registering client events
1 parent 8179c47 commit c307a8d

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

docs/source/operators/telemetry.rst

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Notebook Server can be configured to record structured events from a running
1111
.. warning::
1212
Do NOT rely on this feature for security or auditing purposes. Neither `server <#emitting-server-events>`_ nor `client <#eventlog-endpoint>`_ events are protected against meddling. For server events, those who have access to the environment can change the server code to emit whatever they want. The same goes for client events where nothing prevents users from sending spurious data to the `eventlog` endpoint.
1313

14-
Emitting Server Events
14+
Emitting server events
1515
----------------------
1616

1717
Event logging is handled by its ``Eventlog`` object. This leverages Python's standing logging_ library to emit, filter, and collect event data.
@@ -37,8 +37,16 @@ Here's a basic example for emitting events from the `contents` service:
3737
3838
The output is a file, ``"event.log"``, with events recorded as JSON data.
3939

40-
`eventlog` endpoint
41-
-------------------
40+
Server event schemas
41+
--------------------
42+
43+
.. toctree::
44+
:maxdepth: 2
45+
46+
events/index
47+
48+
The ``eventlog`` endpoint
49+
-------------------------
4250

4351
The Notebook Server provides a public REST endpoint for external applications to validate and log events
4452
through the Server's Event Log.
@@ -54,11 +62,37 @@ Events that are validated by this endpoint must have their schema listed in the
5462

5563
.. _below:
5664

65+
Register client event schemas
66+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5767

58-
Server Event schemas
59-
--------------------
68+
``jupyter_server`` looks for locations of schema files provided by external packages by looking into the ``jupyter_telemetry`` entry point and then loads the files using the ``importlib.resources`` standard library.
6069

61-
.. toctree::
62-
:maxdepth: 2
70+
For example, suppose there is a ``client_events`` package which wants to send events with schemas ``schema1.yaml``, ``schema2.yaml`` and ``extra_schema.yaml`` to the ``eventlog`` endpoint and has the following package structure:
6371

64-
events/index
72+
.. code-block:: text
73+
74+
client_events/
75+
__init__.py
76+
schemas/
77+
__init__.py
78+
schema1.yaml
79+
schema2.yaml
80+
extras/
81+
__init__.py
82+
extra_schema.yaml
83+
84+
``schema1.yaml`` and ``schema2.yaml`` are resources under ``client_events.schemas`` and ``extra_schema.yaml`` under ``client_events.extras``. To make these schemas discoverable by ``jupyter_server``, create an entry point under the ``jupyter_telemetry`` group which resolves to a list containing their locations, in this case ``['client_events.schemas', 'client_events.extras']``:
85+
86+
In :file:`setup.cfg`
87+
88+
.. code-block:: yaml
89+
90+
[options.entry_points]
91+
jupyter_telemetry =
92+
my-event-entry-point = client_events:JUPYTER_TELEMETRY_SCHEMAS
93+
94+
In :file:`client_events/__init__.py`
95+
96+
.. code-block:: python
97+
98+
JUPYTER_TELEMETRY_SCHEMAS = ['client_events.schemas', 'client_events.extras']

0 commit comments

Comments
 (0)