### Example Usage of fromHeaders() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Example of creating a TransactionContext from headers and starting a transaction. ```php $context = \Sentry\Tracing\TransactionContext::fromHeaders( $_SERVER['HTTP_SENTRY_TRACE'], $_SERVER['HTTP_BAGGAGE'] ); $transaction = $hub->startTransaction($context); ``` -------------------------------- ### Transaction::startChild() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Example of starting a child span within a transaction. ```php $transaction = $hub->startTransaction(new \Sentry\Tracing\TransactionContext('payment-processing')); $span = $transaction->startChild(new \Sentry\Tracing\SpanContext( operation: 'db.query', description: 'SELECT * FROM orders' )); // Process payment $span->finish(); $transaction->finish(); ``` -------------------------------- ### ClientBuilder::create() example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Example of creating a ClientBuilder with DSN and environment options. ```php $builder = \Sentry\ClientBuilder::create([ 'dsn' => 'https://key@sentry.io/project', 'environment' => 'production' ]); ``` -------------------------------- ### Set up tracing Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md Example of starting a distributed tracing transaction. ```php $transaction = \Sentry\startTransaction( new \Sentry\Tracing\TransactionContext('user-action') ); ``` -------------------------------- ### getIntegration() example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Example of how to retrieve an integration instance. ```php $integration = $client->getIntegration(\Sentry\Integration\RequestIntegration::class); ``` -------------------------------- ### startContext() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Demonstrates starting and ending an isolated runtime context. ```php \Sentry\SentrySdk::startContext(); try { // Code in isolated context } finally { \Sentry\SentrySdk::endContext(); } ``` -------------------------------- ### Verifying Integration Installation Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md Code example to check if a specific integration, like `RequestIntegration`, is installed and active. ```php $hub = \Sentry\SentrySdk::getCurrentHub(); $client = $hub->getClient(); // Check if a specific integration is installed $requestIntegration = $client->getIntegration( \Sentry\Integration\RequestIntegration::class ); if ($requestIntegration !== null) { echo "RequestIntegration is active\n"; } else { echo "RequestIntegration is not installed\n"; } ``` -------------------------------- ### Spotlight Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of enabling Spotlight debug tool integration and setting its URL. ```php \Sentry\init([ 'spotlight' => true, 'spotlight_url' => 'http://localhost:8969/stream' ]); ``` -------------------------------- ### Metrics Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of enabling metrics collection and setting the flush threshold. ```php \Sentry\init([ 'enable_metrics' => true, 'metric_flush_threshold' => 500 ]); ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md A comprehensive example demonstrating various configuration options for the Sentry SDK in PHP. ```php \Sentry\init([ // Core 'dsn' => 'https://key@o0.ingest.sentry.io/0', 'environment' => 'production', 'release' => 'v1.2.3', // Sampling 'sample_rate' => 0.95, 'traces_sample_rate' => 0.1, 'profiles_sample_rate' => 0.01, // Tracing 'trace_propagation_targets' => [ '/^https:\/\/api\.example\.com\//', '/^https:\/\/webhook\.example\.com\//' ], // Logging 'enable_logs' => true, 'log_flush_threshold' => 100, // Data handling 'max_breadcrumbs' => 100, 'max_value_length' => 2048, 'send_default_pii' => false, 'context_lines' => 7, // Path handling 'in_app_include' => ['/app/', '/src/'], 'in_app_exclude' => ['/vendor/'], 'prefixes' => ['/var/www'], // Network 'http_timeout' => 5, 'http_compression' => true, // Filtering 'ignore_exceptions' => [ 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' ], 'before_send' => function ($event) { return $event; }, 'before_breadcrumb' => function ($breadcrumb) { return $breadcrumb; } ]); ``` -------------------------------- ### Example Usage of toTraceparent() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Example of how to get the traceparent header and send it to a downstream service. ```php $header = $span->toTraceparent(); // Send as 'traceparent' HTTP header to downstream service ``` -------------------------------- ### Install SDK Source: https://github.com/getsentry/sentry-php/blob/master/README.md Install the SDK using Composer. ```bash composer require sentry/sentry ``` -------------------------------- ### Integrations Configuration Example (Filter) Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of filtering out specific integrations using a callable. ```php // Filter integrations \Sentry\init([ 'integrations' => function (array $integrations) { return array_filter($integrations, function ($integration) { return !($integration instanceof \Sentry\Integration\RequestIntegration); }); } ]); ``` -------------------------------- ### Integrations Configuration Example (Custom) Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of providing custom integrations to the Sentry SDK. ```php // Custom integrations \Sentry\init([ 'integrations' => [ new \Sentry\Integration\ErrorListenerIntegration(), new \Sentry\Integration\ExceptionListenerIntegration(), new \Sentry\Integration\RequestIntegration() ] ]); ``` -------------------------------- ### flush() example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Example of flushing events with a timeout and checking the result. ```php $result = $client->flush(5); if ($result->isSuccessful()) { echo 'Events flushed successfully'; } ``` -------------------------------- ### Logging Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of configuring a PSR-3 logger for SDK debug messages. ```php $logger = new \Monolog\Logger('sentry'); \Sentry\init([ 'logger' => $logger ]); ``` -------------------------------- ### getClient() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Builds and returns a configured Client instance. ```php $client = \Sentry\ClientBuilder::create([ 'dsn' => 'https://key@sentry.io/project', 'traces_sample_rate' => 0.1 ])->getClient(); ``` -------------------------------- ### DSN Format Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Example of a DSN string. ```text https://examplePublicKey@o0.ingest.sentry.io/0 ``` -------------------------------- ### startTransaction() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md Starts a new transaction for distributed tracing. ```php $context = new \Sentry\Tracing\TransactionContext('api-request'); $context->setOp('http.server'); $transaction = \Sentry\startTransaction($context); // Do work $span = $transaction->startChild(new \Sentry\Tracing\SpanContext( operation: 'db.query', description: 'SELECT * FROM users' )); // ... execute query $span->finish(); $transaction->finish(); ``` -------------------------------- ### Transport Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of configuring transport settings like timeout, proxy, compression, and send attempts. ```php \Sentry\init([ 'http_timeout' => 10, 'http_proxy' => 'http://proxy.example.com:3128', 'http_compression' => true, 'send_attempts' => 5 ]); ``` -------------------------------- ### Install the dependencies Source: https://github.com/getsentry/sentry-php/blob/master/CONTRIBUTING.md Installs project dependencies using Composer. ```bash composer install ``` -------------------------------- ### Request Filtering Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of configuring paths to include/exclude as in-app and path prefixes to strip. ```php \Sentry\init([ 'in_app_include' => [ '/app/', '/src/' ], 'in_app_exclude' => [ '/vendor/', '/node_modules/' ], 'prefixes' => [ '/var/www/html', '/home/user/project' ] ]); ``` -------------------------------- ### Event Context and Data Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of configuring breadcrumb limits, value length, PII sending, request body size, default tags, and context lines. ```php \Sentry\init([ 'max_breadcrumbs' => 50, 'max_value_length' => 2048, 'send_default_pii' => false, 'max_request_body_size' => 'small', 'tags' => [ 'app_version' => '1.0.0', 'environment_type' => 'cloud' ], 'context_lines' => 10 ]); ``` -------------------------------- ### Version Pinning Examples Source: https://github.com/getsentry/sentry-php/blob/master/CONTRIBUTING.md Examples of how to pin version requirements for the sentry/sentry package. ```json "sentry/sentry": "^1.0", ``` ```json "sentry/sentry": "^1" ``` -------------------------------- ### CheckInStatus Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of creating a CheckInStatus instance. ```php $status = \Sentry\CheckInStatus::ok(); ``` -------------------------------- ### EventId::generate() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Example of generating a new event ID. ```php $eventId = \Sentry\EventId::generate(); ``` -------------------------------- ### Custom Integration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md An example of a custom integration that implements `OptionAwareIntegrationInterface` to access Sentry options. ```php use Sentry\Integration\OptionAwareIntegrationInterface; use Sentry\Integration\IntegrationInterface; use Sentry\Options; class ConfigAwareIntegration implements IntegrationInterface, OptionAwareIntegrationInterface { private Options $options; public function setOptions(Options $options): void { $this->options = $options; } public function setupOnce(): void { $dsn = $this->options->getDsn(); if ($dsn !== null) { // Configure based on DSN } } } ``` -------------------------------- ### getStartTimestamp() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the start timestamp for transaction events. Used to calculate duration. ```php public function getStartTimestamp(): ?float ``` -------------------------------- ### Logging with attributes Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Example of logging with attributes. ```php \Sentry\logger()->error( 'Payment processing failed', [], [ 'user_id' => 123, 'payment_id' => 'pay_xyz', 'error_code' => 'INSUFFICIENT_FUNDS' ] ); ``` -------------------------------- ### Environment and Release Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with environment and release configuration. ```php \Sentry\init([ 'environment' => 'production', 'release' => 'v1.2.3' ]); ``` -------------------------------- ### startContext() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example illustrating the use of `startContext` and `endContext` within a worker loop for isolated processing. ```php // In a worker loop \Sentry\startContext(); try { // Process job } finally { \Sentry\endContext(); } ``` -------------------------------- ### DSN and Project Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with DSN and project configuration. ```php \Sentry\init([ 'dsn' => 'https://key@o0.ingest.sentry.io/0' ]); ``` -------------------------------- ### Logging Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with logging configuration. ```php \Sentry\init([ 'enable_logs' => true, 'log_flush_threshold' => 100 // Flush every 100 logs ]); ``` -------------------------------- ### withMonitor() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example demonstrating how to use the `withMonitor` function to wrap a task with monitor check-ins. ```php $result = \Sentry\withMonitor('daily-task', function () { return executeTask(); }); ``` -------------------------------- ### Sentry SDK Initialization and Usage Source: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md Example demonstrating how to initialize the Sentry SDK, configure the scope with user data and tags, capture an exception, and add a breadcrumb. ```php \Sentry\init(['dsn' => '___PUBLIC_DSN___' ]); \Sentry\configureScope(function (\Sentry\State\Scope $scope): void { $scope->setTag('page_locale', 'de-at'); $scope->setUser(['email' => 'john.doe@example.com']); $scope->setLevel(\Sentry\Severity::warning()); $scope->setExtra('character_name', 'Mighty Fighter'); }); // The following capture call will contain the data from the previous configured Scope try { thisFunctionThrows(); // -> throw new \Exception('foo bar'); } catch (\Exception $exception) { \Sentry\captureException($exception); } \Sentry\addBreadcrumb(new Breadcrumb(Breadcrumb::LEVEL_ERROR, Breadcrumb::TYPE_ERROR, 'error_reporting', 'Message')); ``` -------------------------------- ### Profiling Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with profiling configuration. ```php \Sentry\init([ 'profiles_sample_rate' => 0.1, 'profiles_sampler' => function (\Sentry\Tracing\SamplingContext $context) { return 0.1; // Profile 10% of transactions } ]); ``` -------------------------------- ### MonitorSchedule Example: Daily Schedule Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of creating a daily schedule using MonitorSchedule. ```php // Daily schedule $schedule = new \Sentry\MonitorSchedule( \Sentry\MonitorScheduleUnit::DAY, 1 ); ``` -------------------------------- ### Usage Source: https://github.com/getsentry/sentry-php/blob/master/README.md Example of capturing an exception. ```php try { thisFunctionThrows(); // -> throw new \Exception('foo bar'); } catch (\Exception $exception) { \Sentry\captureException($exception); } ``` -------------------------------- ### MonitorSchedule Example: Hourly Schedule Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of creating an hourly schedule using MonitorSchedule. ```php // Every 6 hours $schedule = new \Sentry\MonitorSchedule( \Sentry\MonitorScheduleUnit::HOUR, 6 ); ``` -------------------------------- ### setTag() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Example usage of the setTag method to attach tags to events. ```php $scope->setTag('request_id', '12345'); $scope->setTag('environment', 'production'); ``` -------------------------------- ### init() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Initializes the Sentry SDK. ```php $hub = \Sentry\SentrySdk::init(); ``` -------------------------------- ### withContext() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example demonstrating the use of `withContext` to execute a job processing callback within an isolated context. ```php $result = \Sentry\withContext(function () { return processJob($jobId); }); ``` -------------------------------- ### Invalid Configuration Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Demonstrates an invalid value passed to init() for 'sample_rate'. ```php \Sentry\init([ 'sample_rate' => 1.5 // Invalid: > 1 ]); // Throws: InvalidArgumentException ``` -------------------------------- ### Example Usage of Severity Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Demonstrates how to create and use a Severity level. ```php $level = \Sentry\Severity::error(); $event->setLevel($level); ``` -------------------------------- ### traceMetrics() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example of using `traceMetrics` to record an HTTP request duration distribution. ```php \Sentry\traceMetrics()->distribution( 'http.request.duration', $duration, ['method' => 'GET'], \Sentry\Unit::millisecond() ); ``` -------------------------------- ### HTTP Breadcrumb Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of how to add an HTTP breadcrumb to Sentry. ```php \Sentry\addBreadcrumb(new \Sentry\Breadcrumb( level: \Sentry\Breadcrumb::LEVEL_INFO, type: \Sentry\Breadcrumb::TYPE_HTTP, category: 'http.client', message: 'GET /api/users/123', metadata: [ 'method' => 'GET', 'url' => '/api/users/123', 'status_code' => 200 ] )); ``` -------------------------------- ### Sampling Callback Error Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example of an error within the 'before_send' callback, demonstrating error handling and event dropping. ```php \Sentry\init([ 'before_send' => function ($event) { if (!$event) { throw new Exception('Event is null'); // Error handling recommended } return $event; } ]); ``` -------------------------------- ### Initialize the SDK Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md Example of initializing the Sentry SDK with basic configuration. ```php \Sentry\init([ 'dsn' => 'https://key@sentry.io/project', 'environment' => 'production', 'traces_sample_rate' => 0.1 ]); ``` -------------------------------- ### flush() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example showing how to call `flush` at application shutdown to ensure all telemetry is sent. ```php // At application shutdown \Sentry\flush(); ``` -------------------------------- ### getIntegration() method signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Returns an installed integration by class name. ```php public function getIntegration(string $className): ?IntegrationInterface ``` -------------------------------- ### Tracing Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with tracing configuration, including `traces_sample_rate` and `traces_sampler`. ```php \Sentry\init([ 'traces_sample_rate' => 0.1, // 10% of transactions 'traces_sampler' => function (\Sentry\Tracing\SamplingContext $context) { if ($context->getTransactionContext()->getOp() === 'http.server') { return 0.2; // 20% of HTTP transactions } return 0.0; // Don't sample other operations }, 'trace_propagation_targets' => [ '/^https:\/\/example\.com\/api\/.+/', '/^https:\/\/internal-api\.local\/.+/' ] ]); ``` -------------------------------- ### setupOnce() Method Signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md The `setupOnce()` method is called once during client initialization. Integrations should register error handlers, hooks, or listeners here. ```php public function setupOnce(): void ``` -------------------------------- ### Testing Custom Integrations Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md Example of initializing Sentry with a custom integration and verifying its registration. ```php // Initialize with custom integration \Sentry\init([ 'integrations' => [new CustomIntegration()] ]); // Verify it was registered $hub = \Sentry\SentrySdk::getCurrentHub(); $integration = $hub->getClient()->getIntegration(CustomIntegration::class); assert($integration !== null); ``` -------------------------------- ### User Action Breadcrumb Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of how to add a user action breadcrumb to Sentry. ```php \Sentry\addBreadcrumb( category: 'user-action', message: 'User logged in', metadata: ['user_id' => 123], level: \Sentry\Breadcrumb::LEVEL_INFO, type: \Sentry\Breadcrumb::TYPE_USER ); ``` -------------------------------- ### Memory monitoring Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Example of monitoring memory usage. ```php \Sentry\traceMetrics()->gauge( 'php.memory.current', memory_get_usage(), [], \Sentry\Unit::byte() ); ``` -------------------------------- ### Monolog Handler Decoration Example Source: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-3.0.md Example of how to decorate the Monolog handler to set tags and extras on the scope when using Sentry PHP SDK 3.0. ```php use Monolog\Handler\HandlerInterface; use Sentry\State\Scope; use function Sentry\withScope; final class MonologHandler implements HandlerInterface { private $decoratedHandler; public function __construct(HandlerInterface $decoratedHandler) { $this->decoratedHandler = $decoratedHandler; } public function isHandling(array $record): bool { return $this->decoratedHandler->isHandling($record); } public function handle(array $record): bool { $result = false; withScope(function (Scope $scope) use ($record, &$result): void { $scope->setTags(...); $scope->setExtras(...); $result = $this->decoratedHandler->handle($record); }); return $result; } public function handleBatch(array $records): void { $this->decoratedHandler->handleBatch($records); } public function close(): void { $this->decoratedHandler->close(); } } ``` -------------------------------- ### Transaction::startChild() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Starts a child span within this transaction. ```php public function startChild(SpanContext $context = null): Span ``` -------------------------------- ### Span::getDescription() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the span description. ```php public function getDescription(): ?string ``` -------------------------------- ### DSN Validation Error Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Shows an example of an invalid DSN string passed to `init()` and the resulting `InvalidArgumentException`. ```php \Sentry\init([ 'dsn' => 'not-a-valid-dsn' ]); // Throws: InvalidArgumentException: The "not-a-valid-dsn" DSN is invalid. ``` -------------------------------- ### getSampled() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the sampling decision. ```php public function getSampled(): ?bool ``` -------------------------------- ### getServerName() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the server name/hostname. ```php public function getServerName(): ?string ``` -------------------------------- ### addFeatureFlag() Example Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md An example showing how to record a feature flag evaluation using `addFeatureFlag`. ```php \Sentry\addFeatureFlag('new-checkout', isFeatureEnabled('new-checkout')); ``` -------------------------------- ### Event Sampling Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with event sampling configuration, including a `before_send` callback. ```php \Sentry\init([ 'sample_rate' => 0.5, // Send 50% of events 'before_send' => function (\Sentry\Event $event, ?EventHint $hint) { if ($event->getLevel() === \Sentry\Severity::debug()) { return null; // Drop debug events } return $event; } ]); ``` -------------------------------- ### Error and Exception Handling Configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of initializing the Sentry SDK with error and exception handling configuration. ```php \Sentry\init([ 'error_types' => E_ALL & ~E_DEPRECATED, 'capture_silenced_errors' => true, 'ignore_exceptions' => [ 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'RuntimeException' ] ]); ``` -------------------------------- ### getHost() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the hostname. ```php public function getHost(): string ``` -------------------------------- ### Creating a Custom Integration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md Example of creating a custom Sentry integration in PHP. ```php use Sentry\Integration\IntegrationInterface; use Sentry\SentrySdk; class CustomIntegration implements IntegrationInterface { public function setupOnce(): void { // Register handlers/listeners once register_shutdown_function(function () { // Capture custom data if (/* error condition */) { \Sentry\captureMessage('Custom error detected'); } }); } } ``` -------------------------------- ### Filtering Integrations Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md Example of filtering integrations during Sentry initialization. ```php \Sentry\init([ 'integrations' => function (array $integrations) { // Remove RequestIntegration return array_filter($integrations, function ($integration) { return !($integration instanceof \Sentry\Integration\RequestIntegration); }); } ]); ``` -------------------------------- ### Registering Custom Integrations Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/integrations.md Example of registering custom integrations with Sentry. ```php \Sentry\init([ 'integrations' => [ new \Sentry\Integration\ErrorListenerIntegration(), new CustomIntegration() ] ]); ``` -------------------------------- ### Set up cron monitoring Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md Example of capturing a check-in for a cron job. ```php $checkInId = \Sentry\captureCheckIn('backup-job', \Sentry\CheckInStatus::inProgress()); ``` -------------------------------- ### Transaction Callbacks Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of using the `before_send_transaction` callback to filter transactions. ```php \Sentry\init([ 'before_send_transaction' => function (\Sentry\Event $transaction) { if ($transaction->getLevel() === \Sentry\Severity::warning()) { // Skip warning-level transactions return null; } return $transaction; } ]); ``` -------------------------------- ### Database query metrics Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Example of tracking database query metrics. ```php $queries = 0; $start = microtime(true); foreach ($items as $item) { $db->insert('items', $item); $queries++; } $duration = (microtime(true) - $start) * 1000; \Sentry\traceMetrics()->distribution( 'db.query.duration', $duration / $queries, ['operation' => 'INSERT', 'table' => 'items'], \Sentry\Unit::millisecond() ); \Sentry\traceMetrics()->count( 'db.queries', $queries, ['operation' => 'INSERT', 'table' => 'items'] ); ``` -------------------------------- ### Trace-level log example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Records a trace-level log with a message and optional values and attributes. ```php \Sentry\logger()->trace('Database query executed', ['table' => 'users']); ``` -------------------------------- ### UserDataBag Usage Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/types.md Example of creating and setting a UserDataBag on the scope. ```php $user = new \Sentry\UserDataBag([ 'id' => '123', 'email' => 'user@example.com', 'username' => 'john_doe', 'ip_address' => '192.168.1.1' ]); \Sentry\configureScope(function ($scope) use ($user) { $scope->setUser($user); }); ``` -------------------------------- ### Behavior Callbacks Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/configuration.md Example of using the `before_breadcrumb` callback to filter breadcrumbs. ```php \Sentry\init([ 'before_breadcrumb' => function (\Sentry\Breadcrumb $breadcrumb) { if ($breadcrumb->getCategory() === 'sql') { // Redact SQL queries $breadcrumb->setMessage('SELECT ... (redacted)'); } return $breadcrumb; } ]); ``` -------------------------------- ### With monitor configuration Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of using `withMonitor` with a custom `MonitorConfig`. ```php $config = new \Sentry\MonitorConfig( schedule: new \Sentry\MonitorSchedule( \Sentry\MonitorScheduleUnit::HOUR, 6 ), checkinMargin: 5, maxRuntime: 60, timezone: 'UTC' ); \Sentry\withMonitor('backup-job', function () { performBackup(); }, $config); ``` -------------------------------- ### Adding Extra Context Source: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md Example of how to add extra context to the client before version 2.0 and the equivalent in version 2.0. ```php $client->extra_context(array('foo' => 'bar')); ``` ```php use Sentry\State\Hub; use Sentry\State\Scope; Hub::getCurrent()->configureScope(function (Scope $scope): void { $scope->setExtra('extra_key', 'extra_value'); }); ``` -------------------------------- ### getFrames() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets all frames from the stacktrace. ```php public function getFrames(): array ``` -------------------------------- ### Basic check-in Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/breadcrumbs-monitors.md Example of capturing a basic check-in for a backup process, including status updates. ```php $checkInId = \Sentry\captureCheckIn( slug: 'daily-backup', status: \Sentry\CheckInStatus::inProgress() ); try { performBackup(); $status = \Sentry\CheckInStatus::ok(); } catch (\Exception $e) { $status = \Sentry\CheckInStatus::error(); } finally { \Sentry\captureCheckIn( slug: 'daily-backup', status: $status, duration: $endTime - $startTime, checkInId: $checkInId ); } ``` -------------------------------- ### getScheme() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the URL scheme. ```php public function getScheme(): string ``` -------------------------------- ### Example Usage of Severity::fromError() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Demonstrates converting a PHP error constant to a Severity level. ```php $severity = \Sentry\Severity::fromError(E_WARNING); ``` -------------------------------- ### Example Handling for EventCreationException Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Demonstrates how to catch and handle `EventCreationException` when creating a DSN or Severity object with invalid values. ```php try { $dsn = \Sentry\Dsn::createFromString('invalid-dsn'); } catch (\InvalidArgumentException $e) { // Handle invalid DSN error_log('DSN validation failed: ' . $e->getMessage()); } try { $severity = new \Sentry\Severity('invalid_level'); } catch (\InvalidArgumentException $e) { // Handle invalid severity error_log('Invalid severity: ' . $e->getMessage()); } ``` -------------------------------- ### startContext() Method Signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Starts a new isolated runtime context. Used in async/worker environments. ```php public static function startContext(): void ``` -------------------------------- ### getOptions() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Returns the options used by the client. ```php public function getOptions(): Options ``` ```php $client = \Sentry\ClientBuilder::create(['dsn' => 'https://...'])->getClient(); $options = $client->getOptions(); ``` -------------------------------- ### Metrics tracking: API endpoint performance Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Example of tracking API endpoint performance. ```php // Track API endpoint performance $start = microtime(true); $result = callExternalApi(); $duration = (microtime(true) - $start) * 1000; // milliseconds \Sentry\traceMetrics()->distribution( 'external.api.duration', $duration, [ 'endpoint' => '/v1/charges', 'status_code' => $result->getStatus() ], \Sentry\Unit::millisecond() ); ``` -------------------------------- ### Record metrics Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md Example of recording a distribution metric. ```php \Sentry\traceMetrics()->distribution('http.request.duration', $duration_ms); ``` -------------------------------- ### ClientBuilder::getHttpClient() method signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Gets the HTTP client instance, creating a default one if not set. ```php public function getHttpClient(): HttpClientInterface ``` -------------------------------- ### Configuration Validation Best Practice Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example of validating Sentry SDK configuration during initialization using a try-catch block. ```php try { $options = [ 'dsn' => $_ENV['SENTRY_DSN'], 'traces_sample_rate' => 0.1, 'environment' => 'production' ]; \Sentry\init($options); } catch (\InvalidArgumentException $e) { // Configuration error - fail fast echo "Sentry configuration error: {$e->getMessage()}\n"; exit(1); } ``` -------------------------------- ### Distribution metric example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Records a distribution metric, capturing a value for percentile calculation with optional attributes and unit. ```php $duration = $endTime - $startTime; \Sentry\traceMetrics()->distribution( 'http.server.duration', $duration, ['http.method' => 'POST'], \Sentry\Unit::millisecond() ); ``` -------------------------------- ### getPostContext() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets source code after the context line. ```php public function getPostContext(): ?array ``` -------------------------------- ### captureCheckIn() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md Captures a cron/monitor check-in. ```php $checkInId = \Sentry\captureCheckIn('backup-job', \Sentry\CheckInStatus::inProgress()); try { performBackup(); \Sentry\captureCheckIn('backup-job', \Sentry\CheckInStatus::ok(), checkInId: $checkInId); } catch (\Exception $e) { \Sentry\captureCheckIn('backup-job', \Sentry\CheckInStatus::error(), checkInId: $checkInId); throw $e; } ``` -------------------------------- ### Counter metric example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Records a counter metric, incrementing by a specified value with optional attributes and unit. ```php \Sentry\traceMetrics()->count( 'http.client.requests', 1, ['method' => 'GET', 'status_code' => 200] ); ``` -------------------------------- ### Gauge metric example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Records a gauge metric, representing a current value snapshot with optional attributes and unit. ```php \Sentry\traceMetrics()->gauge( 'queue.size', queueLength(), ['queue' => 'background_jobs'] ); ``` -------------------------------- ### Transaction::getDynamicSamplingContext() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the dynamic sampling context for propagating decisions to downstream services. ```php public function getDynamicSamplingContext(): DynamicSamplingContext ``` -------------------------------- ### ClientBuilder constructor signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Initializes a new ClientBuilder, optionally with pre-configured options. ```php public function __construct(?Options $options = null) ``` -------------------------------- ### Transaction::getMetadata() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets transaction metadata (sample rate, tags, etc.). ```php public function getMetadata(): TransactionMetadata ``` -------------------------------- ### Configuration Source: https://github.com/getsentry/sentry-php/blob/master/README.md Initialize the SDK as early as possible in your application. ```php \Sentry\init(['dsn' => '___PUBLIC_DSN___' ]); ``` -------------------------------- ### Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md The constructor for the Client class. ```php public function __construct( Options $options, TransportInterface $transport, ?string $sdkIdentifier = null, ?string $sdkVersion = null, ?RepresentationSerializerInterface $representationSerializer = null, ?LoggerInterface $logger = null ) ``` -------------------------------- ### continueTrace() Example Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md Continues an incoming trace from propagation headers. ```php $context = \Sentry\continueTrace( $_SERVER['HTTP_SENTRY_TRACE'] ?? '', $_SERVER['HTTP_BAGGAGE'] ?? '' ); $transaction = \Sentry\startTransaction($context); ``` -------------------------------- ### Frame Methods - getPreContext() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets source code before the context line. ```php public function getPreContext(): ?array ``` -------------------------------- ### Safe Callbacks Best Practice Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example of implementing a safe 'before_send' callback that handles exceptions internally to prevent event dropping. ```php \Sentry\init([ 'before_send' => function (\Sentry\Event $event) { try { // Process event return $event; } catch (\Exception $e) { // Log but don't throw - returning null drops the event error_log("Error in before_send: {$e->getMessage()}"); return null; } } ]); ``` -------------------------------- ### ClientBuilder::getOptions() method signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Returns the current options configuration of the builder. ```php public function getOptions(): Options ``` -------------------------------- ### Event Capture Error Handling Best Practice Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example of handling potential errors during event capture using captureException. ```php try { $eventId = \Sentry\captureException($exception); if ($eventId === null) { // Event was filtered or transport failed error_log('Event not sent to Sentry'); } } catch (\Exception $e) { // Unexpected error in event capture error_log('Unexpected error capturing event: ' . $e->getMessage()); } ``` -------------------------------- ### Example Handling for JsonException Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Demonstrates catching `JsonException` during event serialization when dealing with non-serializable objects or circular references. ```php try { // Serialize a non-JSON-friendly object $event->setExtra('data', $objectWithCircularRef); \Sentry\captureEvent($event); } catch (\Sentry\Exception\JsonException $e) { // Handle serialization failure error_log('Failed to serialize event: ' . $e->getMessage()); } ``` -------------------------------- ### Capture an exception Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md Example of capturing an exception using a try-catch block. ```php try { throw new Exception('Something went wrong'); } catch (Exception $e) { \Sentry\captureException($e); } ``` -------------------------------- ### Get Current Hub and Client Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Demonstrates how to retrieve the current Hub instance and its associated client. ```php $hub = \Sentry\SentrySdk::getCurrentHub(); $client = $hub->getClient(); ``` -------------------------------- ### TransactionContext Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes a new TransactionContext. ```php public function __construct( string $name = self::DEFAULT_NAME, ?bool $parentSampled = null, ?TransactionMetadata $metadata = null ) ``` -------------------------------- ### Registering Error Handlers (Before) Source: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md Example of how error handlers were registered in previous versions of the Sentry PHP SDK. ```php $errorHandler = new Raven_ErrorHandler($client); $errorHandler->registerErrorHandler(); $errorHandler->registerExceptionHandler(); $errorHandler->registerShutdownFunction(); ``` -------------------------------- ### Transport Error Recovery Best Practice Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example demonstrating Sentry's automatic transport retries and manual flush with timeout. ```php // Sentry handles transport retries automatically $client = \Sentry\ClientBuilder::create([ 'send_attempts' => 3, // Retry failed sends 'http_timeout' => 5 // Prevent indefinite hangs ])->getClient(); $eventId = $client->captureException($exception); // Force flush with timeout $result = $client->flush(timeout: 10); if (!$result->isSuccessful()) { error_log('Failed to flush events to Sentry'); } ``` -------------------------------- ### getId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the event ID. ```php public function getId(): EventId ``` -------------------------------- ### init() Method Signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Initializes the SDK by creating a new hub instance. ```php public static function init(): HubInterface ``` -------------------------------- ### getMessageParams() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets parameters for message formatting. ```php public function getMessageParams(): array ``` -------------------------------- ### getLogger() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the logger name for the event. ```php public function getLogger(): ?string ``` -------------------------------- ### Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Private constructor. Use `createFromString()` to instantiate. ```php private function __construct( string $scheme, string $host, int $port, string $projectId, string $path, string $publicKey, ?int $orgId = null ) ``` -------------------------------- ### startTransaction() Method Signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Signature for the startTransaction method, which starts a new transaction for distributed tracing. ```php public function startTransaction( TransactionContext $context, array $customSamplingContext = [] ): Transaction ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/errors.md Example of enabling debug logging in the Sentry PHP SDK by configuring a Monolog logger. ```php $logger = new \Monolog\Logger('sentry'); $logger->pushHandler(new \Monolog\Handler\ErrorLogHandler()); \Sentry\init([ 'logger' => $logger, 'debug' => true // If available in your version ]); ``` -------------------------------- ### Transaction::initSpanRecorder() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes the span recorder for tracking child spans. ```php public function initSpanRecorder(int $maxSpans = 1000): self ``` -------------------------------- ### EventHint::getOriginalEvent() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the original event from the EventHint. ```php public function getOriginalEvent(): ?Event ``` -------------------------------- ### EventHint::getOriginalException() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the original exception from the EventHint. ```php public function getOriginalException(): ?Throwable ``` -------------------------------- ### Transaction::initProfiler() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes profiling for this transaction. ```php public function initProfiler(): Profiler ``` -------------------------------- ### getParentSpanId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the parent span ID. ```php public function getParentSpanId(): ?string ``` -------------------------------- ### getColumnNo() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the column number. ```php public function getColumnNo(): ?int ``` -------------------------------- ### getStatus() Method Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the span status. ```php public function getStatus(): ?SpanStatus ``` -------------------------------- ### SpanContext Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes a new SpanContext. ```php public function __construct( ?string $operation = null, ?string $description = null, ?string $traceId = null, ?string $parentSpanId = null, ?bool $sampled = null ) ``` -------------------------------- ### getMessageFormatted() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the pre-formatted message (after parameter substitution). ```php public function getMessageFormatted(): ?string ``` -------------------------------- ### getTransaction() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Gets the transaction name (operation identifier). ```php public function getTransaction(): ?string ``` -------------------------------- ### getPath() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the path component. ```php public function getPath(): string ``` -------------------------------- ### getPort() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the port number. ```php public function getPort(): int ``` -------------------------------- ### Transaction Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes a new Transaction object. ```php public function __construct( TransactionContext $context, ?HubInterface $hub = null ) ``` -------------------------------- ### Transaction::getName() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the transaction name. ```php public function getName(): string ``` -------------------------------- ### ClientBuilder::create() method signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Creates a new ClientBuilder from an options array. ```php public static function create(array $options = []): self ``` -------------------------------- ### getOsContext() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Retrieves the operating system context information set for the event. ```php public function getOsContext(): ?OsContext ``` -------------------------------- ### ExceptionDataBag::getValue() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the exception message. ```php public function getValue(): string ``` -------------------------------- ### PropagationContext::getSpanId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the span ID for this context. ```php public function getSpanId(): string ``` -------------------------------- ### PropagationContext::getTraceId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the trace ID for this context. ```php public function getTraceId(): string ``` -------------------------------- ### init() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/global-functions.md Initializes the Sentry SDK with configuration options. ```php function init(array $options = []): void ``` ```php \Sentry\init([ 'dsn' => 'https://key@sentry.io/project', 'environment' => 'production', 'traces_sample_rate' => 0.1, 'profiles_sample_rate' => 0.1 ]); ``` -------------------------------- ### getAbsolutePath() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the absolute file path. ```php public function getAbsolutePath(): ?string ``` -------------------------------- ### Severity Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Initializes a new Severity instance. ```php public function __construct(string $value = self::INFO) ``` -------------------------------- ### SpanContext::getTraceId() Method Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the trace ID. ```php public function getTraceId(): ?string ``` -------------------------------- ### Transaction::getProfiler() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the current profiler, if initialized. ```php public function getProfiler(): ?Profiler ``` -------------------------------- ### getPublicKey() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the authentication public key. ```php public function getPublicKey(): string ``` -------------------------------- ### getProjectId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the Sentry project ID. ```php public function getProjectId(): string ``` -------------------------------- ### Span Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Initializes a new Span object. ```php public function __construct(SpanContext $context) ``` -------------------------------- ### toBaggage() Method Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Generates baggage header value for dynamic sampling context propagation. ```php public function toBaggage(): string ``` -------------------------------- ### isInApp() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets whether this frame is in the application code. ```php public function isInApp(): ?bool ``` -------------------------------- ### Running tests Source: https://github.com/getsentry/sentry-php/blob/master/CONTRIBUTING.md Runs tests using PHPUnit. ```bash vendor/bin/phpunit ``` -------------------------------- ### Frame Methods - getMethod() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the method name. ```php public function getMethod(): ?string ``` -------------------------------- ### Stacktrace Constructor Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Initializes a new Stacktrace with an array of frames. ```php public function __construct(array $frames = []) ``` -------------------------------- ### Frame Methods - getClass() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the class name. ```php public function getClass(): ?string ``` -------------------------------- ### Frame Methods - getFunctionName() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the function/method name. ```php public function getFunctionName(): ?string ``` -------------------------------- ### Frame Methods - getLineno() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the line number. ```php public function getLineno(): ?int ``` -------------------------------- ### getOtlpTracesEndpointUrl() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the OpenTelemetry traces endpoint URL. ```php public function getOtlpTracesEndpointUrl(): ?string ``` -------------------------------- ### getOrgId() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the organization ID (for SaaS DSNs). ```php public function getOrgId(): ?int ``` -------------------------------- ### Span::setDescription() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Sets the span description. ```php public function setDescription(string $description): self ``` -------------------------------- ### Configuration Quick Reference Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/README.md A quick reference for common Sentry SDK configuration options. ```php \Sentry\init([ // Core 'dsn' => 'https://key@sentry.io/project', 'environment' => 'production', 'release' => 'v1.0.0', // Sampling 'sample_rate' => 0.95, 'traces_sample_rate' => 0.1, 'profiles_sample_rate' => 0.01, // Advanced 'max_breadcrumbs' => 100, 'attach_stacktrace' => false, 'send_default_pii' => false, // Transport 'http_timeout' => 5, 'http_compression' => true ]); ``` -------------------------------- ### ClientBuilder::setHttpClient() method signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Sets a custom HTTP client for the builder. ```php public function setHttpClient(HttpClientInterface $httpClient): self ``` -------------------------------- ### captureException() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/client.md Captures an exception and sends it to Sentry. ```php public function captureException( \Throwable $exception, ?Scope $scope = null, ?EventHint $hint = null ): ?EventId ``` ```php try { throw new \Exception('Database connection failed'); } catch (\Exception $e) { $client->captureException($e); } ``` -------------------------------- ### Frame Methods - getContextLine() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the source code line. ```php public function getContextLine(): ?string ``` -------------------------------- ### Frame Methods - getVars() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets local variables at the frame. ```php public function getVars(): array ``` -------------------------------- ### Span::getOperation() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Gets the operation name (e.g., 'db.query', 'http.client'). ```php public function getOperation(): ?string ``` -------------------------------- ### Frame Methods - getFilename() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the file name or path. ```php public function getFilename(): ?string ``` -------------------------------- ### getModules() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Retrieves the loaded modules and their versions set for the event. ```php public function getModules(): array ``` -------------------------------- ### getFingerprint() Method Signature Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/hub-scope.md Gets the fingerprint. ```php public function getFingerprint(): array ``` -------------------------------- ### setStartTimestamp() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/event.md Sets the start timestamp for transaction events. Used to calculate duration. ```php public function setStartTimestamp(?float $startTimestamp): self ``` -------------------------------- ### Static Factory Methods Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/logs-metrics.md Provides static factory methods for creating various units. ```php public static function nanosecond(): self public static function microsecond(): self public static function millisecond(): self public static function second(): self public static function minute(): self public static function hour(): self public static function day(): self public static function week(): self public static function byte(): self public static function kilobyte(): self public static function megabyte(): self public static function gigabyte(): self public static function terabyte(): self public static function petabyte(): self public static function percent(): self public static function hertz(): self public static function kilohertz(): self public static function megahertz(): self public static function gigahertz(): self public static function ratio(): self ``` -------------------------------- ### DynamicSamplingContext Methods Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/types.md Dynamic sampling context for trace propagation. ```php public function toW3CHeaderFormat(): string public function toSentryHeaderFormat(): string public static function fromHeaders(array $headers): ?self public static function fromTransaction(Transaction $transaction, HubInterface $hub): self ``` -------------------------------- ### ExceptionDataBag::getMechanism() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the ExceptionMechanism object associated with the exception, if available. ```php public function getMechanism(): ?ExceptionMechanism ``` -------------------------------- ### getAppPath and setAppPath Methods Removal Source: https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md The getAppPath and setAppPath methods have been removed from Raven_Client. Use Options::getProjectRoot and Options::setProjectRoot instead. ```php $client->getAppPath(); $client->setAppPath(...); ``` ```php use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getProjectRoot(); $options->setProjectRoot(...); ``` -------------------------------- ### ExceptionDataBag::getStacktrace() Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/dsn-utilities.md Gets the Stacktrace object associated with the exception, if available. ```php public function getStacktrace(): ?Stacktrace ``` -------------------------------- ### finish() Method Source: https://github.com/getsentry/sentry-php/blob/master/_autodocs/api-reference/tracing.md Finishes the span. Must be called before parent transaction is finished. ```php public function finish(?float $endTimestamp = null): void ```