{
  "name": "Log n8n workflow errors to your REST API with Slack alerts and metrics",
  "nodes": [
    {
      "id": "0debcd19-b472-4bfc-a0eb-504b393ba141",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1984,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "ff361afc-8d33-4759-a80e-456ebf666d65",
      "name": "Error capture",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "e3a6f31e-0bef-434e-a5b7-ee10bf22a379",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -1488,
        -912
      ]
    },
    {
      "id": "fa9e150a-15a0-4233-9aeb-cb4de35441b8",
      "name": "Extract Metadata",
      "type": "n8n-nodes-base.code",
      "position": [
        -1248,
        -912
      ]
    },
    {
      "id": "afe44e8a-f410-4f08-866d-ed5ff9210bde",
      "name": "Extract Environment",
      "type": "n8n-nodes-base.code",
      "position": [
        -1008,
        -912
      ]
    },
    {
      "id": "14b98347-1873-4a44-a75a-ede2b179e14f",
      "name": "Error classification",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "d2658460-93aa-443a-9b1c-411ce25a195f",
      "name": "Classify Error",
      "type": "n8n-nodes-base.code",
      "position": [
        -736,
        -912
      ]
    },
    {
      "id": "3ff6e953-f07d-4726-b5e8-51b3f30f37c3",
      "name": "Generate Error Hash",
      "type": "n8n-nodes-base.code",
      "position": [
        -496,
        -912
      ]
    },
    {
      "id": "5bef2682-4b61-4aac-a5af-3ca30b69d886",
      "name": "API - Check Duplicate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -256,
        -912
      ]
    },
    {
      "id": "b68f0644-af1c-4da5-9316-665b1d793379",
      "name": "Is New Error?",
      "type": "n8n-nodes-base.if",
      "position": [
        -16,
        -912
      ]
    },
    {
      "id": "ec0a3883-a243-4097-aacf-4dba3078df1f",
      "name": "Log storage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "c4e7ae46-d15e-4613-a1cd-b199ea05d8f4",
      "name": "Format Log Entry",
      "type": "n8n-nodes-base.code",
      "position": [
        256,
        -912
      ]
    },
    {
      "id": "5150c3e6-0d68-4a36-80f3-3b22f749acac",
      "name": "API - Save Log",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        496,
        -912
      ]
    },
    {
      "id": "7637a27e-9085-4a24-a367-12f125d4a1e8",
      "name": "Alert routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "39594a0c-eff8-487d-b391-a3cf5d2237ce",
      "name": "Alert Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        768,
        -912
      ]
    },
    {
      "id": "53582f91-3781-459f-b751-6246e051aa26",
      "name": "Critical alerts",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "492701fb-b3fb-4d3b-ba95-f1c8f0025d07",
      "name": "Format Critical Alert",
      "type": "n8n-nodes-base.code",
      "position": [
        1280,
        -912
      ]
    },
    {
      "id": "dc0f1c03-b7a2-4250-9b6f-44b40fbfb4ca",
      "name": "Slack - Critical Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        1520,
        -912
      ]
    },
    {
      "id": "4016f4bb-7104-46f9-a2ee-552311f62dcf",
      "name": "Format Warning Alert",
      "type": "n8n-nodes-base.code",
      "position": [
        1280,
        -720
      ]
    },
    {
      "id": "5f76cf42-3f16-4ab9-a139-41093d6dd3b1",
      "name": "Slack - Warning Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        1520,
        -720
      ]
    },
    {
      "id": "4893b1a0-92f8-4f98-b3ba-e6bde075c36e",
      "name": "No Alert Needed",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1280,
        -528
      ]
    },
    {
      "id": "14ffa09d-8ead-4f7a-a43b-46b2a013fe25",
      "name": "Performance metrics",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1840,
        -1008
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "c12a1628-1956-464a-b088-e6e55f02582f",
      "name": "Calculate Metrics",
      "type": "n8n-nodes-base.code",
      "position": [
        1872,
        -912
      ]
    },
    {
      "id": "9d52ac44-d618-4788-82c2-4617cb91b1a9",
      "name": "API - Save Metrics",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2112,
        -912
      ]
    },
    {
      "id": "0bf5d092-2512-4b13-ac1b-c97320ea1eb3",
      "name": "Prepare Aggregate",
      "type": "n8n-nodes-base.code",
      "position": [
        2112,
        -720
      ]
    },
    {
      "id": "1799d039-09f1-4f7e-b31f-5501cb2a1af9",
      "name": "API - Update Aggregate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2352,
        -720
      ]
    },
    {
      "id": "9ce94f87-4eee-46b2-84ec-2ed7a558d7c4",
      "name": "Retention policy",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1840,
        -368
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "9b2fa15f-46df-4f2b-96d8-2a8c5ce007d7",
      "name": "Calculate Retention",
      "type": "n8n-nodes-base.code",
      "position": [
        1872,
        -256
      ]
    },
    {
      "id": "8770d580-60f4-49e7-a0db-6381c8d55544",
      "name": "API - Cleanup Old Logs",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2112,
        -256
      ]
    },
    {
      "id": "e43d973c-1d07-4273-979e-738dc178e295",
      "name": "Fallback logging",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1984,
        80
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "c589fa39-62d4-484d-864d-77d04bbebc00",
      "name": "Format Logger Error",
      "type": "n8n-nodes-base.code",
      "position": [
        -1712,
        192
      ]
    },
    {
      "id": "fa18fae8-dd04-470b-8b62-5ffa44040fd0",
      "name": "Slack - Logger Error",
      "type": "n8n-nodes-base.slack",
      "position": [
        -1472,
        192
      ]
    },
    {
      "id": "7d112f29-7a60-440b-b2c7-f23cb5c9af08",
      "name": "Skip Duplicate",
      "type": "n8n-nodes-base.noOp",
      "position": [
        224,
        -720
      ]
    }
  ],
  "connections": {
    "Alert Router": {
      "main": [
        [
          {
            "node": "Format Critical Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Warning Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Alert Needed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Extract Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is New Error?": {
      "main": [
        [
          {
            "node": "Format Log Entry",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Skip Duplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API - Save Log": {
      "main": [
        [
          {
            "node": "Alert Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Error": {
      "main": [
        [
          {
            "node": "Generate Error Hash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No Alert Needed": {
      "main": [
        [
          {
            "node": "Calculate Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Metadata": {
      "main": [
        [
          {
            "node": "Extract Environment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Log Entry": {
      "main": [
        [
          {
            "node": "API - Save Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Metrics": {
      "main": [
        [
          {
            "node": "API - Save Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Aggregate": {
      "main": [
        [
          {
            "node": "API - Update Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API - Save Metrics": {
      "main": [
        [
          {
            "node": "Prepare Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Retention": {
      "main": [
        [
          {
            "node": "API - Cleanup Old Logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Environment": {
      "main": [
        [
          {
            "node": "Classify Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Logger Error": {
      "main": [
        [
          {
            "node": "Slack - Logger Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Error Hash": {
      "main": [
        [
          {
            "node": "API - Check Duplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Warning Alert": {
      "main": [
        [
          {
            "node": "Slack - Warning Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API - Check Duplicate": {
      "main": [
        [
          {
            "node": "Is New Error?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Critical Alert": {
      "main": [
        [
          {
            "node": "Slack - Critical Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack - Warning Alert": {
      "main": [
        [
          {
            "node": "Calculate Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API - Update Aggregate": {
      "main": [
        [
          {
            "node": "Calculate Retention",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack - Critical Alert": {
      "main": [
        [
          {
            "node": "Calculate Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}