Managed Spark Cell Monitoring (managed-spark-cell-monitoring)
Managed Spark Cell Monitoring is a Jupyter kernel extension designed to monitor Apache Spark jobs directly from your notebook cells in real time.
Leveraging AnyWidget, it enables platform-agnostic, zero-installation frontend rendering across JupyterLab, Jupyter Classic, Colab Enterprise, and VS Code notebooks.
Key Features
- 📊 Real-time Progress Tracking: Visual progress bars for active Apache Spark jobs and their tasks directly in notebook cells.
- ⚡ AnyWidget Architecture: Precompiled ESM widgets rendered natively without requiring custom JupyterLab extension binaries.
- ⏱️ Task Chart: Live chart of running and scheduled tasks against available executor cores.
Architecture Overview
- Classic PySpark Mode:
- Scala Listener (
scalalistener): Plugs into the Apache Spark driver'sSparkListenerbus to capture fine-grained task and stage metrics with lock-free queueing and delta-change metric caching. - Python Kernel Extension (
managed_spark_cell_monitoring.kernelextension): Intercepts cell execution hooks (pre_run_cell,post_run_cell) and routes telemetry events to active widget instances via Jupyter Comms.
- Scala Listener (
- Spark Connect Snapshot Mode:
- Python Controller & Poller (
managed_spark_cell_monitoring.spark_connect): Tracks the active notebook cell across worker threads (contextvars), pollsGetStatusforCellMonitorTelemetryprotobuf extensions, and reconciles terminal snapshots per operation. - Automatic Fallback: If a Spark Connect server does not implement
GetStatus(UNIMPLEMENTED) or omitsCellMonitorTelemetryon task-bearing operations, the poller falls back cleanly for that session without disrupting execution.
- Python Controller & Poller (
- AnyWidget React Frontend (
managed_spark_cell_monitoring/static/widget.js): Modular React 18 / MobX frontend compiled viaesbuild, providing isolated UI components for the job table, header summary, and task chart in both classic event-stream mode and Spark Connect snapshot mode.
Installation & Usage
1. Installation
Install the pre-built package from PyPI (no Node.js, Yarn, Java, or SBT required on client machines):
# Classic PySpark notebooks
pip install managed-spark-cell-monitoring
# With Spark Connect polling dependencies (grpcio, protobuf)
pip install "managed-spark-cell-monitoring[connect]"
2. Enable in Notebook
In your IPython environment or notebook cell, load the kernel extension:
%load_ext managed_spark_cell_monitoring
Alternatively, configure it to load automatically in all notebook sessions by adding it to your IPython configuration (e.g. ~/.ipython/profile_default/ipython_kernel_config.py):
c.InteractiveShellApp.extensions.append('managed_spark_cell_monitoring')
3. Configure PySpark Session
Create your Apache Spark SparkSession with the extra configurations to activate the Scala Listener. Use managed_spark_cell_monitoring.get_jar_path(...) to automatically resolve the bundled listener JAR. Pass "3" for Apache Spark 3.5 or "4" for Apache Spark 4.x:
import managed_spark_cell_monitoring
from pyspark.sql import SparkSession
# Specify your target major Apache Spark version:
# • Pass "3" for Apache Spark 3.5 (e.g., Google Cloud Dataproc 2.2)
# • Pass "4" for Apache Spark 4.x
spark_major_version = "3" # Change to "4" for Apache Spark 4.x clusters
# Automatically resolves the bundled listener JAR inside site-packages
jar_path = managed_spark_cell_monitoring.get_jar_path(spark_major_version)
spark = (
SparkSession.builder
.config(
'spark.extraListeners',
'managed_spark_cell_monitoring.listener.JupyterManagedSparkCellMonitoringListener',
)
.config('spark.driver.extraClassPath', jar_path)
.getOrCreate()
)
4. Spark Connect Usage & Toggling
For remote Spark Connect sessions (such as Google Cloud Managed Spark Serverless via google-cloud-spark-connect), load the Spark Connect IPython extension or let your client session call get_spark_connect_controller().ensure_current_shell_attached() and create a CellMonitorPoller via create_session_poller(client, ...):
%load_ext managed_spark_cell_monitoring.spark_connect
You can also toggle in-cell monitoring at runtime in either mode using the line magic or environment variable:
%cellmonitor status # or on / off
Setting MANAGED_SPARK_CELL_MONITORING_ENABLED=0 (or false, off, no) starts the kernel with monitoring disabled.
Spark Connect Notes & Differences vs. Classic PySpark
- Server Requirement & Fallback: Snapshot mode requires a Spark Connect server that exposes
CellMonitorTelemetryinGetStatusResponseextensions. Servers without that support trigger automatic per-session fallback (on_fallback) so built-in progress reporting can take over. - Lazy Widget Display: In Spark Connect mode, a cell widget is displayed only after at least one Spark job is observed for the cell; pure-Python cells and jobless SQL/DDL operations leave no empty widget behind.
- Per-Operation Snapshots: Telemetry is aggregated and deduplicated per
(operation_id, version)overGetStatusRPCs rather than streamed over a local driver socket, so Spark driver JAR configuration (get_jar_path/spark.extraListeners) is not required on the notebook kernel. - Live Kernel Requirement: As in Classic PySpark mode, job and task snapshots are synced over live Jupyter Comms rather than stored in widget traitlets, so saved
.ipynbfiles reopened after a kernel shutdown or restart render blank widget state until cells are re-executed. - Per-Cell Toggling Scope: Calling
%cellmonitor off/set_enabled(False)mid-cell freezes any active widget in that cell (takes effect from the next cell), and togglingoff -> onwithin the same cell does not monitor subsequent statements until the next cell runs; avoid turning monitoring off inside a cell whose Spark operations you still want tracked.
Development & Building
Prerequisites
- Node.js (>= 18.0) & Yarn
- Java JDK (8, 11, or 17) & SBT
- Python (>= 3.10)
Building from Source
1. React UI Frontend
The frontend uses React 18 and MobX, bundled via esbuild into standalone assets in managed_spark_cell_monitoring/static/.
# Install frontend dependencies
yarn --cwd js install
# Bundle frontend assets into static/widget.js and static/widget.css
yarn --cwd js build
# Run frontend tests and linter
yarn --cwd js test
yarn --cwd js lint
2. Scala Listener Fat JARs
The Scala listener is compiled using sbt and supports Apache Spark 3.5 (Scala 2.12) and Apache Spark 4.x (Scala 2.13). We use sbt-assembly to build shaded Fat JARs directly into managed_spark_cell_monitoring/static/listeners/.
# Run Scala unit tests
cd scala && sbt test && cd ..
# Build shaded Fat JARs for Apache Spark 3.5 and Apache Spark 4.x
cd scala && sbt assembly && cd ..
3. Python Kernel Package
Install in editable mode and run Python test suites:
# Install package in editable mode with test dependencies
pip install -e ".[test]"
# Run Python unit tests
pytest tests/
# Build distribution wheel (.whl) and source archive (.tar.gz)
python -m build
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Trademarks
Apache®, Apache Spark™, Spark™, and the Apache feather logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries.
Metadata
Release files for managed-spark-cell-monitoring 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| managed_spark_cell_monitoring-1.1.0.tar.gz | 6.7 MB | With provenance | Details for managed_spark_cell_monitoring-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| managed_spark_cell_monitoring-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for managed_spark_cell_monitoring-1.1.0-py3-none-any.whl |
Total release size: 13.2 MB
Release files / managed_spark_cell_monitoring-1.1.0.tar.gz
| Download URL | managed_spark_cell_monitoring-1.1.0.tar.gz |
|---|---|
| Size | 6.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14d87bfd5aa6e56ca2b16d9119376ac70a0c8257aa0b7df50d26733b0fc5db41
|
|
BLAKE2b-256 checksum How to use checksums |
df9cbc3aa6463d5c6b189c256262a8012bff1422625384c6c2de8588faf43cd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / managed_spark_cell_monitoring-1.1.0-py3-none-any.whl
| Download URL | managed_spark_cell_monitoring-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e04dcae33ce8e608d949e3233986b956d5c2239e0db68dd988f9d736f0520ce
|
|
BLAKE2b-256 checksum How to use checksums |
14c9ffe3329dfe1c9a909c1341b6ffeecb89a57ebf7eac3bf0e63ff79e3bed73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Dec 2, 2026.
Transparency logSecurity for managed-spark-cell-monitoring 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for managed_spark_cell_monitoring-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Dec 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.