Observability and operations
This section details the one-off Sentry report export command, which retrieves recent production issues via the Sentry API and writes them to a CSV. It aids in incident review and triage by surfacing key metrics (ID, link, title, culprit, last seen, count).
Prerequisites
- Environment Variable
EnsureSENTRY_API_KEYis set in your.env. - Configuration
The API key is loaded fromconfig/services.php:
'sentry' => [
'api_key' => env('SENTRY_API_KEY'),
],
Command Overview
| Property | Detail |
|---|---|
| Signature | sentry:generate-report |
| Description | Export recent production issues to sentry-report.csv |
| Namespace | App\Console\Commands\oneoffs |
| Location | app/Console/Commands/oneoffs/GenerateSentryReport.php |
Usage
Run from the project root:
php artisan sentry:generate-report
Workflow
flowchart TD
A[Start command<br>`handle()`] --> B{API key set?}
B -- No --> C[Error: "SENTRY_API_KEY is not set"]
B -- Yes --> D[Determine date range<br>(last 30 days)]
D --> E[getEvents(start, end)]
E --> F[Loop pages:<br>makeRequest → parseResponse → collect]
F --> G[Format & sort events]
G --> H[Open `sentry-report.csv` for writing]
H --> I[Write headers & rows]
I --> J[Close file]
J --> K[Info: success messages]
Key Methods
-
handle()
- Loads the API key.
- Computes
startDateandendDate(last 30 days). - Calls
getEvents(), transforms and sorts the results. - Writes
sentry-report.csvwith headers:
ID, Link, Title, Culprit, Last Seen, Count.
-
getEvents(string $startDate, string $endDate)
- Builds the Sentry API URL for production issues.
- Paginates via the
Linkheader until nonextlink remains. - Merges all pages into a single
Collection.
-
makeRequest(string $url)
- Sends an HTTP GET with
Authorization: Bearer <apiKey>. - Uses the
Httpfacade for simplicity and retry behavior.
- Sends an HTTP GET with
-
parseResponse($response)
- Converts JSON to a collection, filtering out issues not seen within the last 30 days.
-
parseLinkHeader(array $headers)
- Extracts the
nextpage URL whenrel="next"andresults="true". - Returns
nullwhen pagination ends.
- Extracts the
CSV Output
| Column | Description |
|---|---|
| ID | Sentry issue identifier |
| Link | Direct URL to the issue in Sentry |
| Title | Issue title |
| Culprit | Code path most responsible for the error |
| Last Seen | Date of the most recent occurrence (MM/DD/YYYY) |
| Count | Total times the issue occurred |
The file is saved as:
sentry-report.csv
in the project root upon successful execution.
Best Practices 💡
{
"title": "Secure API Key",
"content": "Rotate and scope your SENTRY_API_KEY. Avoid committing it to VCS."
}
- Regularly run this export during on-call reviews.
- Archive or attach the CSV to incident tickets.
- Combine with Slack or email reminders for automated workflows.
By integrating this command into your operational toolkit, teams gain a consistent, up-to-date snapshot of error trends, improving response time and root-cause analysis.