Skip to content

Implement ability for users to register custom callbacks via service definition tags. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

samdjstevens
Copy link

@samdjstevens samdjstevens commented Mar 25, 2017

This is my attempt at resolving issue #35.

This PR enables custom callbacks to be registered to the Bugsnag Client object, by creating a service and tagging it with the bugsnag.callback name.

The service must implement a registerCallback method, which is used in the same way as the registerCallback method on the Bugsnag client. This method name is definable on a per-service basis, by setting the method attribute on the tag.

I have also re-factored the existing user setting code in ClientFactory to be a callback service included in the bundle.

I have made additions to the example apps in the repo to show an example callback service, but have not written any documentation for the new feature as they seem to live separately.

@PReimers - does this implementation solve your use case?

@PReimers
Copy link

@samdjstevens doesn't seem to work for me 😞

either I'm doing wrong on implementation or It's just not working.

@samdjstevens
Copy link
Author

@PReimers Are you getting any errors, or are you just not seeing the callbacks take affect on bugsnag notifications? Could you post your service class and definition configuration so I could take a look?

@PReimers
Copy link

@samdjstevens

I forked your repo and changed only the composer.json.

in my Symfony project I changed:
composer.json:

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/PReimers/bugsnag-symfony.git"
        }
],
"require": {
        "php": ">=5.3.3",
...
        "bugsnag/bugsnag": "^3.4",
        "preimers/bugsnag-symfony": "dev-master"

src/BrokerStar/CommonBundle/Bugsnag/MetadataCallback.php

<?php

namespace BrokerStar\CommonBundle\Bugsnag;

use Bugsnag\Report;

class MetadataCallback
{
    /**
    * @param \Bugsnag\Report $report
    */
    public function registerCallback(Report $report)
    {
        $report->setMetaData([
            'installation' => [
                'url' => $_SERVER['HTTP_HOST'],
                'path' => $_SERVER['REQUEST_URI'],
            ]
        ]);
    }
}

src/BrokerStar/CommonBundle/Resources/config/service.yml

services:
    brokerstar_common.bugsnag.metadatacallback:
        class: BrokerStar\CommonBundle\Bugsnag\MetadataCallback
        tags:
          - { name: bugsnag.callback }

by the way how to customize the setUser function?

@samdjstevens
Copy link
Author

@PReimers Your setup looks correct - when an exception is being thrown and reported to Bugsnag, do you see any errors, or is the information just missing from the report when you inspect it on the website? Also, what version of Symfony are you using?

I've made a skeleton Symfony app replicating your integration here - which I have verified to be reporting the extra data to Bugsnag on exceptions. Can you scan this and see if there are any differences in your code?

I assume that you are enabling the bundle and specifying the API key in your config?

@GrahamCampbell
Copy link
Contributor

We do actually have an example apps in https://github.com/bugsnag/bugsnag-symfony/tree/master/example.

@PReimers
Copy link

@samdjstevens
when an exception in thrown I see it on bugsnag dashboard but the information added in MetadataCallback.php are missing

@samdjstevens
Copy link
Author

Just to confirm, you are enabling the bundle, setting your API key, and letting the bundle listener trigger the sending to Bugsnag?

And when clicking through on the excpetion in Bugsnag, there is no "Installation" tab with the custom data, like this?

Can you try downloading my sample project posted above, replacing the api key with yours, and seeing if the extra data is registered?

@PReimers
Copy link

PReimers commented Mar 25, 2017

@samdjstevens your test project is showing the information 😄

but why is it not shown on my project 🤔

btw. should we move the discussion to another place? (like gitter / slack ...)

@PReimers
Copy link

@samdjstevens @GrahamCampbell - This resolves #35

+1 for merging 👍

{
/**
* @param \Bugsnag\Report $report
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @return void.

@samdjstevens
Copy link
Author

@GrahamCampbell - return tags added.

@GrahamCampbell
Copy link
Contributor

Please don't comment any .DS_Store files. I'd recommend adding that to your global ignore file.

@samdjstevens
Copy link
Author

Whoops, usually catch those. Removed now.

@samdjstevens
Copy link
Author

hi @GrahamCampbell - anything blocking this PR from merge still?

@GrahamCampbell GrahamCampbell mentioned this pull request Apr 3, 2017
@samdjstevens
Copy link
Author

Do you have any timescale of when you think this could be merged into master @GrahamCampbell?

@GrahamCampbell
Copy link
Contributor

Not yet, sorry. Need to find the time to sit down and give this a detailed review, and try it out.

* @param null|\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokens
* @param null|\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $checker
* @param bool $setUser
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return void

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

@@ -12,4 +14,16 @@ class BugsnagBundle extends Bundle
* @return string
*/
const VERSION = '1.0.0';

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just copy over the description rather than inherit. Makes it easy for a human to read the code and know what it does straight away.

Copy link
Author

@samdjstevens samdjstevens Apr 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here would literally be "Builds the bundle." - is this really helpful? Anyone who isn't already familiar with Symfony, and what this file is for, would not really be looking at it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better description would be "Setup the callback registering pass." or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

@@ -12,4 +14,16 @@ class BugsnagBundle extends Bundle
* @return string
*/
const VERSION = '1.0.0';

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better description would be "Setup the callback registering pass." or something.

@GrahamCampbell
Copy link
Contributor

Are you able to squash and rebase please @samdjstevens, and then I will do another review. :)

@samdjstevens
Copy link
Author

Sure - squashed and rebased

* @param null|\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokens
* @param null|\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $checker
* @param bool $setUser
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

@@ -12,4 +14,16 @@ class BugsnagBundle extends Bundle
* @return string
*/
const VERSION = '1.0.0';

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra blank line.

@samdjstevens
Copy link
Author

samdjstevens commented Jun 15, 2017

Requested changes made

Edit: Can't see what StyleCI is failing for on this page: https://styleci.io/analyses/8LgvlG

@GrahamCampbell
Copy link
Contributor

Edit: Can't see what StyleCI is failing for on this page: https://styleci.io/analyses/8LgvlG

That link shows a diff, that has the change.

@@ -44,6 +45,9 @@ public function __construct(
}

/**
* Define a callback to set the currently authenticated user as the user
* on any BugSnag reports that are sent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Bugsnag

@samdjstevens
Copy link
Author

That link shows a diff, that has the change.

Yes, but what is it complaining about? I see no rule violation message or anything

@GrahamCampbell
Copy link
Contributor

image

@samdjstevens
Copy link
Author

Yes I can see the diff. The diff shows 4 spaces before the asterisks, which is the same as the other lines. I'm asking what the actual rule violation is as this isn't shown anywhere on the StyleCI page.

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Jun 16, 2017

The rule is that there must be phpdoc formatting like that, in between param and returns annotations. :)

@samdjstevens
Copy link
Author

samdjstevens commented Jun 16, 2017

Ahhh I see, the diff is the change I need to make, thanks. Patch applied

protected $setUser;

/**
* @param null|\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put null on the right of the other type. :)

*/
protected $setUser;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a description to this doc, similar to the others in the project.


/**
* Define a callback to set the currently authenticated user as the user
* on any Bugsnag reports that are sent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to:

    /**
     * Define a callback to set the currently authenticated user.
     *
     * @param \Bugsnag\Report $report
     *
     * @return void
     */

This is because "short descriptions" cannot span more than 1 line, and we also apply the extra cs constraint that they cannot be longer than 80 characters.

@samdjstevens
Copy link
Author

I think I'm going to bow out of this PR - it feels like the review process is endless CS requests that I don't know about. If anyone wants to take this over, please feel free too!

@kattrali
Copy link
Contributor

Thanks for getting it this far, @samdjstevens. I think we can take it over the finish line and ensure that code style requirements are more clear in the future. 👍

@Baldinof
Copy link

Hi, any news on this PR?

@abigailbramble abigailbramble added the needs discussion Requires internal analysis/discussion label Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Requires internal analysis/discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants