$ show getsentry/sentry-php
This is the official Sentry SDK for PHP (sentry-php), a client library that instruments PHP applications for error tracking, exception capture, performance monitoring (tracing, logging, metrics, profiling, and check-ins). The architecture follows a hub-scope pattern: a global SentrySdk facade manages a stack of Hub instances, each holding a Client and Scope. The Client handles event creation, before-send callbacks, sampling, and integration setup. Events are serialized into Sentry envelope format and transmitted via an HTTP transport (cURL) or a local agent socket. The library ships with numerous integrations for PHP frameworks (Monolog, Guzzle, OpenTelemetry, Symfony, Laravel), a custom Options resolver, serializers, aggregation buffers for metrics and logs, and runtime context isolation for long-lived workers (FrankenPHP, RoadRunner). External dependencies include Monolog, PSR-7, OpenTelemetry API, and the Excimer extension for profiling. The SDK is highly configurable via the Options class and supports extensive event enrichment through scopes and event processors.
The LLM identified 3 files worth highlighting for reuse:
A generic, fixed-size ring buffer implementation with O(1) push, peek, and overwrite semantics. It is self-contained, requires no internal SDK dependencies, and can be extracted as a standalone utility for any project that needs a bounded, overwriting queue. Demonstrates efficient memory management and clean, testable API design.
A custom configuration resolver that supports nested defaults, type validation, dot-notation path access, and environment variable fallbacks. It is a key part of the SDK's configuration system but is written as a standalone utility with only internal PHP standard library dependencies. The pattern of resolving and merging nested options with logging of invalid keys is reusable in any application needing complex configuration management.
A reusable trait that parses the Sentry trace header ('sentry-trace') and W3C baggage header to extract trace context (trace ID, span ID, sampling decision, dynamic sampling data). It implements header validation, parsing of comma-separated baggage entries, and freeze/unfreeze semantics for the dynamic sampling context. This pattern can be extracted for any PHP project that needs to propagate distributed tracing headers.