VOOZH about

URL: https://deepwiki.com/hypervel/sentry/2.3-transport-and-http-client

⇱ Transport and HTTP Client | hypervel/sentry | DeepWiki


Loading...
Menu

Transport and HTTP Client

Purpose and Scope

This document covers the transport layer and HTTP client implementation used by the Hypervel Sentry integration to communicate with the Sentry.io platform. Specifically, it documents the custom HttpPoolTransport for asynchronous event submission using connection pooling, the Pool class for managing HTTP connections, and the HttpClientFactory for creating HTTP clients with SDK identification.

For information about how the Hub uses these components to capture and send events, see Hub and Client Management. For configuration of transport and pooling options, see Configuration.


Overview

The Hypervel Sentry integration implements a custom transport layer to enable efficient, asynchronous communication with Sentry.io. Unlike synchronous transports that block request processing, the HttpPoolTransport leverages Hypervel's connection pooling capabilities to send events without blocking coroutines. This design is critical for high-performance async applications where blocking I/O would significantly degrade throughput.

The transport layer consists of three main components:

ComponentPurposeKey Benefit
HttpPoolTransportSentry transport implementationAsync event submission without blocking
PoolConnection pool managerReuses HTTP connections efficiently
HttpClientFactoryHTTP client factoryCreates clients with SDK version headers

Sources: src/SentryServiceProvider.php1-143


Architecture Overview

The following diagram illustrates how the transport layer components relate to each other and to the Sentry SDK:


Sources: src/SentryServiceProvider.php65-75 src/HttpClient/HttpClientFactory.php1-19


HttpPoolTransport

The HttpPoolTransport is a custom implementation of Sentry's TransportInterface that uses connection pooling for asynchronous event submission. Instead of creating a new HTTP connection for each event, it delegates to a managed connection pool, allowing multiple events to be sent concurrently without resource exhaustion.

Registration and Configuration

The transport is registered during the service provider's registration phase by extending the ClientBuilder class. This approach allows the custom transport to replace the SDK's default transport seamlessly:


The transport is configured at src/SentryServiceProvider.php65-75:

  1. A new Pool instance is created with:

    • Sentry SDK options from the ClientBuilder
    • The application container for dependency resolution
    • Pool-specific configuration from config.pools.sentry
  2. The HttpPoolTransport wraps the Pool instance

  3. The transport is set on the ClientBuilder using setTransport()

Sources: src/SentryServiceProvider.php65-75

Event Submission Flow

When the Sentry client needs to send an event, the flow proceeds as follows:


The key advantage is that the Pool::send() method is non-blocking, allowing the coroutine to continue processing while the event is transmitted in the background.

Sources: src/SentryServiceProvider.php65-75


Connection Pool (Pool)

The Pool class manages a pool of reusable HTTP connections for communicating with Sentry.io. It is instantiated with three dependencies:

ParameterTypePurpose
$optionsOptionsSentry SDK options (DSN, environment, etc.)
$appApplicationContainer for resolving dependencies
$poolConfigarrayPool-specific configuration (size, timeouts, etc.)

Configuration Source

Pool configuration is read from the pools.sentry configuration key. This allows operators to tune connection pool behavior based on application needs:

Configuration Path: config.pools.sentry

Typical configuration might include:

  • min_connections - Minimum connections to maintain
  • max_connections - Maximum connections to create
  • wait_timeout - How long to wait for an available connection
  • max_idle_time - When to close idle connections

Sources: src/SentryServiceProvider.php70

Pool Lifecycle


Sources: src/SentryServiceProvider.php67-72


HttpClientFactory

The HttpClientFactory creates instances of HttpClient with proper SDK identification headers. This ensures that Sentry.io can track which SDK and version is sending events, enabling version-specific features and diagnostics.

Factory Implementation

The factory is bound to the HttpClientInterface in the service container and resolves the HttpClient class:


Implementation: src/HttpClient/HttpClientFactory.php10-19

The factory's __invoke() method receives the application container and creates an HttpClient with:

  • SDK Identifier: Retrieved from Version::getSdkIdentifier() (e.g., "sentry.php.hypervel")
  • SDK Version: Retrieved from Version::getSdkVersion() (e.g., parsed from composer.json)

SDK Version Headers

The HttpClient includes these values in HTTP headers when communicating with Sentry.io:

HeaderValue SourcePurpose
User-AgentSDK identifier + versionIdentifies the SDK to Sentry.io
X-Sentry-SDKSDK identifier + versionParsed by Sentry for analytics

This enables Sentry to:

  • Track SDK adoption and version distribution
  • Enable/disable features based on SDK capabilities
  • Provide version-specific documentation links
  • Debug SDK-specific issues

Sources: src/HttpClient/HttpClientFactory.php1-19


Integration with Service Provider

The transport and HTTP client components are registered during the SentryServiceProvider::register() phase, before any features are booted. This ensures that when features need to capture events, the transport layer is fully configured.

Registration Order


Key Points:

  1. Line 65-75: The ClientBuilder is extended first, injecting the custom transport
  2. Line 77-81: The ClientInterface is bound to resolve from the configured builder
  3. Line 83-85: Factory bindings are registered for builder, hub, and HTTP client
  4. Line 86: Only after transport setup do features get registered

This ordering ensures that features like CacheFeature, QueueFeature, and RedisFeature can immediately start capturing spans and events without transport initialization failures.

Sources: src/SentryServiceProvider.php63-87


Transport Configuration Flow

The following diagram shows how configuration flows from various sources into the transport layer:


Configuration Keys:

Key PathComponentPurpose
sentry.dsnOptionsSentry project DSN
sentry.environmentOptionsEnvironment name (production, staging, etc.)
sentry.traces_sample_rateOptionsSampling rate for transactions
pools.sentryPoolConnection pool configuration

Sources: src/SentryServiceProvider.php65-75 src/HttpClient/HttpClientFactory.php10-19


Dependency Resolution

The transport layer components use Laravel/Hypervel's dependency injection container for resolution. The following table shows the bindings:

AbstractConcreteResolution Strategy
ClientBuilder::classClientBuilderFactory::classFactory pattern via bind()
ClientInterface::classResolved via ClientBuilder::getClient()Closure binding at src/SentryServiceProvider.php77-81
HttpClientInterface::classHttpClientFactory::classFactory pattern via bind()

When any component requests a ClientBuilder, the container invokes ClientBuilderFactory, which creates a builder pre-configured with:

Sources: src/SentryServiceProvider.php63-87 src/HttpClient/HttpClientFactory.php1-19


Benefits of Custom Transport

The custom transport implementation provides several advantages over the SDK's default HTTP transport:

BenefitDescriptionImplementation
Non-blocking I/OEvents are sent without blocking the current coroutineConnection pool operates asynchronously
Connection ReuseHTTP connections are reused across multiple eventsPool manages connection lifecycle
Resource EfficiencyLimited number of connections prevents resource exhaustionPool enforces max connection limits
Backpressure HandlingWhen pool is exhausted, sends can wait or fail gracefullyPool configuration controls wait behavior
PerformanceReduced latency for event submissionPersistent connections eliminate handshake overhead

This design is essential for Hypervel applications that use Swoole or other async runtimes, where blocking I/O would create significant performance bottlenecks.

Sources: src/SentryServiceProvider.php65-75


Summary

The transport and HTTP client layer of the Hypervel Sentry integration consists of:

  1. HttpPoolTransport - Custom transport implementation using connection pooling for async event submission
  2. Pool - Connection pool manager configured via pools.sentry configuration
  3. HttpClientFactory - Factory creating HTTP clients with SDK version identification

These components are registered during SentryServiceProvider::register() and work together to provide efficient, non-blocking communication with Sentry.io. The connection pooling strategy ensures that high-throughput async applications can send telemetry data without performance degradation.

Sources: src/SentryServiceProvider.php1-143 src/HttpClient/HttpClientFactory.php1-19