Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

notebook-metrics

A JupyterLab/JupyterLite extension for Jupyter UI metrics.

If you are integrating the package for the first time, start with the onboarding guide.

Usage

This package contains four Jupyter extensions.

Jupyter server extension

The Jupyter server extension, notebook_metrics registers event schemas for four types of metrics events:

  1. CommandExecuted events (anonymous: false, sensitivity: "high"), which are emitted every time the command registry executes a command
  2. CurrentChanged events (anonymous: false, sensitivity: "high"), which are emitted every time a non-null new value is emitted by the application shell's currentChanged signal
  3. JupyterError events (anonymous: false, sensitivity: "high"), which are emitted every time notebook cell execution fails with a Jupyter error
  4. RuntimeError events (anonymous: false, sensitivity: "high"), which are emitted every time an error or unhandledpromiserejection listener on the application window is invoked

JupyterLab/JupyterLite dispatcher extension

The front-end dispatcher extension listens for registered events and dispatches them based on filter and user settings to a collector extension. It also provides a single API point of entry, a function called register(...), which registers an event schema URL and an optional broadcast source that emits metrics events for dispatch. In cases where no broadcast is necessary (e.g., where a UI component automatically emits metrics events), the source argument can be omitted.

JupyterLab/JupyterLite collector extension

The collector extension is the client that receives metrics emissions. The default implementation is a no-op and in production, the extension notebook-metrics:collector needs to be disabled and replaced with a custom extension that provides an IMetrics.ICollector for the dispatcher extension to use. The interface for a collector is minimal:

interface ICollector {
  collect: (schema: string, event: IMetrics.Event) => Promise<void>;
}

An extension that replaces the default no-op collector would have this shape:

const collector: JupyterFrontEndPlugin<IMetrics.ICollector> = {
  id: 'my-collector-extension',
  description: 'A collector for metrics emissions',
  provides: IMetrics.ICollector,
  activate: (): IMetrics.ICollector => ({
    collect: async (schema: string, event: IMetrics.Event) => {
      // Save emission here...
    }
  })
};

JupyterLab/JupyterLite broadcasts extension

This frontend extension registers the four metrics event types that ship with this package.

Configuration

This plugin can be configured in two ways to allow a user to disable or limit emissions: the JupyterLab user settings system or using the JupyterLab PageConfig object.

There are several ways to populate PageConfig, (which is an object literal loaded in the HTML page that hosts JupyterLab). As a convenience for JupyterLab deployment, this package supports setting a path to a YAML file as an environment variable, NOTEBOOK_METRICS_OVERRIDE.

The contents of an override file are the same keys that exist in the user settings (dispatcher.json) and if set, they always take precedence over user settings.

Here is an example override file for the most permissive emission settings:

anonymous: false
disabled: false
excluded:
  'https://schema.notebook.link/metrics/command-executed/v1': false
  'https://schema.notebook.link/metrics/current-changed/v1': false
  'https://schema.notebook.link/metrics/jupyter-error/v1': false
  'https://schema.notebook.link/metrics/runtime-error/v1': false
sensitivity: high

Requirements

  • Python >= 3.9
  • JupyterLab >= 4.0.0,<5

Install

python -m pip install notebook-metrics

Uninstall

To remove the extension, execute:

python -m pip uninstall notebook-metrics

Contributing

Development install

Note: You will need Node.js 24.x to build the extension package and run the frontend tooling.

This repo uses jlpm, JupyterLab's pinned Yarn wrapper.

# Clone the repo to your local environment
# Change directory to the metrics directory
# Install package in development mode
python -m pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm build

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Development uninstall

python -m pip uninstall notebook-metrics

In development mode, you will also need to remove the symlink created by jupyter labextension develop command. To find its location, you can run jupyter labextension list to figure out where the labextensions folder is located. Then you can remove the symlink named notebook-metrics within that folder.

Testing the extension

Python tests

Install the editable package with test extras, then run:

python -m pip install -e ".[test]"
pytest -vv -r ap --cov notebook_metrics

Frontend tests

This extension is using Jest for JavaScript code testing.

To execute them, execute:

jlpm install
jlpm test

Integration tests

This extension uses Playwright for the integration tests (aka user level tests). More precisely, the JupyterLab helper Galata is used to handle testing the extension in JupyterLab.

More information are provided within the ui-tests README.

The local flow that is currently validated in this repo is:

jlpm build:prod
cd ui-tests
jlpm install
jlpm playwright install
PLAYWRIGHT_HTML_OPEN=never jlpm playwright test
cd ..

Packaging the extension

See RELEASE

Metadata

Release files for notebook-metrics 1.0.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notebook-metrics 1.0.0a1
File Size Uploaded
notebook_metrics-1.0.0a1.tar.gz 228.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notebook-metrics 1.0.0a1
File Interpreter ABI Platform
notebook_metrics-1.0.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 268.1 kB

Release files / notebook_metrics-1.0.0a1.tar.gz

Download URL notebook_metrics-1.0.0a1.tar.gz
Size 228.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c779b1998e4320f72251168cc52b30cb5cd85552482d68568e078e002300659d
BLAKE2b-256 checksum
How to use checksums
cda0f5df622bc5b5a784a8252bbfb28632b0317fa2438b259c80878df823de09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / notebook_metrics-1.0.0a1-py3-none-any.whl

Download URL notebook_metrics-1.0.0a1-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
755c54aaca475f7111c6b1006c5890059229366b5c9c61e31baa91b26e737bb7
BLAKE2b-256 checksum
How to use checksums
266c4aae45c19a0cd1eceea22c3469dc8c7a9396f8bd71d7597c22cfe832906d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.0.0a1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page