The Practitioner’s Ultimate Guide to Scalable Logging
Standardize and structure production logging for Spark jobs on Databricks, and get more out of your logs by centralizing cluster logs for ingestion and analysis.
by Zach King
Introduction: Logging Matters, Here’s Why
Scaling from a few dozen jobs to hundreds is challenging for several reasons, one of which is observability. Observability is the ability to understand the system by analyzing components such as logs, metrics, and traces. This is just as relevant for smaller data teams with only a few pipelines to monitor, and distributed computing engines like Spark can be challenging to reliably monitor, debug, and create mature escalation procedures.
Logging is arguably the simplest and most impactful of these observability components. Clicking and scrolling through logs, one job run at a time, is not scalable. It can be time-consuming, difficult to parse, and often requires subject-matter expertise of the workflow. Without building mature logging standards into your data pipelines, troubleshooting errors or job failures takes significantly longer, leading to costly outages, ineffective tiers of escalation, and alert fatigue.
In this blog, we’ll walk you through:
- Steps to break away from basic print statements and set up a proper logging framework.
- When to configure the Spark log4j logs to use JSON format.
- Why centralize cluster log storage for easy parsing and querying.
- How to create a central AI/BI dashboard in Databricks that you can set up in your own workspace for more customized log analysis.
Key Architectural Considerations
The following considerations are important to keep in mind to tailor these logging recommendations to your organization:
Logging Libraries
- Several logging libraries exist for both Python and Scala. Our examples use Log4j and the standard Python logging module.
- Configuration for logging libraries or frameworks will be different, and you should consult their respective documentation if using a non-standard tool.
Cluster Types
- Examples in this blog will focus primarily on the following compute:
- At the time of this writing, the following compute types have less support for log delivery, although recommendations for logging frameworks still apply:
- Lakeflow Declarative Pipelines (formerly DLT): Only supports event logs
- Serverless Jobs: Does not support log delivery
- Serverless Notebooks: Does not support log delivery
Data Governance
- Data governance should extend to cluster logs, as logs may accidentally expose sensitive data. For example, when you write logs to a table, you should consider which users have access to the table and utilize least privilege access design.
- We will demonstrate how to deliver cluster logs to Unity Catalog volumes for simpler access control and lineage. Log delivery to Volumes is in Public Preview and is only supported on Unity Catalog-enabled compute with Standard access mode or Dedicated access mode assigned to a user.
- This feature is not supported on compute with Dedicated access mode assigned to a group.
Technical Solution Breakdown