---
title: Log All Relevant Context on Errors
impact: HIGH
impactDescription: speeds up troubleshooting
tags: logging, troubleshooting, quality, python
---

## Log All Relevant Context on Errors

When an error occurs, log the metadata (IDs, parameters) needed to reproduce it.

**Incorrect:**
```python
except Exception as e:
    logger.error("Upload failed")
```

**Correct:**
```python
except Exception as e:
    logger.error(f"Upload failed for user {user_id}", extra={
        "file_id": file_id,
        "bucket": bucket_name,
        "exc_info": True
    })
```
