Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-47240

SPIP: Structured Logging Framework for Apache Spark

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.0.0
    • None
    • Spark Core

    Description

      This proposal aims to enhance Apache Spark's logging system by implementing structured logging. This transition will change the format of the default log files from plain text to JSON, making them more accessible and analyzable. The new logs will include crucial identifiers such as worker, executor, query, job, stage, and task IDs, thereby making the logs more informative and facilitating easier search and analysis.

      Current Logging Format

      The current format of Spark logs is plain text, which can be challenging to parse and analyze efficiently. An example of the current log format is as follows:

      23/11/29 17:53:44 ERROR BlockManagerMasterEndpoint: Fail to know the executor 289 is alive or not.
      org.apache.spark.SparkException: Exception thrown in awaitResult: 
          <stacktrace…>
      Caused by: org.apache.spark.rpc.RpcEndpointNotFoundException: ..
      

      Proposed Structured Logging Format

      The proposed change involves structuring the logs in JSON format, which organizes the log information into easily identifiable fields. Here is how the new structured log format would look:

      {
         "ts":"23/11/29 17:53:44",
         "level":"ERROR",
         "msg":"Fail to know the executor 289 is alive or not",
         "context":{
             "executor_id":"289"
         },
         "exception":{
            "class":"org.apache.spark.SparkException",
            "msg":"Exception thrown in awaitResult",
            "stackTrace":"..."
         },
         "source":"BlockManagerMasterEndpoint"
      } 

      This format will enable users to upload and directly query driver/executor/master/worker log files using Spark SQL for more effective problem-solving and analysis, such as tracking executor losses or identifying faulty tasks:

      spark.read.json("hdfs://hdfs_host/logs").createOrReplaceTempView("logs")
      /* To get all the executor lost logs */
      SELECT * FROM logs WHERE contains(message, 'Lost executor');
      /* To get all the distributed logs about executor 289 */
      SELECT * FROM logs WHERE executor_id = 289;
      /* To get all the errors on host 100.116.29.4 */
      SELECT * FROM logs WHERE host = "100.116.29.4" and log_level="ERROR";
      

       

      SPIP doc: https://docs.google.com/document/d/1rATVGmFLNVLmtxSpWrEceYm7d-ocgu8ofhryVs4g3XU/edit?usp=sharing

      Attachments

        1.
        Introduce Structured Logging Framework Sub-task Resolved Gengliang Wang Actions
        2.
        Implement logWarning API in structured logging framework Sub-task Resolved Gengliang Wang Actions
        3.
        Implement logInfo API in structured logging framework Sub-task Resolved Gengliang Wang Actions
        4.
        Spark core: Migrate logError with variables to structured logging framework Sub-task Resolved Gengliang Wang Actions
        5.
        Hive module: Migrate logInfo with variables to structured logging framework Sub-task Resolved Gengliang Wang Actions
        6.
        Hive-thriftserver: Migrate logError with variables to structured logging framework Sub-task Resolved Gengliang Wang Actions
        7.
        SQL catalyst: Migrate logError with variables to structured logging framework Sub-task Resolved Gengliang Wang Actions
        8.
        Add documentation for Structured logging framework Sub-task Resolved Gengliang Wang Actions
        9.
        Structured logging framework: support log concatenation Sub-task Resolved Gengliang Wang Actions
        10.
        Enable structured logging in log4j2.properties.template and update `configuration.md` Sub-task Resolved Gengliang Wang Actions
        11.
        Add scala style check for invalid MDC usage Sub-task Resolved Gengliang Wang Actions
        12.
        Guidelines for the Structured Logging Framework Sub-task Resolved Gengliang Wang Actions
        13.
        Use milliseconds as the time unit in loggings Sub-task Resolved Gengliang Wang Actions
        14.
        Store LogKey name as a value to avoid generating new string instances Sub-task Resolved Gengliang Wang Actions
        15.
        Provide a constant table schema for querying structured logs Sub-task Resolved Gengliang Wang Actions
        16.
        Improve the readability of JSON loggings Sub-task Resolved Gengliang Wang Actions
        17.
        Disable structured logging for Interpreter by default Sub-task Resolved Gengliang Wang Actions
        18.
        Provide options to enable structured logging for Interpreter Sub-task Open Gengliang Wang Actions
        19.
        Make spark.log.structuredLogging.enabled effective Sub-task Resolved Gengliang Wang Actions
        20.
        Provide a constant table schema in PySpark for querying structured logs Sub-task Resolved Gengliang Wang Actions
        21.
        Unify MDC key `mdc.taskName` and `task_name` Sub-task Resolved Gengliang Wang Actions
        22.
        Remove logDebug and logTrace with MDC in java structured logging framework Sub-task Resolved Gengliang Wang Actions
        23.
        Rename Java Logger as SparkLogger Sub-task Resolved Gengliang Wang Actions
        24.
        Change the scope of object LogKeys as private in Spark Sub-task Resolved Gengliang Wang Actions
        25.
        Log entry should be constructed only once Sub-task Resolved Gengliang Wang Actions
        26.
        Include SPARK_LOG_SCHEMA in the context of repl shell Sub-task Resolved Gengliang Wang Actions
        27.
        SQL core: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        28.
        SQL core: Migrate logInfo with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        29.
        Hive module: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        30.
        Connector module: Migrate logError with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        31.
        Connector module: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        32.
        Connector module: Migrate logInfo with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        33.
        Streaming: Migrate logError with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        34.
        Streaming: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        35.
        MLLib: Migrate logError with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        36.
        MLLib: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        37.
        Resource managers: Migrate logError with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        38.
        Resource managers: Migrate logWarn with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        39.
        Resource managers: Migrate logInfo with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        40.
        Improve `*LoggingSuite*` Sub-task Resolved Pan Bingkun Actions
        41.
        Introduce a tool that can sort alphabetically enumeration field in `LogEntry` automatically Sub-task Resolved Pan Bingkun Actions
        42.
        Make the value of MDC can support `null` Sub-task Resolved Pan Bingkun Actions
        43.
        Make the external Spark ecosystem can use structured logging mechanisms Sub-task Resolved Pan Bingkun Actions
        44.
        Implement the structured log framework on the java side Sub-task Resolved Pan Bingkun Actions
        45.
        Spark core (java side): Migrate `error/warn/info` with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        46.
        SQL (java side): Migrate `error/warn/info` with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        47.
        Common (java side): Migrate `error/warn/info` with variables to structured logging framework Sub-task Resolved Pan Bingkun Actions
        48.
        Ban import `org.slf4j.Logger` & `org.slf4j.LoggerFactory` Sub-task Resolved Pan Bingkun Actions
        49.
        Reorganize `LogKey` Sub-task Resolved Pan Bingkun Actions
        50.
        Add external third-party ecosystem access guide to the doc Sub-task Resolved Pan Bingkun Actions
        51.
        Migrate the remaining code to structured logging framework Sub-task Resolved Pan Bingkun Actions
        52.
        Spark core: Migrate logInfo with variables to structured logging framework Sub-task Resolved Anh Tuan Pham Actions
        53.
        Spark core: Migrate logWarn with variables to structured logging framework Sub-task Resolved Daniel Actions
        54.
        SQL catalyst: Migrate logWarn with variables to structured logging framework Sub-task Resolved Daniel Actions
        55.
        SQL catalyst: Migrate logInfo with variables to structured logging framework Sub-task Resolved Daniel Actions
        56.
        SQL core: Migrate logError with variables to structured logging framework Sub-task Resolved Daniel Actions
        57.
        Hive module: Migrate logError with variables to structured logging framework Sub-task Resolved Haejoon Lee Actions
        58.
        Hive-thriftserver: Migrate logWarn with variables to structured logging framework Sub-task Resolved Haejoon Lee Actions
        59.
        Hive-thriftserver: Migrate logInfo with variables to structured logging framework Sub-task Resolved Haejoon Lee Actions
        60.
        Streaming: Migrate logInfo with variables to structured logging framework Sub-task Resolved Daniel Actions
        61.
        MLLib: Migrate logInfo with variables to structured logging framework Sub-task Resolved Anh Tuan Pham Actions
        62.
        Graphx: Migrate logs with variables to structured logging framework Sub-task Resolved Haejoon Lee Actions
        63.
        Enable structured logging in all the test log4j2.properties Sub-task Open Unassigned Actions
        64.
        Create log4j templates for both structured logging and plain text logging Sub-task Resolved Unassigned Actions
        65.
        Improve user experience of loading logs as json data source Sub-task Resolved Unassigned Actions
        66.
        Support `three` methods of the log `concatenation` in the `structured logging framework` Sub-task Open Unassigned Actions
        67.
        Sort LogKey alphabetically Sub-task Resolved Daniel Actions
        68.
        RPackageUtils: Migrate logInfo/logWarn/logError with variables to structured logging framework Sub-task Open Unassigned Actions
        69.
        Add scala style check for logging message inline variables Sub-task Resolved Amanda Liu Actions
        70.
        Structured Logging Framework Scala Style Migration Sub-task Resolved Amanda Liu Actions
        71.
        Remove unused LogKeys Sub-task Resolved Unassigned Actions
        72.
        Structured Logging Framework Scala Style Migration [Part 2] Sub-task Open Unassigned Actions
        73.
        Add Streaming related fields to log4j ThreadContext Sub-task Resolved Wei Liu Actions
        74.
        Fix to not log message context with explicitly LogEntry constructed when Structured Logging conf is off Sub-task Resolved Xinyi Yu Actions
        75.
        Fix incorrect logkeys Sub-task Resolved Michael Zhang Actions

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            Gengliang.Wang Gengliang Wang

            Dates

              Created:
              Updated:

              Slack

                Issue deployment