treblle/oaas-laravel
Composer 安装命令:
composer require treblle/oaas-laravel
包简介
Laravel SDK for Treblle Observability as a Service (OaaS)
README 文档
README
Website • Documentation • Pricing
Treblle is an API intelligence platfom that helps developers, teams and organizations understand their APIs from a single integration point.
Treblle Laravel OaaS SDK
A Laravel SDK for Treblle Observability as a Service (OaaS). Easily retrieve and filter requests from APIs monitored by Treblle and expose that data to your end-customers.
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
- Guzzle HTTP 7.0 or higher
Installation
Install the package via Composer:
composer require treblle/oaas-laravel
Laravel Setup
The package will automatically register its service provider. Publish the configuration file:
php artisan vendor:publish --tag=treblle-oaas-config
Configuration
Add your Treblle OaaS API token to your .env file:
TREBLLE_OAAS_API_TOKEN=your_api_token_here
You can obtain your API token from the Treblle Identity Dashboard under Developer Settings.
Usage
Basic Usage
To use the SDK you will need to pass your Workspace ID (found in Workspace Settings on the Treblle Dashboard) and your API ID (found in API Settings on the Treblle Dashboard)
use Treblle\OaaS\Facades\TreblleOaaS; // Get all requests for a customer $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->get(); foreach ($requests as $request) { echo "Request: {$request->getMethod()} {$request->getPath()}" . PHP_EOL; echo "Status: {$request->getHttpCode()}" . PHP_EOL; echo "Load Time: {$request->getLoadTimeMs()}ms" . PHP_EOL; }
Advanced Filtering
The SDK provides a fluent API for filtering requests:
use Treblle\OaaS\Enums\HttpMethod; use Treblle\OaaS\Enums\Device; use Treblle\OaaS\Enums\TimePeriod; $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->whereMethod(HttpMethod::POST) ->whereDevice(Device::IOS) ->whereTimePeriod(TimePeriod::LAST_24_HOURS) ->whereSuccessful() // 2xx status codes ->withoutProblems() ->sortByLoadTimeSlowest() ->limit(10) ->get(); // Custom time range filtering (alternative to whereTimePeriod) $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->whereTimeRange('2025-09-01 00:00:00', '2025-09-30 23:59:59') ->get(); // Get all-time requests $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->allTime() ->get(); // Search checkout requests for specific payment methods $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->withParams('stripe') // Find requests with Stripe payment data ->whereMethod(HttpMethod::POST) ->get(); // Find user registration attempts with Gmail addresses $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->withParams('@gmail.com') // Partial match on email domains ->get();
Pagination
// Get paginated results $page1 = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->paginate(perPage: 20, page: 1); echo "Total requests: {$page1->total()}" . PHP_EOL; echo "Current page: {$page1->currentPage()} / {$page1->totalPages()}" . PHP_EOL; // Check if there are more pages if ($page1->hasNextPage()) { $page2 = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->paginate(perPage: 20, page: 2); }
Request Details
Get detailed information about a specific request:
$requestDetails = TreblleOaaS::getRequest('workspace-id', 'api-id', 'request-id'); echo "Request URL: {$requestDetails->getRequestUrl()}" . PHP_EOL; echo "Response Body: " . json_encode($requestDetails->getResponseBody()) . PHP_EOL; echo "Server Info: " . json_encode($requestDetails->getServerInfo()) . PHP_EOL; // Check compliance and security if ($requestDetails->hasProblem()) { echo "Request has problems: " . json_encode($requestDetails->getProblem()) . PHP_EOL; } $compliance = $requestDetails->getComplianceReport(); echo "Compliance Status: {$compliance['status']}" . PHP_EOL; echo "Compliance Score: {$compliance['overall_percentage']}%" . PHP_EOL;
Available Filters
| Filter Method | Description |
|---|---|
whereCustomer(string $customerId) |
Filter by external user/customer ID |
whereLocation(string $location) |
Filter by geographic location |
withParams(string $params) |
Filter by request parameters |
whereMethod(HttpMethod $method) |
Filter by HTTP method |
whereDevice(Device $device) |
Filter by device type (iOS/Android/Desktop) |
whereHttpCode(int|string $code) |
Filter by HTTP status code |
whereSuccessful() |
Filter for 2xx responses |
whereClientError() |
Filter for 4xx responses |
whereServerError() |
Filter for 5xx responses |
whereTimePeriod(TimePeriod $period) |
Filter by time period |
whereTimeRange(string $start, string $end) |
Filter by custom date range (YYYY-MM-DD HH:MM:SS format) |
allTime() |
Get all requests regardless of time period |
withProblems() |
Only requests with problems |
withoutProblems() |
Only requests without problems |
Sorting Options
| Sort Method | Description |
|---|---|
sortByCreatedAtDesc() |
Most recent first (default) |
sortByCreatedAtAsc() |
Oldest first |
sortByLoadTimeFastest() |
Fastest requests first |
sortByLoadTimeSlowest() |
Slowest requests first |
Helper Methods
Request summary objects provide helpful methods:
foreach ($requests as $request) { // Status checks if ($request->isSuccessful()) { echo "✅ Successful request" . PHP_EOL; } elseif ($request->hasClientError()) { echo "⚠️ Client error: {$request->getHttpCode()}" . PHP_EOL; } elseif ($request->hasServerError()) { echo "❌ Server error: {$request->getHttpCode()}" . PHP_EOL; } // Performance checks if ($request->isLoadTimeFast()) { echo "⚡ Fast response: {$request->getLoadTimeMs()}ms" . PHP_EOL; } else { echo "🐌 Slow response: {$request->getLoadTimeMs()}ms" . PHP_EOL; } // Customer info if ($displayName = $request->getCustomerDisplayName()) { echo "Customer: {$displayName}" . PHP_EOL; } // Security info echo "Threat Level: {$request->getThreatLevel()}" . PHP_EOL; echo "Has Auth: " . ($request->hasAuth() ? 'Yes' : 'No') . PHP_EOL; }
Configuration Options
The configuration file allows you to customize various aspects:
return [ // API Configuration 'api_token' => env('TREBLLE_OAAS_API_TOKEN'), 'base_url' => env('TREBLLE_OAAS_BASE_URL', 'https://api-forge.treblle.com/api/v1'), // Request Timeouts 'timeout' => env('TREBLLE_OAAS_TIMEOUT', 30), 'connect_timeout' => env('TREBLLE_OAAS_CONNECT_TIMEOUT', 10), // Pagination Defaults 'default_limit' => env('TREBLLE_OAAS_DEFAULT_LIMIT', 20), 'max_limit' => env('TREBLLE_OAAS_MAX_LIMIT', 50), ];
Error Handling
The SDK throws OaaSException for API errors:
use Treblle\OaaS\Exceptions\OaaSException; try { $requests = TreblleOaaS::requests('workspace-id', 'api-id') ->whereCustomer('customer-123') ->get(); } catch (OaaSException $e) { echo "API Error: {$e->getMessage()}" . PHP_EOL; echo "HTTP Status: {$e->getCode()}" . PHP_EOL; if ($e->hasResponse()) { $responseData = $e->getResponseData(); echo "Response: " . json_encode($responseData) . PHP_EOL; } }
Data Models
The SDK provides rich data models:
RequestCollection- Collection of request summaries with paginationRequestSummary- Summary information about a requestRequestDetails- Complete request details including headers, body, compliance, etc.PaginationMeta- Pagination metadataPaginationLinks- Pagination navigation links
License
This package is open-sourced software licensed under the MIT license.
Support
For support, please visit Treblle's documentation or contact support@treblle.com.
treblle/oaas-laravel 适用场景与选型建议
treblle/oaas-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.71k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「monitoring」 「sdk」 「laravel」 「intelligence」 「treblle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 treblle/oaas-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 treblle/oaas-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 treblle/oaas-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
A PSR-7 compatible library for making CRUD API endpoints
APM agent for laravel projects to monitor the application with elastic apm tools.
统计信息
- 总下载量: 14.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-27