1. Go to this page and download the library: Download treblle/treblle-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return [
/*
|--------------------------------------------------------------------------
| Enable / Disable Monitoring
|--------------------------------------------------------------------------
| Set to false to completely disable Treblle. Useful for maintenance windows,
| load testing, or when you want to turn it off without removing middleware.
|
| Env: TREBLLE_ENABLE
| Default: true
*/
'enable' => env('TREBLLE_ENABLE', true),
/*
|--------------------------------------------------------------------------
| Treblle Ingress URL
|--------------------------------------------------------------------------
| The endpoint Treblle data is sent to. Only change this if you are running
| a self-hosted Treblle instance or pointing at a test endpoint.
|
| Env: TREBLLE_API_URL
| Default: https://ingress.treblle.com
*/
'url' => env('TREBLLE_API_URL', 'https://ingress.treblle.com'),
/*
|--------------------------------------------------------------------------
| SDK Token
|--------------------------------------------------------------------------
| Your Treblle SDK Token. Found in your Treblle account settings.
| Previously called TREBLLE_API_KEY in v5.x.
|
| Env: TREBLLE_SDK_TOKEN
| Required: yes
*/
'sdk_token' => env('TREBLLE_SDK_TOKEN'),
/*
|--------------------------------------------------------------------------
| API Key
|--------------------------------------------------------------------------
| Your Treblle project API Key. Identifies which project this data belongs to.
| Previously called TREBLLE_PROJECT_ID in v5.x.
|
| Env: TREBLLE_API_KEY
| Required: yes
*/
'api_key' => env('TREBLLE_API_KEY'),
/*
|--------------------------------------------------------------------------
| Ignored Environments
|--------------------------------------------------------------------------
| Treblle will not send any data when your app is running in one of these
| environments. Comma-separated list. Compared against app()->environment().
|
| Env: TREBLLE_IGNORED_ENV
| Default: dev,test,testing
*/
'ignored_environments' => env('TREBLLE_IGNORED_ENV', 'dev,test,testing'),
/*
|--------------------------------------------------------------------------
| Masked Fields
|--------------------------------------------------------------------------
| Field names listed here will have their values replaced with asterisks
| before the data leaves your server. Matching is case-insensitive and
| applies to both request body and response body.
|
| The fields below are masked by default. Add your own sensitive fields.
*/
'masked_fields' => [
'password',
'pwd',
'secret',
'password_confirmation',
'cc',
'card_number',
'ccv',
'ssn',
'credit_score',
'api_key',
],
/*
|--------------------------------------------------------------------------
| Excluded Headers
|--------------------------------------------------------------------------
| Headers listed here are completely removed before the data is sent to
| Treblle. Supports exact match, wildcard patterns, and regex.
|
| Examples:
| 'authorization' — exact match (case-insensitive)
| 'x-*' — all headers starting with x-
| '*-token' — all headers ending with -token
| '/^x-(api|auth)-/i' — regex pattern
*/
'excluded_headers' => [],
/*
|--------------------------------------------------------------------------
| Custom Metadata
|--------------------------------------------------------------------------
| Static key/value pairs
// Public API — Project A
Route::middleware(['treblle:api_key_project_a'])->prefix('api/public')->group(function () {
Route::get('/products', [PublicProductController::class, 'index']);
Route::get('/categories', [PublicCategoryController::class, 'index']);
});
// Partner API — Project B
Route::middleware(['treblle:api_key_project_b'])->prefix('api/partner')->group(function () {
Route::get('/orders', [PartnerOrderController::class, 'index']);
Route::post('/webhooks', [PartnerWebhookController::class, 'handle']);
});
// Admin API — Project C
Route::middleware(['treblle:api_key_project_c'])->prefix('api/admin')->group(function () {
Route::get('/analytics', [AdminAnalyticsController::class, 'index']);
});
// Correct — treblle.early runs first, before any transformations
Route::middleware(['treblle.early', 'transform-legacy-format', 'treblle'])->group(function () {
Route::post('/api/v1/orders', [OrderController::class, 'store']);
});
// Wrong — treblle.early after transformation is pointless
Route::middleware(['transform-legacy-format', 'treblle.early', 'treblle'])->group(function () {
Route::post('/api/v1/orders', [OrderController::class, 'store']);
});
// Clients send v1 format, your app works with v2 format internally
Route::middleware(['treblle.early', 'normalize-to-v2', 'treblle'])
->prefix('api/v1')
->group(function () {
Route::post('/users', [UserController::class, 'store']);
});
use Treblle\Laravel\Facades\Treblle;
// Single key/value
Treblle::meta('tenant_id', auth()->user()->tenant_id);
// Multiple key/values at once
Treblle::meta([
'tenant_id' => auth()->user()->tenant_id,
'plan' => auth()->user()->plan,
'trace_id' => $request->header('X-Trace-Id'),
]);
use Treblle\Laravel\Facades\Treblle;
class OrderController extends Controller
{
public function store(Request $request): JsonResponse
{
Treblle::meta([
'tenant_id' => auth()->user()->tenant_id,
'plan' => auth()->user()->plan,
'order_source' => 'api',
]);
// ... create the order
}
}
use Treblle\Laravel\Facades\Treblle;
class AttachTreblleContext
{
public function handle(Request $request, Closure $next)
{
Treblle::meta([
'trace_id' => $request->header('X-Trace-Id', (string) Str::uuid()),
'tenant_id' => $request->header('X-Tenant-Id'),
]);
return $next($request);
}
}
use Treblle\Laravel\Facades\Treblle;
class PaymentService
{
public function charge(array $data): void
{
Treblle::meta('payment_gateway', 'stripe');
// ... process payment
}
}
// config/treblle.php
'excluded_headers' => [
// Exact match (case-insensitive)
'authorization',
'cookie',
'x-api-key',
// Wildcard — all headers starting with x-internal-
'x-internal-*',
// Wildcard — all headers ending with -token
'*-token',
// Wildcard — headers containing -secret-
'*-secret-*',
// Regex — headers matching x-api- or x-auth-
'/^x-(api|auth)-/i',
],
// config/treblle.php
// Override the Treblle ingress endpoint (e.g. for custom deployments or local testing)
'url' => env('TREBLLE_API_URL', 'https://ingress.treblle.com'),
// HTTP methods Treblle will never monitor
'ignored_methods' => ['HEAD', 'OPTIONS'],
// Static metadata sent with every request (per-request metadata merges over this)
'metadata' => [],
// Old (v5.x)
Route::middleware(['treblle:project-id-1'])
// New (v6.0)
Route::middleware(['treblle:api-key-1'])