Observability Monitoring And Incident Response

Sentry For PHP Applications

Metrics tell you the error rate went up; an error tracker tells you which error, with the stack trace, the request context, and how many users it hit. Sentry is the widely used tool in this category, and "Sentry" here stands for the whole class of application error-tracking services. The job it does — turning a flood of individual exceptions into a deduplicated, prioritized, context-rich list — is one that raw logs do badly and that matters enormously for actually fixing bugs rather than just knowing they exist.

What An Error Tracker Adds Over Logs

A logged exception is one line among millions; the same exception thrown ten thousand times is ten thousand lines. An error tracker changes the unit of work from occurrence to issue:

  • Grouping. Identical errors are fingerprinted and collapsed into one issue with a count, so "NullReference in Checkout, 8,400 events, 1,200 users" is a single actionable item instead of a log deluge.
  • Context capture. Each event carries the full stack trace, the request (URL, method, sanitized parameters), the release version, the environment, and — for logged-in users — a user identifier, so you can reproduce instead of guess.
  • Regression and release tracking. Errors are tied to the deploy that introduced them, so a spike lines up with a release and a resolved issue that reappears is flagged as a regression.
  • Prioritization. Frequency and user-impact counts let you fix the bug hurting a thousand users before the one hurting one.

Wiring It Into PHP

The SDK installs via Composer and hooks the error and exception handlers so uncaught throwables are captured automatically; framework integrations (Laravel, Symfony) add request context and breadcrumbs. The conceptual model is simple — capture, enrich, send — but three configuration decisions separate a useful setup from a noisy or dangerous one:

  • Environments and releases. Tag every event with the environment (production/staging) and the release (a version or commit sha). Without the release tag, you lose the single most useful feature: "this error started at release X," which turns triage into a diff.
  • Scrub sensitive data. This is the one that bites teams. Error context can sweep up passwords, tokens, session cookies, personal data, and payment details from request parameters and headers, and send them to a third party — a compliance and security incident in itself. Configure before_send scrubbing and server-side data-scrubbing rules to strip secrets before transmission, and treat the error tracker as an external service that publishes whatever you feed it. The security track's principle that stack traces belong in logs, not responses, extends here: they belong in the tracker, scrubbed.
  • Sampling and quotas. A high-traffic error can burn your event quota in minutes and bury the signal. Rate-limit or sample noisy issues so the tracker stays a curated list rather than a firehose.
PHP example
<?php

declare(strict_types=1);

// Conceptual shape of a before-send scrubber: drop secrets before the event leaves your server.
function scrub(array $event): array
{
    foreach (['password', 'token', 'authorization', 'cookie', 'card_number'] as $secret) {
        unset($event['request']['data'][$secret]);
    }
    return $event;
}

$event = ['request' => ['data' => ['email' => 'a@b.com', 'password' => 'hunter2']]];
$clean = scrub($event);

echo isset($clean['request']['data']['password']) ? 'LEAKED' : 'scrubbed';
echo PHP_EOL;

// Prints:
// scrubbed

From Alert To Fix

An error tracker earns its keep by connecting to workflow: new or spiking issues alert the right channel (tuned so a known, low-priority error does not page anyone), issues link to the deploy and ideally to the code, and resolving an issue in the tracker closes the loop when the fix ships. This is the application-layer counterpart to the infrastructure alerting in the next lesson — errors are what your code is telling you, and they deserve their own tuned, de-duplicated, secret-free pipeline.

What To Check

Before moving on, make sure you can:

  • explain what grouping, context, and release-tracking add over raw logs
  • tag events with environment and release and say why release tags matter most
  • scrub secrets and personal data before events leave your server
  • sample or rate-limit noisy errors to protect signal and quota
  • connect error issues to alerts, deploys, and resolution

What You Should Be Able To Do

After this lesson, you should be able to integrate an error tracker into a PHP application so that exceptions become a prioritized, context-rich, secret-free issue list tied to releases, and route new and regressing issues to a channel that helps you fix the important bugs first.

Practice

Practice: Design Error Tracking
Show solution

Tagging: every event tagged with environment (production/staging separated so staging noise never pollutes production triage) and release (the deploy's commit sha). The release tag is non-negotiable here because "which deploy introduced this" is the fastest triage path.

Scrubbing — critical for a payments app: before_send strips card numbers, CVVs, passwords, tokens, authorization headers, and cookies before transmission, plus server-side scrubbing rules as a second layer. The design treats Sentry as a third party that will store whatever it receives, so PII and secrets must never reach it — this is a compliance requirement, not a nicety.

Noise control: high-frequency known errors are sampled or rate-limited so they cannot exhaust the event quota or bury new issues; a noisy third-party deprecation is filtered out entirely.

Action: new issues and regressions (a resolved issue reappearing) alert the engineering channel; issues crossing a user-impact threshold escalate. Each issue links to its release and to the code. Alert routing is tuned so routine low-priority errors inform without paging, reserving pages for genuine spikes — the same signal-preservation discipline as infrastructure alerting.

Practice: Diagnose A Leaky, Noisy Tracker

A team's Sentry receives 50,000 events/day, mostly one noisy deprecation warning; nobody looks at it anymore. During an audit, security finds full credit-card numbers and session cookies in stored error events. Separately, a real checkout bug went unnoticed for a week because it was buried.

Task

Diagnose all three problems and their fixes.

Show solution

Three failures, one root theme (an unmanaged pipeline), each with a distinct fix.

Sensitive data leak — the most serious: credit-card numbers and session cookies in stored events mean the app sent payment data and live session tokens to a third-party service, which is a PCI and privacy incident and hands an attacker who reaches Sentry both card data and hijackable sessions. Fix: before_send scrubbing plus server-side scrub rules to strip card fields, cookies, and auth headers before transmission — and, because the data is already stored externally, a cleanup/response step to purge it and rotate exposed session material per the compromise playbook. The rule: the tracker publishes whatever you feed it, so secrets must be removed at the source.

Noise burying signal: 50,000 events dominated by one deprecation trained the team to ignore the tool, so it stopped functioning as an alert surface entirely. Fix: filter that deprecation out (or fix it), sample high-frequency issues, and tune alerts so only new/spiking issues notify. An error tracker's value is inversely proportional to its noise.

The missed checkout bug is the consequence of the first two: a real, high-impact issue was invisible because grouping and prioritization were drowned and nobody was watching. Once noise is controlled and new-issue alerts route to a read channel, a checkout error spiking across users pages within minutes instead of hiding for a week.

The through-line: an error tracker is a curated signal, and it requires active management — scrubbing for safety, sampling for clarity, and tuned alerting for action — or it degrades into an expensive, leaky log dump.

Practice: Define Error Tracking Checks
Show solution
  • A test triggers an error carrying planted fake secrets (a test card number, a fake token) and asserts the transmitted event has them scrubbed — the most important check, since a leak here is a compliance incident.
  • A test asserts every event carries environment and release tags, so triage-by-deploy keeps working.
  • Event-volume and quota-consumption are monitored; a sudden spike (a new noisy issue) alerts before it exhausts quota or buries signal.
  • A test confirms new/regressing issues generate an alert to the configured channel.

Human, periodically:

  • Review the top issues by volume and confirm they are real and actioned, not noise the team has learned to ignore — a growing ignore-list is the early sign the tracker is decaying into a log dump.
  • Audit a sample of stored events for any sensitive data that slipped past scrubbing as new fields and endpoints were added; scrub rules must evolve with the app.
  • Confirm alert routing still distinguishes page-worthy spikes from informational errors, so the tool neither cries wolf nor stays silent.