Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
|
d4bb614e1e | |
|
83a2b0794f | |
|
edf7b4464f | |
|
a300156a91 | |
|
8e97007a7e | |
|
f705ec6810 | |
|
501aea8f3e | |
|
6e82beea2f | |
|
283b5534c3 | |
|
5938c54af4 | |
|
12e14401d2 |
|
@ -0,0 +1 @@
|
|||
simple-glitchtip-c5.zip
|
102
README.md
102
README.md
|
@ -1,29 +1,99 @@
|
|||
# Simple Glitchtip Plugin Installation
|
||||
# Simple Glitchtip Plugin for Concrete5
|
||||
|
||||
A lightweight plugin for Concrete5 that reports errors and exceptions to **GlitchTip** or **Sentry**. This package is designed to provide seamless error tracking by integrating with GlitchTip via environment variables.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
To install or update the Simple Glitchtip plugin, run the following command from the root of your WordPress HTML directory:
|
||||
To install or update the **Simple Glitchtip** plugin, run the following command from your server's root directory:
|
||||
|
||||
```bash
|
||||
curl -sSL https://git.nixc.us/colin/simple-glitchtip/raw/branch/main/install.sh | bash
|
||||
curl -sSL https://git.nixc.us/nixius/simple-glitchtip-c5/raw/branch/main/install.sh | bash
|
||||
```
|
||||
|
||||
This script automates the installation process and sets up the required files for the plugin.
|
||||
|
||||
---
|
||||
|
||||
## Enabling the Plugin
|
||||
|
||||
### After running the install script, you need to activate the plugin. You can do this via the WordPress admin dashboard:
|
||||
After running the installation script, enable the plugin via the Concrete5 dashboard:
|
||||
|
||||
Log in to your WordPress admin dashboard.
|
||||
Navigate to Plugins > Installed Plugins.
|
||||
Find Simple Glitchtip in the list and click Activate.
|
||||
1. Log in to your Concrete5 admin panel.
|
||||
2. Navigate to **System & Settings > Extend Concrete5 > Add Functionality**.
|
||||
3. Find **Simple Glitchtip** in the list of available packages and click **Install**.
|
||||
|
||||
### What install.sh Does
|
||||
Once installed, the plugin will automatically capture and report errors.
|
||||
|
||||
The install.sh script performs the following actions:
|
||||
---
|
||||
|
||||
Defines the URL for downloading the simple-glitchtip.php file.
|
||||
Creates the target directory (wp-content/plugins/simple-glitchtip) if it doesn't exist.
|
||||
Downloads the simple-glitchtip.php file into the target directory.
|
||||
Downloads the Sentry SDK as sentry.phar into the target directory.
|
||||
Sets the correct permissions for the simple-glitchtip.php and sentry.phar files.
|
||||
Prints a message indicating that the Simple Glitchtip plugin has been installed or updated successfully.
|
||||
## What the `install.sh` Script Does
|
||||
|
||||
This setup includes the necessary error reporting functionality within a single plugin file and automates the installation and updating process via the provided install.sh script.
|
||||
The `install.sh` script performs the following actions:
|
||||
|
||||
1. **Creates the Plugin Directory:**
|
||||
- Ensures the `packages/simple_glitchtip` directory exists under your Concrete5 root.
|
||||
|
||||
2. **Downloads the Required Files:**
|
||||
- Fetches the `controller.php` file containing the plugin logic.
|
||||
- Installs the necessary dependencies, such as the Sentry PHP SDK, if not already present.
|
||||
|
||||
3. **Sets Permissions:**
|
||||
- Ensures the files have appropriate permissions for execution by the Concrete5 application.
|
||||
|
||||
4. **Prints a Success Message:**
|
||||
- Confirms the plugin has been installed or updated successfully.
|
||||
|
||||
---
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
This plugin uses environment variables to configure the integration with GlitchTip/Sentry:
|
||||
|
||||
- **`GLITCHTIP_DSN`**: The DSN URL provided by your GlitchTip/Sentry project.
|
||||
- **`APP_ENV`**: The application environment (e.g., `production`, `staging`, `development`). Defaults to `production`.
|
||||
- **`APP_VERSION`**: The current version of your application for release tracking. Defaults to `1.0.0`.
|
||||
|
||||
### Setting Environment Variables
|
||||
You can set these variables in your server configuration or in a `.env` file, depending on your environment. For example:
|
||||
|
||||
```bash
|
||||
export GLITCHTIP_DSN=https://your-glitchtip-dsn-url
|
||||
export APP_ENV=production
|
||||
export APP_VERSION=1.2.3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Error and Exception Handling:**
|
||||
- The plugin hooks into Concrete5's lifecycle to capture uncaught exceptions and PHP errors.
|
||||
- Errors are reported to GlitchTip/Sentry using the DSN configured in `GLITCHTIP_DSN`.
|
||||
|
||||
2. **Event IDs:**
|
||||
- Each error is assigned a unique event ID for tracking in GlitchTip/Sentry.
|
||||
- Event IDs are also logged to Concrete5's internal log system for cross-referencing.
|
||||
|
||||
3. **Fail-Safe Operation:**
|
||||
- If the `GLITCHTIP_DSN` environment variable is not set, the plugin gracefully disables error reporting and logs a warning.
|
||||
|
||||
---
|
||||
|
||||
## Testing the Plugin
|
||||
|
||||
To test the integration, you can trigger a test error:
|
||||
|
||||
### Example 1: Uncaught Exception
|
||||
```php
|
||||
throw new \Exception('Test Exception from Simple Glitchtip');
|
||||
```
|
||||
|
||||
### Example 2: PHP Error
|
||||
```php
|
||||
trigger_error('Test Warning from Simple Glitchtip', E_USER_WARNING);
|
||||
```
|
||||
|
||||
Check your GlitchTip/Sentry dashboard for the reported errors, and Concrete5 logs for the corresponding event IDs.
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "nixius/simple-glitchtip-c5",
|
||||
"description": "A simple integration for GlitchTip",
|
||||
"version": "0.0.3",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Nixius\\SimpleGlitchtip\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Your Name",
|
||||
"email": "your.email@example.com"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"glitchtip",
|
||||
"integration",
|
||||
"php"
|
||||
],
|
||||
"require": {}
|
||||
}
|
24
install.sh
24
install.sh
|
@ -1,22 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Define plugin details
|
||||
PLUGIN_URL="https://git.nixc.us/colin/simple-glitchtip/raw/branch/main/simple-glitchtip.php"
|
||||
RAVEN_CLIENT_URL="https://github.com/getsentry/sentry-php/releases/download/3.5.1/sentry-php.phar"
|
||||
PLUGIN_DIR="./wp-content/plugins/simple-glitchtip"
|
||||
CONTROLLER_URL="https://git.nixc.us/nixius/simple-glitchtip-c5/raw/branch/main/controller.php"
|
||||
SENTRY_SDK_URL="https://github.com/getsentry/sentry-php/releases/latest/download/sentry.phar"
|
||||
PACKAGE_DIR="./packages/simple_glitchtip"
|
||||
|
||||
# Create plugin directory if it doesn't exist
|
||||
mkdir -p "$PLUGIN_DIR"
|
||||
# Create the package directory if it doesn't exist
|
||||
mkdir -p "$PACKAGE_DIR"
|
||||
|
||||
# Download the plugin file
|
||||
curl -o "$PLUGIN_DIR/simple-glitchtip.php" "$PLUGIN_URL"
|
||||
# Download the controller file
|
||||
curl -o "$PACKAGE_DIR/controller.php" -L "$CONTROLLER_URL"
|
||||
|
||||
# Download the Raven client (Sentry/Glitchtip SDK)
|
||||
curl -o "$PLUGIN_DIR/raven-client.phar" -L "$RAVEN_CLIENT_URL"
|
||||
# Download the Sentry SDK (as a .phar file)
|
||||
curl -o "$PACKAGE_DIR/sentry.phar" -L "$SENTRY_SDK_URL"
|
||||
|
||||
# Set correct permissions
|
||||
chmod 644 "$PLUGIN_DIR/simple-glitchtip.php"
|
||||
chmod 644 "$PLUGIN_DIR/raven-client.phar"
|
||||
chmod 644 "$PACKAGE_DIR/controller.php"
|
||||
chmod 644 "$PACKAGE_DIR/sentry.phar"
|
||||
|
||||
# Inform user
|
||||
echo "Simple Glitchtip plugin installed/updated successfully."
|
||||
echo "Simple Glitchtip package installed/updated successfully."
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Ensure environment variables are set
|
||||
if [[ -z "$REGISTRY_USER" || -z "$REGISTRY_PASSWORD" ]]; then
|
||||
echo "Error: REGISTRY_USER and REGISTRY_PASSWORD must be set in the environment."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Variables
|
||||
ZIP_FILE="simple-glitchtip-c5.zip"
|
||||
REGISTRY_URL="https://git.nixc.us/api/packages/nixius/composer"
|
||||
|
||||
# Ensure composer.json exists
|
||||
if [[ ! -f "composer.json" ]]; then
|
||||
echo "Error: composer.json not found in the current directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Increment version in composer.json
|
||||
echo "Incrementing version in composer.json..."
|
||||
VERSION=$(jq -r '.version' composer.json)
|
||||
if [[ $VERSION == "null" ]]; then
|
||||
echo "Error: version is missing in composer.json."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract version components
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
||||
PATCH=$((PATCH + 1)) # Increment patch version
|
||||
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||
|
||||
# Update composer.json with the new version
|
||||
jq --arg version "$NEW_VERSION" '.version = $version' composer.json > composer.json.tmp && mv composer.json.tmp composer.json
|
||||
echo "Updated version to $NEW_VERSION."
|
||||
|
||||
# Zip the current directory
|
||||
echo "Creating zip file: $ZIP_FILE..."
|
||||
zip -r "$ZIP_FILE" . >/dev/null
|
||||
echo "Zip file created."
|
||||
|
||||
# Upload to Gitea registry
|
||||
echo "Uploading $ZIP_FILE to $REGISTRY_URL..."
|
||||
RESPONSE=$(curl --silent --write-out "%{http_code}" --output /dev/null \
|
||||
--user "$REGISTRY_USER:$REGISTRY_PASSWORD" \
|
||||
--upload-file "$ZIP_FILE" \
|
||||
"$REGISTRY_URL")
|
||||
|
||||
if [[ $RESPONSE -eq 201 ]]; then
|
||||
echo "Package successfully uploaded with version $NEW_VERSION."
|
||||
else
|
||||
echo "Error: Failed to upload package. HTTP response code: $RESPONSE."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rm -f "$ZIP_FILE"
|
||||
echo "Cleanup complete. Done!"
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: Simple Glitchtip
|
||||
Description: A simple plugin to handle Sentry/Glitchtip DSNs and report errors.
|
||||
Version: 1.0
|
||||
Author: Colin
|
||||
Plugin URI: https://git.nixc.us/colin/simple-glitchtip
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
// Register settings
|
||||
function sg_register_settings() {
|
||||
register_setting('sg-settings-group', 'sg_dsn');
|
||||
}
|
||||
|
||||
// Settings page
|
||||
function sg_settings_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Simple Glitchtip Settings</h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields('sg-settings-group'); ?>
|
||||
<?php do_settings_sections('sg-settings-group'); ?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">DSN</th>
|
||||
<td><input type="text" name="sg_dsn" value="<?php echo esc_attr(get_option('sg_dsn')); ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Add settings menu
|
||||
function sg_add_settings_menu() {
|
||||
add_options_page('Simple Glitchtip Settings', 'Glitchtip', 'manage_options', 'sg-settings', 'sg_settings_page');
|
||||
}
|
||||
add_action('admin_menu', 'sg_add_settings_menu');
|
||||
add_action('admin_init', 'sg_register_settings');
|
||||
|
||||
// Initialize error handler
|
||||
function sg_initialize_error_handler($dsn) {
|
||||
if (!class_exists('Sentry\State\Hub')) {
|
||||
require_once plugin_dir_path(__FILE__) . 'sentry.phar';
|
||||
}
|
||||
|
||||
Sentry\init(['dsn' => $dsn]);
|
||||
|
||||
function handle_exception($exception) {
|
||||
Sentry\captureException($exception);
|
||||
}
|
||||
set_exception_handler('handle_exception');
|
||||
|
||||
function handle_error($errno, $errstr, $errfile, $errline) {
|
||||
Sentry\captureMessage("$errstr in $errfile on line $errline");
|
||||
}
|
||||
set_error_handler('handle_error');
|
||||
}
|
||||
|
||||
// Initialize the plugin
|
||||
function sg_initialize_plugin() {
|
||||
$dsn = getenv('SENTRY_DSN') ?: getenv('GLITCHTIP_DSN') ?: get_option('sg_dsn');
|
||||
if ($dsn) {
|
||||
sg_initialize_error_handler($dsn);
|
||||
}
|
||||
}
|
||||
add_action('plugins_loaded', 'sg_initialize_plugin');
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Concrete\Package\SimpleGlitchtip;
|
||||
|
||||
use Concrete\Core\Package\Package;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Sentry\ClientBuilder;
|
||||
use Sentry\State\HubInterface;
|
||||
|
||||
class Controller extends Package
|
||||
{
|
||||
protected $pkgHandle = 'simple_glitchtip';
|
||||
protected $appVersionRequired = '9.0.0';
|
||||
protected $pkgVersion = '1.0.0';
|
||||
protected $pkgName = 'SimpleGlitchtip Error Reporter';
|
||||
protected $pkgDescription = 'Reports errors to Sentry/GlitchTip using the GLITCHTIP_DSN environment variable.';
|
||||
|
||||
public function on_start()
|
||||
{
|
||||
$this->app->singleton(HubInterface::class, function () {
|
||||
$dsn = getenv('GLITCHTIP_DSN');
|
||||
if (!$dsn) {
|
||||
\Log::warning('SimpleGlitchtip: GLITCHTIP_DSN environment variable is not set.');
|
||||
return null;
|
||||
}
|
||||
|
||||
$clientBuilder = ClientBuilder::create([
|
||||
'dsn' => $dsn,
|
||||
'environment' => getenv('APP_ENV') ?: 'production',
|
||||
'release' => getenv('APP_VERSION') ?: '1.0.0',
|
||||
'tags' => [
|
||||
'application' => 'concrete5',
|
||||
],
|
||||
]);
|
||||
|
||||
return $clientBuilder->getHub();
|
||||
});
|
||||
|
||||
$hub = $this->app->make(HubInterface::class);
|
||||
if ($hub) {
|
||||
$this->attachErrorHandlers();
|
||||
} else {
|
||||
\Log::warning('SimpleGlitchtip: HubInterface is not initialized. Error reporting is disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
private function attachErrorHandlers()
|
||||
{
|
||||
set_exception_handler(function (\Throwable $exception) {
|
||||
$hub = $this->app->make(HubInterface::class);
|
||||
if ($hub) {
|
||||
$eventId = $hub->captureException($exception);
|
||||
\Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId);
|
||||
}
|
||||
});
|
||||
|
||||
set_error_handler(function ($severity, $message, $file, $line) {
|
||||
if (!(error_reporting() & $severity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hub = $this->app->make(HubInterface::class);
|
||||
if ($hub) {
|
||||
$exception = new \ErrorException($message, 0, $severity, $file, $line);
|
||||
$eventId = $hub->captureException($exception);
|
||||
\Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
register_shutdown_function(function () {
|
||||
$error = error_get_last();
|
||||
if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
|
||||
$hub = $this->app->make(HubInterface::class);
|
||||
if ($hub) {
|
||||
$exception = new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
|
||||
$eventId = $hub->captureException($exception);
|
||||
\Log::error('SimpleGlitchtip: Sentry Event ID (shutdown error): ' . $eventId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue