Skip to content

Latest commit

 

History

History
99 lines (68 loc) · 2.31 KB

QUICKSTART.md

File metadata and controls

99 lines (68 loc) · 2.31 KB

Quickstart

Get telemetry flowing from a PHP application in under 5 minutes.

1. Install

composer require telemetryflow/php-native

Need the gRPC transport? Install the grpc PHP extension. The HTTP transport works with no extra extensions.

2. Configure

Create a .env (or export these variables):

TELEMETRYFLOW_API_KEY_ID=tfk_your_key_id
TELEMETRYFLOW_API_KEY_SECRET=tfs_your_key_secret
TELEMETRYFLOW_ENDPOINT=localhost:4317
TELEMETRYFLOW_SERVICE_NAME=my-php-service
TELEMETRYFLOW_SERVICE_VERSION=1.0.0
TELEMETRYFLOW_ENVIRONMENT=development
TELEMETRYFLOW_INSECURE=true

3. Initialize & Send Telemetry

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use TelemetryFlow\Core\TelemetryFlow;

$client = TelemetryFlow::newFromEnv();
$client->initialize();

// Metric
$client->incrementCounter('api.requests', 1, ['method' => 'GET']);

// Log
$client->logInfo('Started up', ['version' => '1.0.0']);

// Trace
$spanId = $client->startSpan('handle-request', 'server');
// ... your code ...
$client->endSpan($spanId);

// Always flush on shutdown
$client->shutdown();

4. Point at a Collector

Run the TFO-Collector locally (it listens on :4317 gRPC / :4318 HTTP) and your telemetry appears in the TelemetryFlow dashboard.

Using the Builder

For explicit control:

use TelemetryFlow\Core\Builder;

$client = Builder::create()
    ->withApiKey('tfk_...', 'tfs_...')
    ->withEndpoint('api.telemetryflow.id:4317')
    ->withService('my-app', '2.0.0')
    ->withHttp()                      // or withGrpc()
    ->withSignals(true, true, true)   // metrics, logs, traces
    ->withCustomAttribute('team', 'backend')
    ->build();

$client->initialize();

Laravel

composer require telemetryflow/laravel
php artisan vendor:publish --tag=telemetryflow-config
use TelemetryFlow\Laravel\Facades\TelemetryFlow;

TelemetryFlow::incrementCounter('orders.created');

See the Laravel README for middleware, logging, and Guzzle instrumentation.

Next Steps