PHP code example of tiden / telemetry-php
1. Go to this page and download the library: Download tiden/telemetry-php 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/ */
tiden / telemetry-php example snippets
use Tiden\Sdk;
Sdk::init([
'dsn' => getenv('TIDEN_DSN'), // http://<publicKey>@<host:ingestPort>/<projectId>
'release' => '[email protected] ',
'environment' => 'production',
// 'send_default_pii' => false, // default: scrub likely-PII before send
// 'http_timeout' => 2.0, // seconds per send; connect timeout is min(this, 1 s)
// 'max_envelope_bytes' => 921600, // size cap, see "Envelope size cap"
// 'retry_after_default' => 60.0, // pause after a 429 without Retry-After
// 'on_transport_failure' => fn (array $failure) => error_log(json_encode($failure)),
]);
// With captureGlobals (default), uncaught exceptions + fatals are reported
// automatically. Manual capture:
try {
risky();
} catch (\Throwable $e) {
Sdk::captureException($e);
}
Sdk::captureMessage('checkout completed', 'info');
Sdk::addBreadcrumb(new \Tiden\Breadcrumb('cache miss', category: 'cache'));
Sdk::configureScope(fn ($s) => $s->setTag('tenant', 'acme'));
Sdk::pushScope();
try {
Sdk::configureScope(fn ($s) => $s->setTag('job', 'send-mail'));
runJob();
} finally {
Sdk::popScope();
}
Sdk::configureScope(fn ($s) => $s->clearBreadcrumbs()); // tags, user, extra stay
// Send a hand-built event through the current scope. It is sent as given:
// set event_id, timestamp and platform yourself. Returns its event_id.
Sdk::captureEvent([
'event_id' => \Tiden\EventNormalizer::uuid4(),
'timestamp' => microtime(true),
'platform' => 'php',
'level' => 'warning',
'message' => 'custom',
]);
$transport = new \Tiden\Transport\NullTransport;
Sdk::init(['dsn' => 'http://key@localhost/1'], captureGlobals: false, transport: $transport);
// $transport->envelopes holds every serialized envelope.
/** @param array{reason: 'curl_error'|'http_error'|'rate_limited'|'suppressed'|'envelope_too_large', status: int|null, bytes: int, curl_errno: int|null} $failure */
bash
composer