forked from colin/simple-glitchtip
Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
d4bb614e1e | |
|
83a2b0794f | |
|
edf7b4464f | |
|
a300156a91 | |
|
8e97007a7e | |
|
f705ec6810 |
|
@ -0,0 +1 @@
|
||||||
|
simple-glitchtip-c5.zip
|
|
@ -1,11 +1,24 @@
|
||||||
{
|
{
|
||||||
"name": "nixius/simple-glitchtip-c5",
|
"name": "nixius/simple-glitchtip-c5",
|
||||||
"description": "A simple integration for GlitchTip",
|
"description": "A simple integration for GlitchTip",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Nixius\\SimpleGlitchtip\\": "src/"
|
"Nixius\\SimpleGlitchtip\\": "src/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Your Name",
|
||||||
|
"email": "your.email@example.com"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"glitchtip",
|
||||||
|
"integration",
|
||||||
|
"php"
|
||||||
|
],
|
||||||
|
"require": {}
|
||||||
}
|
}
|
|
@ -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,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Concrete\Package\SimpleSentry;
|
|
||||||
|
namespace Concrete\Package\SimpleGlitchtip;
|
||||||
|
|
||||||
use Concrete\Core\Package\Package;
|
use Concrete\Core\Package\Package;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -8,56 +9,53 @@ use Sentry\State\HubInterface;
|
||||||
|
|
||||||
class Controller extends Package
|
class Controller extends Package
|
||||||
{
|
{
|
||||||
protected $pkgHandle = 'simple_sentry';
|
protected $pkgHandle = 'simple_glitchtip';
|
||||||
protected $appVersionRequired = '9.0.0';
|
protected $appVersionRequired = '9.0.0';
|
||||||
protected $pkgVersion = '1.0.0';
|
protected $pkgVersion = '1.0.0';
|
||||||
protected $pkgName = 'SimpleSentry Error Reporter';
|
protected $pkgName = 'SimpleGlitchtip Error Reporter';
|
||||||
protected $pkgDescription = 'Reports errors to Sentry/GlitchTip using the GLITCHTIP_DSN environment variable.';
|
protected $pkgDescription = 'Reports errors to Sentry/GlitchTip using the GLITCHTIP_DSN environment variable.';
|
||||||
|
|
||||||
public function on_start()
|
public function on_start()
|
||||||
{
|
{
|
||||||
$this->app->singleton(HubInterface::class, function () {
|
$this->app->singleton(HubInterface::class, function () {
|
||||||
$dsn = getenv('GLITCHTIP_DSN'); // Pull the DSN from the environment variable
|
$dsn = getenv('GLITCHTIP_DSN');
|
||||||
if (!$dsn) {
|
if (!$dsn) {
|
||||||
\Log::warning('SimpleSentry: GLITCHTIP_DSN environment variable is not set.');
|
\Log::warning('SimpleGlitchtip: GLITCHTIP_DSN environment variable is not set.');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$clientBuilder = ClientBuilder::create([
|
$clientBuilder = ClientBuilder::create([
|
||||||
'dsn' => $dsn,
|
'dsn' => $dsn,
|
||||||
'environment' => getenv('APP_ENV') ?: 'production', // Use APP_ENV or default to 'production'
|
'environment' => getenv('APP_ENV') ?: 'production',
|
||||||
'release' => getenv('APP_VERSION') ?: '1.0.0', // Use APP_VERSION or default to '1.0.0'
|
'release' => getenv('APP_VERSION') ?: '1.0.0',
|
||||||
|
'tags' => [
|
||||||
|
'application' => 'concrete5',
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $clientBuilder->getHub();
|
return $clientBuilder->getHub();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach error handlers only if the HubInterface is properly initialized
|
|
||||||
$hub = $this->app->make(HubInterface::class);
|
$hub = $this->app->make(HubInterface::class);
|
||||||
if ($hub) {
|
if ($hub) {
|
||||||
$this->attachErrorHandlers();
|
$this->attachErrorHandlers();
|
||||||
} else {
|
} else {
|
||||||
\Log::warning('SimpleSentry: HubInterface is not initialized. Error reporting is disabled.');
|
\Log::warning('SimpleGlitchtip: HubInterface is not initialized. Error reporting is disabled.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function attachErrorHandlers()
|
private function attachErrorHandlers()
|
||||||
{
|
{
|
||||||
// Catch uncaught exceptions
|
|
||||||
set_exception_handler(function (\Throwable $exception) {
|
set_exception_handler(function (\Throwable $exception) {
|
||||||
$hub = $this->app->make(HubInterface::class);
|
$hub = $this->app->make(HubInterface::class);
|
||||||
if ($hub) {
|
if ($hub) {
|
||||||
$eventId = $hub->captureException($exception);
|
$eventId = $hub->captureException($exception);
|
||||||
|
\Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId);
|
||||||
// Log the Sentry event ID in Concrete5
|
|
||||||
\Log::error('SimpleSentry: Sentry Event ID: ' . $eventId);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Catch PHP errors
|
|
||||||
set_error_handler(function ($severity, $message, $file, $line) {
|
set_error_handler(function ($severity, $message, $file, $line) {
|
||||||
if (!(error_reporting() & $severity)) {
|
if (!(error_reporting() & $severity)) {
|
||||||
// Error not included in error_reporting
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +63,22 @@ class Controller extends Package
|
||||||
if ($hub) {
|
if ($hub) {
|
||||||
$exception = new \ErrorException($message, 0, $severity, $file, $line);
|
$exception = new \ErrorException($message, 0, $severity, $file, $line);
|
||||||
$eventId = $hub->captureException($exception);
|
$eventId = $hub->captureException($exception);
|
||||||
|
\Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId);
|
||||||
// Log the Sentry event ID in Concrete5
|
|
||||||
\Log::error('SimpleSentry: Sentry Event ID: ' . $eventId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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