API Services EventAwareTelemetryService - evansims/openfga-php GitHub Wiki
Event-aware telemetry service that emits domain events. This service extends the base TelemetryService functionality by emitting domain events for operation lifecycle, enabling decoupled observability.
Table of Contents
OpenFGA\Services
public function recordAuthenticationEvent(
string $event,
bool $success,
float $duration,
array $attributes = [],
): void
Record an authentication event with duration and outcome. Tracks authentication-related operations including token acquisition, renewal, and validation. Provides insights into authentication performance and failure patterns.
Name | Type | Description |
---|---|---|
$event |
string |
The authentication event type |
$success |
bool |
Whether the event was successful |
$duration |
float |
Event duration in seconds |
$attributes |
array |
void
public function recordFailure(
OpenFGA\Services\TelemetryContext $context,
Throwable $exception,
mixed $result = NULL,
): void
Record a failed operation with error details. Completes an operation context with failure information, including exception details and any additional error context. This provides structured error tracking for debugging and monitoring.
Name | Type | Description |
---|---|---|
$context |
TelemetryContext |
The operation context from startOperation() |
$exception |
Throwable |
The exception that caused the failure |
$result |
mixed |
Optional partial result data |
void
public function recordHttpRequest(
Psr\Http\Message\RequestInterface $request,
?Psr\Http\Message\ResponseInterface $response = NULL,
?Throwable $exception = NULL,
?float $duration = NULL,
): void
Record an HTTP request/response pair with automatic span management. Handles the complete lifecycle of HTTP request telemetry, including span creation, timing, and completion with response or error details. Ideal for tracking individual API calls.
Name | Type | Description |
---|---|---|
$request |
Psr\Http\Message\RequestInterface |
The HTTP request being tracked |
$response |
Psr\Http\Message\ResponseInterface | null
|
The HTTP response received |
$exception |
Throwable | null
|
Optional exception that occurred |
$duration |
float | null
|
Optional manual duration override |
void
public function recordOperationMetrics(
string $operation,
float $duration,
OpenFGA\Models\StoreInterface|string $store,
?OpenFGA\Models\AuthorizationModelInterface|string|null $model = NULL,
array $attributes = [],
): void
Record operational metrics for performance monitoring. Tracks operation-level metrics including timing, throughput, and contextual information about stores and models. Used for performance analysis and capacity planning.
Name | Type | Description |
---|---|---|
$operation |
string |
The operation name |
$duration |
float |
Operation duration in seconds |
$store |
StoreInterface | string
|
The store context |
$model |
AuthorizationModelInterface | null | string | null
|
Optional model context |
$attributes |
array |
void
public function recordSuccess(OpenFGA\Services\TelemetryContext $context, mixed $result = NULL): void
Record a successful operation with results. Completes an operation context with success information and any relevant result data. This tracks successful operation patterns and performance characteristics.
Name | Type | Description |
---|---|---|
$context |
TelemetryContext |
The operation context from startOperation() |
$result |
mixed |
The operation result data |
void
public function startOperation(
string $operation,
OpenFGA\Models\StoreInterface|string $store,
?OpenFGA\Models\AuthorizationModelInterface|string|null $model = NULL,
array $attributes = [],
): OpenFGA\Services\TelemetryContext
Start tracking a business operation. Creates a new telemetry context for tracking a complete business operation including timing, success/failure status, and contextual information. Returns a context object that should be passed to recordSuccess/recordFailure.
Name | Type | Description |
---|---|---|
$operation |
string |
The operation name |
$store |
StoreInterface | string
|
The store context |
$model |
AuthorizationModelInterface | null | string | null
|
Optional model context |
$attributes |
array |
TelemetryContext
— Context for completing the operation tracking