test_sentry_connection(); } /** * Send test error to Sentry * * @param string $message Optional test message * @return array Results */ function metasync_send_test_error($message = 'Test error from MetaSync Plugin') { $telemetry = metasync_telemetry(); try { // Create a test exception throw new Exception($message . ' - Test Exception at ' . date('Y-m-d H:i:s')); } catch (Exception $e) { $telemetry->send_exception($e, array( 'test' => true, 'source' => 'manual_test', 'timestamp' => time() )); return array( 'success' => true, 'message' => 'Test exception sent to both custom backend and Sentry' ); } } /** * Send test message to Sentry * * @param string $message Test message * @param string $level Log level * @return array Results */ function metasync_send_test_message($message = 'Test message from MetaSync Plugin', $level = 'warning') { $telemetry = metasync_telemetry(); $telemetry->send_message($message, $level, array( 'test' => true, 'source' => 'manual_test', 'timestamp' => time() )); return array( 'success' => true, 'message' => "Test {$level} message sent to both backends" ); } /** * Get Sentry configuration status * * @return array Configuration status */ function metasync_get_sentry_status() { $options = get_option('metasync_options', array()); $dsn = isset($options['sentry_dsn']) ? $options['sentry_dsn'] : ''; // Check if DSN is set via wp-config.php $wp_config_dsn = defined('METASYNC_SENTRY_DSN') ? METASYNC_SENTRY_DSN : ''; $telemetry_stats = metasync_telemetry()->get_telemetry_stats(); return array( 'dsn_in_options' => !empty($dsn), 'dsn_in_wp_config' => !empty($wp_config_dsn), 'active_dsn' => !empty($wp_config_dsn) ? $wp_config_dsn : $dsn, 'sentry_enabled' => isset($telemetry_stats['sentry_enabled']) ? $telemetry_stats['sentry_enabled'] : false, 'telemetry_enabled' => isset($telemetry_stats['enabled']) ? $telemetry_stats['enabled'] : false, 'environment' => Metasync_Telemetry_Config::detect_environment(), 'plugin_version' => defined('METASYNC_VERSION') ? METASYNC_VERSION : '1.0.0' ); } /** * Display Sentry setup instructions */ function metasync_show_sentry_instructions() { echo "
"; echo "

🔧 Sentry Integration Setup

"; $status = metasync_get_sentry_status(); if (!$status['sentry_enabled']) { echo "
"; echo "⚠️ Sentry Not Configured
"; echo "Follow the steps below to connect your Sentry dashboard."; echo "
"; } else { echo "
"; echo "✅ Sentry Configured
"; echo "Active DSN: " . substr($status['active_dsn'], 0, 30) . "..."; echo "
"; } echo "

Step 1: Get Your Sentry DSN

"; echo "
    "; echo "
  1. Go to your Sentry Dashboard
  2. "; echo "
  3. Select your project (or create a new one)
  4. "; echo "
  5. Go to Settings → Projects → [Your Project] → Client Keys (DSN)
  6. "; echo "
  7. Copy the DSN (looks like: https://[key]@[org].ingest.sentry.io/[project])
  8. "; echo "
"; echo "

Step 2: Configure DSN (Choose One Method)

"; echo "

Method A: Add to wp-config.php (Recommended)

"; echo "
";
    echo "// Add this line to your wp-config.php file\n";
    echo "define('METASYNC_SENTRY_DSN', 'YOUR_SENTRY_DSN_HERE');\n";
    echo "
"; echo "

Method B: Using PHP function

"; echo "
";
    echo "// Add this to your theme's functions.php or a custom plugin\n";
    echo "metasync_set_sentry_dsn('YOUR_SENTRY_DSN_HERE');\n";
    echo "
"; echo "

Step 3: Test the Connection

"; echo "

Run these commands to test your Sentry integration:

"; echo "
";
    echo "// Test connection\n";
    echo "\$result = metasync_test_sentry();\n";
    echo "var_dump(\$result);\n\n";
    echo "// Send test error\n";
    echo "\$result = metasync_send_test_error('Test error message');\n";
    echo "var_dump(\$result);\n\n";
    echo "// Send test warning\n";
    echo "\$result = metasync_send_test_message('Test warning message', 'warning');\n";
    echo "var_dump(\$result);\n";
    echo "
"; echo "

Current Status

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Telemetry Enabled:" . ($status['telemetry_enabled'] ? '✅ Yes' : '❌ No') . "
Sentry Enabled:" . ($status['sentry_enabled'] ? '✅ Yes' : '❌ No') . "
Environment:" . $status['environment'] . "
Plugin Version:" . $status['plugin_version'] . "
"; echo "
"; } // Auto-display instructions if called directly via admin if (isset($_GET['metasync_sentry_setup'])) { add_action('admin_notices', 'metasync_show_sentry_instructions'); }