PHP code example of konzume / splunk-observability-sdk
1. Go to this page and download the library: Download konzume/splunk-observability-sdk 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/ */
konzume / splunk-observability-sdk example snippets
// bootstrap/app.php
use Konzume\SplunkObservability\Middleware\RequestLifecycleMiddleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(/* ... */)
->withMiddleware(function (Middleware $middleware): void {
$middleware->prepend(RequestLifecycleMiddleware::class);
})
->withExceptions(/* ... */)
->create();
use Konzume\SplunkObservability\Facades\Splunk;
Splunk::event('payment_completed', [
'tenant_id' => $tenantId,
'amount' => $amount,
'currency' => $currency,
]);
Splunk::metric('checkout_time', $durationMs, ['provider' => 'stripe']);
$result = Splunk::trace('payment_flow', function () use ($order) {
return $paymentGateway->charge($order);
});
Splunk::setTenantId((string) $request->header('X-Tenant-Id'));
Splunk::setUserId((string) $apiKey->user_id);
use Illuminate\Support\Facades\Log;
Log::channel('splunk')->info('order placed', ['order_id' => $order->id]);
Log::channel('splunk')->error('payment declined', ['gateway' => 'stripe', 'code' => $e->getCode()]);
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'splunk'],
],
],
use Illuminate\Support\Facades\Http;
Http::withToken($token)->post('https://api.partner.com/charge', $payload);
// → captured as an http_client event: method, URL (sanitized), status, duration, sizes
Mail::to($user)->send(new OrderShipped($order));
// → captured as a mail event
'sampling' => [
'requests' => 1.0, // 100% of requests
'queries' => 1.0,
'exceptions' => 1.0, // never sample exceptions out
'queues' => 1.0,
'force_sample_on_error' => true,
'force_sample_when_slow' => true,
],
$this->app->singleton(\Konzume\SplunkObservability\Contracts\Exporter::class, MyDatadogExporter::class);
bash
php artisan vendor:publish --tag=splunk-observability-config