The logtide/logtide package is the foundation
for all LogTide PHP SDKs. It provides DSN-based configuration, automatic batching,
distributed tracing (W3C Trace Context), breadcrumbs, scopes, and span management.
Installation
Requires PHP 8.1 or higher.
composer require logtide/logtide
For framework-specific integrations, install the corresponding package instead
(it includes logtide/logtide as a dependency):
# Framework packages (pick one)
composer require logtide/logtide-laravel # Laravel 10/11/12
composer require logtide/logtide-symfony # Symfony 6.4/7.x
composer require logtide/logtide-slim # Slim 4
composer require logtide/logtide-wordpress # WordPress Quick Start
<?php
use function LogTide\init;
use function LogTide\info;
use function LogTide\error;
use function LogTide\captureException;
use function LogTide\flush;
$hub = init([
'dsn' => 'https://[email protected]',
'service' => 'api-server',
'environment' => 'production',
'release' => '1.0.0',
]);
// Capture logs
info('Server started', ['port' => 8080]);
error('Query timeout', ['query' => 'SELECT ...', 'duration_ms' => 5000]);
// Capture exceptions
try {
riskyOperation();
} catch (\Throwable $e) {
captureException($e);
}
// Shutdown is auto-handled via register_shutdown_function The DSN (Data Source Name) encodes your API host and project key in a single connection string. You can find it in your LogTide project settings.
Configuration
<?php
use function LogTide\init;
init([
// Required
'dsn' => 'https://[email protected]',
// Recommended
'service' => 'api-server',
'environment' => 'production',
'release' => '1.2.3',
// Batching
'batch_size' => 100, // Max logs per batch (default: 100)
'flush_interval' => 5000, // Flush interval in ms (default: 5000)
'max_buffer_size' => 10000, // Max logs in buffer (default: 10000)
// Reliability
'max_retries' => 3, // Retry attempts (default: 3)
'retry_delay_ms' => 1000, // Initial retry delay in ms (default: 1000)
'circuit_breaker_threshold' => 5, // Failures before open (default: 5)
'circuit_breaker_reset_ms' => 30000, // Reset timeout in ms (default: 30000)
// Tracing
'traces_sample_rate' => 1.0, // 0.0 to 1.0, sample rate for traces
'max_breadcrumbs' => 100, // Max breadcrumbs per scope (default: 100)
// Advanced
'attach_stacktrace' => false, // Attach stacktrace to log events
'send_default_pii' => false, // Send PII (IP, user agent, etc.)
'default_integrations' => true, // Register default error/exception handlers
// Debug
'debug' => false,
]); Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
dsn | string | — | Data Source Name (required) |
service | string | 'unknown' | Service name for log grouping |
environment | string | — | Deployment environment (production, staging, etc.) |
release | string | — | App version for release tracking |
batch_size | int | 100 | Max events per batch |
flush_interval | int | 5000 | Flush interval in milliseconds |
max_buffer_size | int | 10000 | Max events in buffer before dropping |
max_retries | int | 3 | Max retry attempts for failed sends |
retry_delay_ms | int | 1000 | Initial retry delay in ms (exponential backoff) |
circuit_breaker_threshold | int | 5 | Consecutive failures before circuit opens |
circuit_breaker_reset_ms | int | 30000 | Timeout before circuit half-opens (ms) |
traces_sample_rate | float | 1.0 | Trace sampling rate (0.0–1.0) |
max_breadcrumbs | int | 100 | Max breadcrumbs per scope |
before_send | Closure | — | Callback to modify or discard events before sending |
debug | bool | false | Enable internal debug logging |
Hub API
captureLog
Send a structured log event. Convenience functions are available for each log level.
<?php
use function LogTide\{debug, info, warn, error, critical};
// Log levels: debug, info, warn, error, critical
info('User signed up', ['user_id' => 123, 'plan' => 'pro']);
warn('Rate limit approaching', ['current' => 90, 'max' => 100]);
error('Query timeout', ['query' => 'SELECT ...', 'duration_ms' => 5000]);
// With explicit service name override
info('Payment processed', ['amount' => 99.99], 'payment-service'); captureException
Capture an exception with full stack trace, context, and breadcrumbs.
<?php
use function LogTide\captureException;
try {
processPayment($orderId);
} catch (\Throwable $e) {
captureException($e);
} flush
Flush all pending events. The SDK automatically flushes on shutdown via register_shutdown_function.
<?php
use function LogTide\flush;
// Manually flush pending events
flush(); Scopes & Context
Scopes let you attach contextual data that gets included with every event within that scope. Framework packages create per-request scopes automatically.
Global Scope
Configure the global scope to set tags and extras that apply to all events.
<?php
use function LogTide\configureScope;
configureScope(function (\LogTide\State\Scope $scope): void {
$scope->setTag('region', 'eu-west-1');
$scope->setExtra('server_id', gethostname());
$scope->setUser(['id' => 'user-123', 'role' => 'admin']);
});
// All events now include the region tag, server_id, and user context Isolated Scopes
Create an isolated scope for a block of code. Tags and context set inside don't leak outside.
<?php
use function LogTide\{withScope, info};
withScope(function () {
\LogTide\LogtideSdk::getCurrentHub()->getScope()->setTag('handler', 'payment');
info('Processing payment', ['order_id' => 456]);
// This event includes the 'handler' tag
});
info('Back to global scope');
// This event does NOT include the 'handler' tag Breadcrumbs
Breadcrumbs record a trail of events leading up to an error, making it easier to debug. Framework packages add breadcrumbs automatically for HTTP requests, DB queries, and more.
<?php
use function LogTide\{addBreadcrumb, captureException};
use LogTide\Breadcrumb\Breadcrumb;
use LogTide\Enum\BreadcrumbType;
// Add breadcrumbs manually
addBreadcrumb(new Breadcrumb(
BreadcrumbType::DEFAULT,
'User authenticated',
category: 'auth',
data: ['method' => 'oauth', 'provider' => 'github'],
));
addBreadcrumb(new Breadcrumb(
BreadcrumbType::NAVIGATION,
'Navigated to /dashboard',
category: 'navigation',
));
// When an exception is captured, breadcrumbs are included automatically
captureException(new \RuntimeException('Dashboard failed to load'));
// The error event will contain both breadcrumbs above Distributed Tracing
LogTide supports the W3C Trace Context standard for distributed tracing across services. Spans are exported in OTLP format.
Spans
<?php
use function LogTide\{startSpan, finishSpan, captureException};
$span = startSpan('db.query SELECT users', [
'kind' => \LogTide\Enum\SpanKind::CLIENT,
]);
$span?->setAttributes([
'db.system' => 'postgresql',
'db.statement' => 'SELECT * FROM users WHERE id = $1',
]);
try {
$result = $db->query('SELECT * FROM users WHERE id = ?', [$userId]);
$span?->setStatus(\LogTide\Enum\SpanStatus::OK);
} catch (\Throwable $e) {
$span?->setStatus(\LogTide\Enum\SpanStatus::ERROR, $e->getMessage());
captureException($e);
}
if ($span !== null) {
finishSpan($span);
} Trace Propagation
Framework SDKs automatically extract incoming traceparent headers and inject them into responses for end-to-end trace correlation.
<?php
use function LogTide\{getTraceparent, continueTrace};
// Continue a trace from an incoming request
$traceparent = $_SERVER['HTTP_TRACEPARENT'] ?? '';
if (!empty($traceparent)) {
continueTrace($traceparent);
}
// Get the current traceparent to propagate to outgoing requests
$outgoingTraceparent = getTraceparent();
// → "00-<trace-id>-<span-id>-01"
$response = $httpClient->request('GET', 'https://api.example.com/data', [
'headers' => ['traceparent' => $outgoingTraceparent],
]); Monolog Integration
LogTide includes built-in Monolog handlers. No separate package needed — just
composer require monolog/monolog alongside the SDK.
LogtideHandler
Forwards Monolog records to LogTide as log events.
<?php
use Monolog\Logger;
use Monolog\Level;
use LogTide\Monolog\LogtideHandler;
// Initialize the SDK first
\LogTide\init(['dsn' => 'https://[email protected]']);
// Create a Monolog logger with the LogTide handler
$logger = new Logger('my-app');
$logger->pushHandler(new LogtideHandler(Level::Debug));
// Use standard Monolog methods — logs are sent to LogTide
$logger->info('User logged in', ['user_id' => $userId]);
$logger->error('Payment failed', ['order_id' => $orderId]); BreadcrumbHandler
Records Monolog entries as breadcrumbs instead of sending them as log events.
<?php
use Monolog\Logger;
use Monolog\Level;
use LogTide\Monolog\LogtideHandler;
use LogTide\Monolog\BreadcrumbHandler;
$logger = new Logger('my-app');
// Low-level logs become breadcrumbs (trail of events)
$logger->pushHandler(new BreadcrumbHandler(Level::Debug));
// Important logs are sent as events
$logger->pushHandler(new LogtideHandler(Level::Warning)); Framework Packages
Each framework package wraps logtide/logtide with
framework-specific middleware, service providers, and auto-instrumentation.
Auto-discovery, middleware, log channel, Facade, breadcrumb integrations
Bundle with semantic config, request/console subscribers, Doctrine integration
PSR-15 middleware, route pattern resolution, error middleware
WordPress hooks, error capture, database query monitoring, HTTP API tracking
Best Practices
\LogTide\init() as early as possible in your
application entry point. This ensures default integrations (error handlers, exception handlers)
capture everything from the start.
environment and release in
your config. This enables filtering by environment and tracking regressions across releases.