Skip to content

Conversation

@PatrickRoethlisberger
Copy link
Contributor

Adds Sentry Environments support

Changes proposed in this pull request:
This PR adds support for setting a custom sentry environment while unifying the default to the base URL.

Screenshot
Setting in the admin interface with default:
Admin Setting

Environment set in request to sentry instance:
Default Env in Request

Settings in admin interface with custom environment:
Admin Setting

Custom Environment in request to sentry instance:
Custom Env in Request

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tested on a local Flarum installation.

extend.php Outdated
(new Flarum\Settings())
->default('fof-sentry.monitor_performance', 0),
->default('fof-sentry.monitor_performance', 0)
->default('fof-sentry.environment', resolve(UrlGenerator::class)->to('forum')->base()),
Copy link
Member

@dsevillamartin dsevillamartin Jul 27, 2022

Choose a reason for hiding this comment

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

I believe we had issues in the past when resolving UrlGenerator early in Listener __construct methods.

I can't find all the info regarding this issue, but I did find this commit from Franz in flarum/mentions (flarum/mentions@4dc8068) that stopped resolving UrlGenerator early in an event subscriber class.
Blomstra also came across this issue more recently, so it still exists: blomstra/flarum-ext-fontawesome@14c55e5.

This default will have to be set in another way that doesn't resolve UrlGenerator too early. I don't know the best way to do that right now that avoids complicating this simple code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had a chat with @imorland and he mentioned that for this to work, the flarum\core has to be ^1.3.1. Could this be linked to the issue mentioned here? flarum/framework#3439

Copy link
Member

Choose a reason for hiding this comment

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

No, the 1.3.1 issue is different to this. @datitisev is referring to the early resolution of the UrlGenerator here.

The < 1.3.1 issue is chaining multiple ->default settings were not registered correctly

Copy link
Member

@dsevillamartin dsevillamartin Jul 27, 2022

Choose a reason for hiding this comment

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

I don't think so. The UrlGenerator resolution problem here isn't related to the Settings extender itself, as you are calling resolve as a parameter to ->default(). It doesn't matter how the extender handles that output as the resolution occurs in extend.php before the extender does anything.

I'm not entirely sure when the Sentry init function is called in the lifecycle, so I don't know if that would be after app boot. It might work there or it might need code in boot to run the Sentry init (I don't know if this can be run multiple times).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer if I move the UrlGenerator default to the SentryJavaScript.php and SentryServiceProvider.php files if no custom environment is set in the admin settings?

Copy link
Member

Choose a reason for hiding this comment

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

Yep. Looks like that should work.

I added some logs to see the run order and SentryJavascript runs well after boot. And the Sentry init code only runs when Sentry is actually triggered (e.g. by an error, I had a SentryServiceProvider@register HubInterface log line that never appeared) so it should be fine.

[2022-07-28 13:29:43] flarum.DEBUG: SentryServiceProvider@register
[2022-07-28 13:29:43] flarum.DEBUG: SentryServiceProvider@boot
[2022-07-28 13:29:44] flarum.DEBUG: SentryJavascript

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this work for you?

Copy link
Contributor Author

@PatrickRoethlisberger PatrickRoethlisberger Aug 11, 2022

Choose a reason for hiding this comment

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

@datitisev just tell me when I can do something here

Copy link
Member

Choose a reason for hiding this comment

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

@PatrickRoethlisberger I think this should work.

@imorland could you check as well whether the fix should solve the issues?
I mainly checked load order but didn't test it with an ext that would be broken with the previous code.

Moving urlGenerator into SentryServiceProvider and SentryJavaScript so default is not set in extend.php
@imorland imorland merged commit 311328d into FriendsOfFlarum:master Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants