1. Go to this page and download the library: Download gemvc/apm-tracekit 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/ */
gemvc / apm-tracekit example snippets
// Get APM instance from Request
$apm = $request->apm;
if ($apm !== null && $apm->isEnabled()) {
// Start a custom span
$span = $apm->startSpan('custom-operation', [
'custom.attribute' => 'value'
]);
try {
// Your code here
$result = doSomething();
// End span with success
$apm->endSpan($span, ['result' => 'success'], \Gemvc\Core\Apm\ApmInterface::STATUS_OK);
} catch (\Throwable $e) {
// Record exception
$apm->recordException($span, $e);
$apm->endSpan($span, ['result' => 'error'], \Gemvc\Core\Apm\ApmInterface::STATUS_ERROR);
throw $e;
}
}
use Gemvc\Core\Apm\Providers\TraceKit\TraceKitToolkit;
// Initialize toolkit
$toolkit = new TraceKitToolkit();
// Register new service (first-time setup)
$response = $toolkit->registerService('[email protected]', 'My Organization');
if ($response->response_code === 200) {
$sessionId = $response->data['session_id'];
// User receives verification code via email
}
// Verify code and activate service
$response = $toolkit->verifyCode($sessionId, '123456');
if ($response->response_code === 200) {
$apiKey = $response->data['api_key'];
// Save to .env: TRACEKIT_API_KEY=$apiKey
}
// Send periodic health heartbeat (non-blocking)
$toolkit->sendHeartbeatAsync('healthy', [
'memory_usage_mb' => round(memory_get_usage(true) / 1024 / 1024, 2),
'cpu_load' => sys_getloadavg()[0] ?? 0,
]);
// Get service metrics
$metrics = $toolkit->getMetrics('1h');
// Create webhook for alerts
$toolkit->createWebhook(
'production-alerts',
'https://example.com/webhooks/alerts',
['alert.created', 'alert.resolved'],
true
);
bash
php vendor/bin/tracekit init
bash
php vendor/bin/tracekit init
bash
php vendor/bin/tracekit init
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.