Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"flarum/core": "^1.2.0",
"flarum/core": "^1.3.1",
"sentry/sdk": "^3.1.0"
},
"authors": [
Expand Down
5 changes: 5 additions & 0 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ app.initializers.add('fof/sentry', () => {
setting: 'fof-sentry.dsn',
type: 'url',
})
.registerSetting({
label: app.translator.trans('fof-sentry.admin.settings.environment_label'),
setting: 'fof-sentry.environment',
type: 'string',
})
.registerSetting({
label: app.translator.trans('fof-sentry.admin.settings.user_feedback_label'),
setting: 'fof-sentry.user_feedback',
Expand Down
1 change: 1 addition & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fof-sentry:
admin:
settings:
dsn_label: Sentry DSN
environment_label: Sentry Environment
user_feedback_label: User Feedback
javascript_label: Report JavaScript Errors
javascript_console_label: Capture JavaScript Console
Expand Down
11 changes: 10 additions & 1 deletion src/Content/SentryJavaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FoF\Sentry\Content;

use Flarum\Frontend\Document;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;

class SentryJavaScript
Expand All @@ -21,9 +22,15 @@ class SentryJavaScript
*/
private $settings;

public function __construct(SettingsRepositoryInterface $settings)
/**
* @var UrlGenerator
*/
private $url;

public function __construct(SettingsRepositoryInterface $settings, UrlGenerator $url)
{
$this->settings = $settings;
$this->url = $url;
}

public function __invoke(Document $document)
Expand All @@ -35,6 +42,7 @@ public function __invoke(Document $document)
}

$dsn = $this->settings->get('fof-sentry.dsn');
$environment = empty($this->settings->get('fof-sentry.environment')) ? str_replace(['https://', 'http://'], '', $this->url->to('forum')->base()) : $this->settings->get('fof-sentry.environment');
$showFeedback = (bool) (int) $this->settings->get('fof-sentry.user_feedback');
$captureConsole = (bool) (int) $this->settings->get('fof-sentry.javascript.console');

Expand All @@ -56,6 +64,7 @@ public function __invoke(Document $document)
if (window.Sentry) {
Sentry.init({
dsn: '$dsn',
environment: '$environment',
beforeSend: function(event) {
event.logger = 'javascript';

Expand Down
9 changes: 5 additions & 4 deletions src/SentryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Flarum\Foundation\Paths;
use Flarum\Frontend\Assets;
use Flarum\Frontend\Compiler\Source\SourceCollector;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use FoF\Sentry\Contracts\Measure;
use FoF\Sentry\Formatters\SentryFormatter;
Expand Down Expand Up @@ -47,22 +48,22 @@ public function register()
$this->container->singleton(HubInterface::class, function ($container) {
/** @var SettingsRepositoryInterface $settings */
$settings = $container->make(SettingsRepositoryInterface::class);
/** @var UrlGenerator $urlGenerator */
$url = $container->make(UrlGenerator::class);
$dsn = $settings->get('fof-sentry.dsn');
$environment = empty($settings->get('fof-sentry.environment')) ? str_replace(['https://', 'http://'], '', $url->to('forum')->base()) : $settings->get('fof-sentry.environment');
$performanceMonitoring = (int) $settings->get('fof-sentry.monitor_performance');

/** @var Paths $paths */
$paths = $container->make(Paths::class);

$tracesSampleRate = $performanceMonitoring > 0 ? round($performanceMonitoring / 100, 2) : 0;

/** @var Config $config */
$config = $container->make(Config::class);

init([
'dsn' => $dsn,
'in_app_include' => [$paths->base],
'traces_sample_rate' => $tracesSampleRate,
'environment' => str_replace(['https://', 'http://'], '', Arr::get($config, 'url')),
'environment' => $environment,
'release' => Application::VERSION,
]);

Expand Down