Notebooks

Static analysis of the code of Fabric notebooks: findings by cell and line, severity, confidence, official source, CU consumption, run duration, Spark queue and schedule.

The Notebooks screen, in the Performance menu, shows the code findings of the Microsoft Fabric notebooks: patterns in PySpark, Spark SQL, Scala and R that usually make the run slower or more expensive, such as pulling data into the driver, row by row loops, Python UDFs without Arrow, single partition writes, cartesian products, installing libraries in the notebook itself and %run chains. Each finding points to the cell and line, the severity, the confidence, the recommended action and the official source. Alongside, the screen shows the Capacity Units (CU) consumption of the last 7 days, the run duration and the average Spark queue time.

How to access: Performance › Notebooks. The screen is read-only and available to all profiles, within each user's workspace scope; in the Audit profile it is blocked by default and can be unblocked in Users. Click the name of a notebook to open the Notebook detail. Running the analysis is managed by administrators in Mapping › Code analysis.

The analysis is static: Power Monitor reads the notebook definition already collected and looks for patterns in the code, without running the notebook and without querying the data. No code excerpt is shown on this screen: each finding shows only the rule, the cell and the line. To read the code cell by cell, with the findings marked, use the Code tab in Governance › Data Engineering.

What it is for

  • Reduce capacity consumption: find the notebooks that spend the most CU and have high severity findings.
  • Diagnose slow notebooks: see whether the time goes to work outside Spark (driver, Python loops, sleep), to poorly distributed writes or to waiting in the Spark queue.
  • Standardize development: use the rules as a code review checklist (libraries in Environments, declared schema, parameterized OneLake paths).
  • Track progress: the Seen since column shows how long each issue has existed, and the finding leaves the list when the code is fixed.

Screen components

The Notebooks screen follows the same design as the Dataflows screen: Code analysis line with the last run (and the View/manage collection → link for administrators), Analysis coverage card (Analyzed, With findings, Not analyzable and Pending), filters and paginated list. The differences are described below.

Filters

Filter Options
Search Part of the notebook name
Workspace All workspaces or a workspace in your scope
Analysis status All, Analyzed, With findings, Pending or Not analyzable
Minimum severity Any (no filter), Critical, High or above, Medium or above, Low or above or Any finding
Sort by Severity, Name or Most recent analysis

Clear filters resets everything to the default, keeping the sort.

Notebook list

Column Content
Notebook Name, with a link to the detail
Workspace Notebook workspace
Findings Count by severity; No findings or Not counted (not analyzed yet or not analyzable); {n} at runtime badge for rules decided by the schedule or the run chain
CU in 7 days CU consumed in the last 7 complete days and the share of the capacity
p95 duration Run duration at the 95th percentile, with the source badge (Job runs, Spark sessions, Estimate or No source)
Average Spark queue Average wait time of the notebook's Spark sessions and the number of sessions
Analysis Analysis status and the Partial coverage, Re-analysis pending or Definition read failed badges

Missing values appear as No data, never as zero.

Notebook detail

What it is: the page opened from the notebook name (Code findings by cell, evaluated rules, consumption and runs.), with Back to Notebooks and Refresh.

Detail header: analysis status, findings by severity, Analyzed at, Definition captured at, Rule catalog version and the facts: Cells, Code cells and Markdown cells always; Python, SQL, Scala, R and T-SQL cell counts, display calls, %run executions and notebook.run calls when there are any. If the notebook is synced with Git, a note says Definition read in the Git format (.py, .sql, .scala or .r).

Findings tab:

  • Code findings: columns Rule (title, identifier, description and recommended action), Severity, Confidence (with the Heuristic badge), Cell and line, Seen since and Source. The cell is shown as Cell N and the line is counted within the cell. Cell numbering also counts markdown cells, as in Fabric. A finding that applies to the whole notebook appears as Whole item.
  • Runtime findings (Rules decided now from the Fabric schedule and the reference run chain, not only from the code.): here the cell also appears, for example the one with the first display() of a scheduled notebook.

Evaluated rules tab: the result of each catalog rule, with Type, Result (Triggered, Not triggered or Not evaluated), Reason and Sources, as in the Dataflows screen.

Consumption tab: last 7 complete days, from Capacity Metrics: Total CU, Interactive CU, Background CU, Share of the capacity, Daily average, Daily peak, Throttling and Operations.

Runs tab: three cards:

Card Content
Runs Samples, Average, p50 and p95 of the duration over the last 30 days, with the labeled source
Spark queue Average queue and number of Sessions over the last 30 days
Schedule Scheduled (there is an enabled schedule in Fabric), Not scheduled (only paused schedules, or none) or Schedule unknown (the schedule collection did not run or could not read the workspace; the rules that depend on the schedule stay not evaluated)

Analyzed rules

Rule Language What is checked
Data pulled into the driver (heuristic) Python, Scala .collect(), .toPandas() or .collectAsList() without a .limit() before and without aggregation
Row by row loop on the driver (heuristic) Python, Scala Loop over .collect(), toLocalIterator(), iterrows() or itertuples()
Python UDF without Arrow (heuristic) Python Regular Python UDF (@udf, udf(), spark.udf.register); pandas_udf, useArrow=True or Arrow enabled in the session do not count
Cache never released (heuristic, low confidence) All .cache(), .persist() or CACHE TABLE with no release (unpersist, UNCACHE TABLE etc.) in the notebook
Single partition write Python, Scala coalesce(1) or repartition(1) followed by a write
Schema inference on read All inferSchema option on when reading
Explicit cartesian product All crossJoin, join with how="cross" or CROSS JOIN in SQL
Library installed in the notebook Python, R %pip, !pip, %conda install or install.packages()
Waiting with sleep inside a loop (heuristic, low confidence) Python, Scala sleep inside a while or for
Notebooks run in sequence (heuristic) Python Two or more calls to notebookutils.notebook.run() (or mssparkutils), or one inside a loop (Power-Monitor threshold)
OneLake path hardcoded in the code All abfss://...onelake.dfs.fabric.microsoft.com path written literally in the code
Data display in a scheduled notebook (heuristic) Python, Scala Runtime rule: display() or .show() in a notebook with an enabled schedule in Fabric
Deep reference run chain All Runtime rule: chain of %run or notebook.run deeper than 3 levels (Power-Monitor threshold; Fabric fails above 5)

Rules and behavior

  • Where the code comes from: each notebook's definition (Fabric format or Git format) is collected once a day by the Notebook, pipeline and dataflow dependencies collection, which needs the Service Principal with write permission (Contributor or higher) on the workspaces. When the collection finishes, the analysis runs automatically. See Mapping › Code analysis.
  • What is analyzed: code cells in Python (PySpark), SQL, Scala, R and T-SQL. Markdown cells and cells with other magic commands (such as %%configure or %%html) are not analyzed, but they count in the cell numbering.
  • Status, partial coverage, re-analysis pending and definition read failed: same rules as in the Dataflows screen. Coverage is partial, for example, when the notebook exceeds the read limits (2,000 cells or 1 million characters) or when a cell exceeds the analyzer time limit; in that case, the rules that depend on the whole notebook (such as cache never released) stay Not evaluated instead of risking a false result.
  • Duration: last 30 days, with at least 5 runs. The preferred source is the job run history (Job runs). When the notebook is run by a Service Principal and there is no job run, Power Monitor uses the duration of the successful Spark sessions (Spark sessions); lastly, the Capacity Metrics estimate (Estimate).
  • Spark queue: average wait time of the Spark sessions that report it, collected by Spark Sessions.
  • Run chain: only considers notebooks in the same workspace. When the %run target is built at run time or has not been mapped yet, the rule stays Not evaluated (Signal missing from the definition).
  • Seen since: changing lines inside the cell does not reset the date; inserting a cell above changes the numbering and makes the finding count as new.
  • Pattern-based detection: the rules recognize patterns in the code text, they do not run Python. Unusual code may produce a false positive or fail to trigger: the rules with that risk are marked as heuristic.

Step by step: finding the notebook most worth optimizing

  1. Open the screen

    Go to Performance › Notebooks and check on the Code analysis line that the last run is recent.

  2. Filter the serious findings

    In Minimum severity, choose High or above and, in Sort by, Severity.

  3. Cross with consumption and the queue

    Compare CU in 7 days, p95 duration and Average Spark queue. A high queue indicates contention for Spark resources on the capacity, which the code alone does not solve.

  4. Open the detail and go to the cell

    In the detail, the Findings tab shows the cell and line of each issue. To read the excerpt, open the notebook in Fabric or use the Code tab in Governance › Data and Engineering › Data Engineering.

  5. Fix and check

    After publishing the fix, wait for the next daily collection (or ask an administrator to run the analysis). The fixed finding leaves the list.

Frequently asked questions

The "Data display in a scheduled notebook" rule shows as Not evaluated.

It depends on the notebook schedule in Fabric. If the schedule collection could not read the workspace, the schedule is Schedule unknown and the rule is not evaluated, instead of claiming there is no problem.

Why does the cell numbering not match my editor?

The numbering counts all cells, including markdown cells, as Fabric does. The line is counted from the first line with content in the cell.

Is the notebook code shown or sent to AI?

Not on this screen: findings show only the rule, the cell and the line, and the code is not sent to AI. The code can only be read in the Code tab of the notebook detail in Data Engineering, with credentials masked.

Last updated