Skip to content

Commit

Permalink
Register Sentry within Bluem-Woo
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb committed Nov 25, 2023
1 parent 7501991 commit a4580b3
Show file tree
Hide file tree
Showing 8 changed files with 7,175 additions and 17 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"8.0.30","version":"3.39.1:v3.39.1#857046d26b0d92dc13c4be769309026b100b517e","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"gateways\/Bluem_Creditcard_Payment_Gateway.php":"f5bea7a321540f7368ab56245a6a2c16","gateways\/Bluem_Sofort_Payment_Gateway.php":"2bc2ded0b685fbabb01dbe16433f9035","gateways\/Bluem_CarteBancaire_Payment_Gateway.php":"6f86e64622c88ecb283e4e5b193b79d9","gateways\/Bluem_PayPal_Payment_Gateway.php":"9484dd7ba1bcbff3ee2a3fbef7352240","gateways\/Bluem_Bank_Based_Payment_Gateway.php":"85e436f95be9c9d86afbbc5562875e6a","gateways\/Bluem_Mandates_Payment_Gateway.php":"9c5469ea5668180b9d1a47fcbcdfc2b6","gateways\/Bluem_iDEAL_Payment_Gateway.php":"c7a3969c5e386651afeef4ceda50d6df","gateways\/Bluem_Payment_Gateway_Interface.php":"139437cdf558c183074aa606755387a3","gateways\/Bluem_Payment_Gateway.php":"71d21fc3c3ee54e59503046c27d09c60","bluem-mandates.php":"be04a3bcee93db7fd9cc57731f9fbc84","bluem-interface.php":"c72f2cb7919bf3ed05ff296f017aff3a","index.php":"133002ba6da2763767d77c39bd56ba8d","bluem-mandates-shortcode.php":"7be2c75c1d0762b8fdf5e136c7f7f078","tests\/Unit\/BluemTest.php":"c94dd5707bc4070d2f6ed9d4bf942046","tests\/Acceptance\/FirstCest.php":"01b3400790dc6ddb3a1f4609562aa95c","tests\/Support\/AcceptanceTester.php":"a58ff42eb4a35ec58fdb503ee497a95c","tests\/Support\/_generated\/AcceptanceTesterActions.php":"b5462b02ae9aa7772ef7ff176086951c","tests\/Support\/_generated\/FunctionalTesterActions.php":"2a17766d1b2e1a78795a74181c491043","tests\/Support\/_generated\/UnitTesterActions.php":"9478041665ef070a3db44f568ecf8b91","bluem-idin.php":"3b3d4b44fbac12affb8843f9addc59a0","uninstall.php":"132045b2222673df39f723ecee1af875","bluem.php":"e568b22356c93de4f46e99b96f824491","bluem-payments.php":"9deb29956167084c284b1b837c2957ef","bluem-compatibility.php":"9ae1ffc2349b1e203aca65950bb9512b","bluem-db.php":"29128f815231c5be89f3acc1cdef4735","bluem-integrations.php":"7fe31272f523f8cba23eaf20062a7d8d","bluem-login.php":"247e4f6a19b5a2d7d0f3ca56bdb66537","views\/requests.php":"0051e9d1f9b7f1efefa858b8cc165452","views\/settings.php":"c9b85100395f7e0e1079f5d3d663ff34","views\/home.php":"9309636555f22bd5f94129cdf6966a7b","views\/importexport.php":"1e52c1760d09e89e53a62a2da628fb8e","views\/request.php":"3c751900ece726e6c45dd8f38bdf843e","views\/status.php":"30553c25ea34b233c2c3a47f0fb64dd8","views\/activate.php":"f22114a10dd3e17ab849190cdcf3e31a","bluem-mandates-instant.php":"9f194374bcba0562e776f2d629404438"}}
45 changes: 45 additions & 0 deletions Observability/SentryLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Bluem\Wordpress\Observability;

use Sentry\State\Scope;
use function Sentry\configureScope;

final class SentryLogger
{
private const KEY = 'ce6a8fc06ff29a03f805eae2041fdd4e@o4506286009548800';
private const PROJECT_ID = 4506286012891136;

private const ENV_DEVELOPMENT = 'development';
private const ENV_PRODUCTION = 'production';

public function initialize(): void
{
\Sentry\init([
'dsn' => 'https://'.self::KEY.'.ingest.sentry.io/'.self::PROJECT_ID,
'environment' => $this->getEnvironment(),
'attach_stacktrace'=> true,
]);

$values = get_option( 'bluem_woocommerce_options' );
$senderId =$values['senderID'] ?? '';

configureScope(function (Scope $scope) use ($senderId): void {
$scope->setContext('website', [
'name' => get_bloginfo( 'name' ),
'email' => get_option( "admin_email" ),
'url'=> home_url(),
]);
$scope->setTag('bluemSenderId', $senderId);
});
}

private function getEnvironment(): string
{
if($_SERVER['SERVER_NAME'] === 'localhost') {
return self::ENV_DEVELOPMENT;
}

return self::ENV_PRODUCTION;
}
}
32 changes: 29 additions & 3 deletions bluem.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
require __DIR__ . '/vendor/autoload.php';

use Bluem\BluemPHP\Bluem;
use Bluem\Wordpress\Observability\SentryLogger;

if ( ! defined( "BLUEM_LOCAL_DATE_FORMAT" ) ) {
define( "BLUEM_LOCAL_DATE_FORMAT", "Y-m-d\TH:i:s" );
Expand Down Expand Up @@ -66,6 +67,9 @@
// integrations with external plugins
require_once __DIR__ . '/bluem-integrations.php';

// Observability
require_once __DIR__ . '/Observability/SentryLogger.php';

/**
* Check if WooCommerce is activated
*/
Expand Down Expand Up @@ -374,6 +378,7 @@ function bluem_plugin_activation() {
include_once 'views/activate.php';
}


function bluem_requests_view() {
if ( isset( $_GET['request_id'] ) && $_GET['request_id'] !== "" ) {
if ( isset( $_GET['admin_action'] ) && $_GET['admin_action'] == "delete" ) {
Expand Down Expand Up @@ -819,6 +824,7 @@ function bluem_woocommerce_register_settings() {
"bluem_woocommerce",
"bluem_woocommerce_modules_section"
);

add_settings_section(
'bluem_woocommerce_general_section',
'<span class="dashicons dashicons-admin-settings"></span> ' . __( "General settings", 'bluem' ),
Expand Down Expand Up @@ -946,6 +952,12 @@ function bluem_woocommerce_register_settings() {
add_action( 'admin_init', 'bluem_woocommerce_register_settings' );

function bluem_woocommerce_init() {

/**
* Register error logging
*/
bluem_register_error_logging();

/**
* Create session storage.
*/
Expand Down Expand Up @@ -1203,8 +1215,8 @@ function bluem_woocommerce_get_core_options(): array {
'error_reporting_email' => [
'key' => 'error_reporting_email',
'title' => 'bluem_error_reporting_email',
'name' => 'Rapporteer errors bij de developers via een automatische email',
'description' => "Help ons snel problemen oplossen en downtime minimaliseren. Geef hier aan of je als de developers van Bluem automatisch een notificatie e-mail wil sturen met technische details (geen persoonlijke informatie). Dit staat standaard aan, behalve als je dit expliciet uitzet. ",
'name' => 'Rapporteer errors bij de developers',
'description' => "Help ons snel problemen oplossen en downtime minimaliseren door niet-persoonlijke technische meldingen door te laten sturen.",
'type' => 'select',
'default' => '1',
'options' => [
Expand Down Expand Up @@ -1593,12 +1605,12 @@ function bluem_woocommerce_modules_render_suppress_warning() {
bluem_woocommerce_modules_render_generic_activation( "suppress_warning" );
}


function bluem_woocommerce_settings_render_suppress_woo() {
bluem_woocommerce_settings_render_input(
bluem_woocommerce_get_option( 'suppress_woo' )
);
}
//throw new Exception("Voorbeeld voor Peter");

function bluem_woocommerce_settings_render_error_reporting_email() {
bluem_woocommerce_settings_render_input(
Expand Down Expand Up @@ -1974,3 +1986,17 @@ function bluem_admin_status() {
function bluem_woocommerce_is_woocommerce_active(): bool {
return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
}


function bluem_register_error_logging() {
$settings = get_option( 'bluem_woocommerce_options' );

if ( ! isset( $settings['error_reporting_email'] )
|| ((int)$settings['error_reporting_email'] === 1)
) {
echo "Init";
$logger = new SentryLogger();
$logger->initialize();
}
throw new \RuntimeException('test voor Peter');
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"symfony/polyfill-mbstring": "v1.19.0",
"symfony/polyfill-php80": "^1.27",
"psr/log":"1.1.4",
"ext-json": "*"
"ext-json": "*",
"sentry/sdk": "^4.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
Loading

0 comments on commit a4580b3

Please sign in to comment.