born05 / craft-sentry

Pushes Craft CMS errors to Sentry.
MIT License
10 stars 11 forks source link

Question: Usage inside another plugin #3

Closed umkasanki closed 4 years ago

umkasanki commented 4 years ago

Hi, sorry for dummy question, but could you please explain how I can use your plugin inside another plugin?

eg:

<?php

namespace dev\name;

use Craft;
use yii\base\Event;
use craft\guestentries\controllers\SaveController;
use craft\guestentries\events\SaveEvent;

class Plugin extends \craft\base\Plugin
{

    public $hasCpSection = false;

    public function init()
    {
        parent::init();

        Event::on(SaveController::class, SaveController::EVENT_AFTER_SAVE_ENTRY, function(SaveEvent $e) {
                $entry = $e->entry;

                if (cond) {

                    // main logic

                } else {

                    // send error to sentry

                }

Thanks

roelvanhintum commented 4 years ago

Hi @umkasanki, good question. You can log anywhere straight to the Sentry sdk by using one of the following lines:

Sentry\captureMessage("Your message");
Sentry\captureException($exception);
Sentry\captureLastError();

I do need some modifications to make sure the captures are populated with some additional info on environment and craft version etc. Right now this is only done when the plugin handles the error.

For more info on the SDK: https://docs.sentry.io/platforms/php/#capturing-errors

umkasanki commented 4 years ago

Thank you very much

roelvanhintum commented 4 years ago

@umkasanki 1.0.1 has the additional info on every capture.