LogTide

WordPress SDK

WordPress integration without a DI container. Registers WordPress action/filter hooks directly for error capture, lifecycle breadcrumbs, database query monitoring, and HTTP API tracking.

Installation

Requires Bedrock or another Composer-based WordPress setup.

composer require logtide/logtide-wordpress

Quick Start

Add initialization to your wp-config.php or a must-use plugin (mu-plugins/logtide.php):

<?php
// mu-plugins/logtide.php

use LogTide\WordPress\LogtideWordPress;

LogtideWordPress::init([
    'dsn' => defined('LOGTIDE_DSN') ? LOGTIDE_DSN : '',
    'service' => 'my-wordpress-site',
    'environment' => defined('WP_ENVIRONMENT_TYPE') ? WP_ENVIRONMENT_TYPE : 'production',
]);

Define your DSN in wp-config.php:

<?php
// wp-config.php
define('LOGTIDE_DSN', 'https://[email protected]');

Configuration

<?php

LogtideWordPress::init([
    'dsn' => LOGTIDE_DSN,
    'service' => 'my-wordpress-site',
    'environment' => WP_ENVIRONMENT_TYPE,
    'release' => '1.0.0',

    // Database monitoring
    'slow_query_threshold_ms' => 100.0,  // Log queries slower than this (default: 100ms)

    // All standard LogTide options are supported:
    'batch_size' => 100,
    'max_retries' => 3,
    'traces_sample_rate' => 1.0,
    'debug' => false,
]);

Automatic Hooks

The SDK automatically registers WordPress hooks for comprehensive monitoring:

  • Error Capture — PHP error handler (set_error_handler) captures warnings and notices
  • wp_die — Captures WP_Error messages passed to wp_die()
  • Lifecycle — Records wp_loaded and shutdown breadcrumbs
  • Redirects — Records redirect URLs as navigation breadcrumbs
  • Mail — Records wp_mail() calls with recipient and subject
  • Plugins — Records plugin activation/deactivation events
  • Multisite — Records switch_blog events with blog IDs

Database Monitoring

Instruments $wpdb to record slow database queries as breadcrumbs. Queries exceeding the threshold (default: 100ms) are captured with query text and duration.

<?php

// Enable SAVEQUERIES in wp-config.php for detailed query tracking
define('SAVEQUERIES', true);

// Configure slow query threshold
LogtideWordPress::init([
    'dsn' => LOGTIDE_DSN,
    'slow_query_threshold_ms' => 50.0,  // Capture queries slower than 50ms
]);

HTTP API Tracking

Hooks into the WordPress HTTP API (wp_remote_get, wp_remote_post, etc.) to record outgoing HTTP requests as breadcrumbs with URL, method, status code, and duration.

Best Practices

1. Use a Must-Use Plugin
Place initialization in mu-plugins/ to ensure LogTide loads before any regular plugins, catching all errors from the start.
2. Use Bedrock or Composer
This package requires Composer. Use Bedrock for a modern Composer-based WordPress project structure.
3. WP-CLI & Cron
The SDK flushes on shutdown, so WP-CLI commands and WP-Cron jobs are automatically covered.
Esc

Type to search across all documentation pages