Jump to content

Spark event log

From Open Lakehouse Wiki
Spark event log
Also known as Event log, eventLog
Field Monitoring and debugging
Key parts EventLoggingListener, JSON lines (one listener event per line), compression codec, rolling files, compaction
Open source implementations Apache Spark
Related Spark History Server, Spark UI, Spark listener
Last verified 23 November 2026 against the v4.3.0 tag of apache/spark (EventLoggingListener.scala, EventLogFileWriters.scala, config/package.scala, config/History.scala, docs/configuration.md, docs/monitoring.md, docs/core-migration-guide.md) and Spark JIRA SPARK-28594 and SPARK-45771.

The Spark event log is a file, or a directory of files, in which an Apache Spark application records the listener events that its driver posts for jobs, stages, tasks, executors and SQL query executions, so that the application's Spark UI can be rebuilt after it ends. Not every event is written: some are recorded only when a setting turns them on, events can opt out of logging, and spark.eventLog.excludedPatterns suppresses named events.[1] The Spark History Server reads event logs to show finished applications. Event logging is off by default and is turned on with spark.eventLog.enabled.[2]

What does the event log record?

The event log is written by EventLoggingListener, a Spark listener that the driver registers when event logging is on. Each event that it logs is serialized to JSON and written as one line; the first line records the Spark version.[1] The events include application start and end, job start and end, stage submission and completion, task start and end with task metrics, executors added and removed, environment updates, and SQL execution start and end with the query plans. These are the kinds of events that also build the live Spark UI.

Some events are left out by default. EventLoggingListener writes block updates and stage executor metrics only when their settings are on, writes events from other modules only if the event's logEvent flag is true, and the log writer drops any line that starts with a pattern listed in spark.eventLog.excludedPatterns:[1][3][2][4]

  • spark.eventLog.logBlockUpdates.enabled (default false) logs every block update. The documentation warns that this increases the size of the event log considerably.
  • spark.eventLog.logStageExecutorMetrics (default false) writes per-stage peaks of executor metrics.

Where is the event log written?

spark.eventLog.enabled  true
spark.eventLog.dir      hdfs://namenode/shared/spark-logs

spark.eventLog.dir defaults to /tmp/spark-events, a path on the driver's local file system, so on a cluster it is set to a shared location such as HDFS or object storage that the Spark History Server also reads.[2][1][5]

A single-file event log is named after the application ID and carries an .inprogress suffix until the application ends. A rolling event log is a directory named eventlog_v2_<appId> that holds numbered events_<index>_<appId> files and an appstatus_<appId> file, which also has the .inprogress suffix while the application runs.[3]

What changed in Spark 4.0?

Two event log defaults changed in Spark 4.0. The Spark migration guide says that since 4.0, Spark rolls event logs to archive them incrementally, and that it compresses event logs; setting spark.eventLog.rolling.enabled or spark.eventLog.compress to false restores the earlier behaviour.[6] The rolling default came from SPARK-45771.[7] Since Spark 3.2, the event log codec defaults to zstd and no longer falls back to spark.io.compression.codec.[6]

Setting Default in 4.3.0 Since
spark.eventLog.enabled false 1.0.0
spark.eventLog.dir /tmp/spark-events 1.0.0
spark.eventLog.compress true 1.0.0
spark.eventLog.compression.codec zstd 3.0.0
spark.eventLog.rolling.enabled true 3.0.0
spark.eventLog.rolling.maxFileSize 128m 3.0.0
spark.eventLog.excludedPatterns (none) 4.1.0

All values are from the Spark 4.3.0 source.[2]

Why do event logs get so large?

An event log grows with the number of tasks, because every task end event carries the task's metrics. Applications with many small tasks, long-running Structured Streaming queries that run a job for every micro-batch, and queries with very large plans produce the largest logs. A large single-file log is slow for the History Server to replay, because the whole file must be read to build the UI.[5]

Ways to keep event logs manageable:

  • Rolling. With spark.eventLog.rolling.enabled (on by default since 4.0), Spark starts a new file when the current one reaches spark.eventLog.rolling.maxFileSize (default 128m). Rolling was added for running streaming applications in Spark 3.0.0 (SPARK-28594).[2][8]
  • Compaction. Rolling alone does not reduce the total size. Setting spark.history.fs.eventLog.rolling.maxFilesToRetain on the History Server compacts older rolled files and drops events for finished jobs, terminated executors and finished SQL executions. The documentation describes compaction as lossy.[5][9]
  • Excluding events. spark.eventLog.excludedPatterns (since 4.1.0) takes a comma-separated list of event names that are not written.[4]
  • Leaving verbose events off, such as block updates.[4]
  • Retention. The History Server cleaner (spark.history.fs.cleaner.enabled, default false) deletes old logs.[9]

Reading an event log without the History Server

Because each line is a JSON object whose Event field names the event class (for example SparkListenerStageCompleted),[10] a compressed log can be decompressed and read with ordinary JSON tools. Spark itself can read one as a JSON data source, which is a quick way to find the slowest stages of a finished run:

events = spark.read.json("/tmp/spark-events/app-20261123120000-0000")
(events.filter("Event = 'SparkListenerStageCompleted'")
       .selectExpr("`Stage Info`.`Stage ID` AS stage",
                   "`Stage Info`.`Completion Time` - `Stage Info`.`Submission Time` AS ms")
       .orderBy("ms", ascending=False)
       .show(5))

The JSON format comes from Spark's JsonProtocol, an internal class whose source states that any version of Spark should be able to read event logs written by any other version, and that JSON fields are never deleted, only added as optional fields.[10] For tools, the REST API of the History Server or the live UI, at /api/v1, is the documented interface to the same data and has its own versioning policy.[5]

See also

References

  1. ↑ 1.0 1.1 1.2 1.3 EventLoggingListener.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  2. ↑ 2.0 2.1 2.2 2.3 2.4 config/package.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  3. ↑ 3.0 3.1 EventLogFileWriters.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  4. ↑ 4.0 4.1 4.2 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  5. ↑ 5.0 5.1 5.2 5.3 Monitoring and Instrumentation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  6. ↑ 6.0 6.1 Migration Guide: Spark Core (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  7. ↑ SPARK-45771: Enable spark.eventLog.rolling.enabled by default. Apache Software Foundation.Retrieved 2026-11-23.
  8. ↑ SPARK-28594: Allow event logs for running streaming apps to be rolled over. Apache Software Foundation.Retrieved 2026-11-23.
  9. ↑ 9.0 9.1 config/History.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  10. ↑ 10.0 10.1 JsonProtocol.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.