1111
1212namespace FoF \Sentry \Content ;
1313
14+ use Flarum \Foundation \Application ;
15+ use Flarum \Foundation \Config ;
1416use Flarum \Frontend \Document ;
1517use Flarum \Http \UrlGenerator ;
1618use Flarum \Settings \SettingsRepositoryInterface ;
@@ -33,11 +35,17 @@ class SentryJavaScript
3335 */
3436 private $ container ;
3537
36- public function __construct (SettingsRepositoryInterface $ settings , UrlGenerator $ url , Container $ container )
38+ /**
39+ * @var Config
40+ */
41+ private $ config ;
42+
43+ public function __construct (SettingsRepositoryInterface $ settings , UrlGenerator $ url , Container $ container , Config $ config )
3744 {
3845 $ this ->settings = $ settings ;
3946 $ this ->url = $ url ;
4047 $ this ->container = $ container ;
48+ $ this ->config = $ config ;
4149 }
4250
4351 public function __invoke (Document $ document )
@@ -84,12 +92,18 @@ public function __invoke(Document $document)
8492 'tracesSampleRate ' => $ tracesSampleRate ,
8593 'replaysSessionSampleRate ' => $ replaysSessionSampleRate ,
8694 'replaysOnErrorSampleRate ' => $ replaysErrorSampleRate ,
95+ 'tags ' => [
96+ 'flarum ' => Application::VERSION ,
97+ 'offline ' => $ this ->config ['offline ' ] ? 'true ' : 'false ' ,
98+ 'debug ' => $ this ->config ->inDebugMode () ? 'true ' : 'false ' ,
99+ ],
87100 ];
88101
89- // Merge with custom config
90- if ($ this ->container ->bound ('fof.sentry.frontend.config ' )) {
91- $ customConfig = $ this ->container ->make ('fof.sentry.frontend.config ' );
92- $ config = array_merge ($ config , $ customConfig );
102+ // Retrieve custom tags if they exist
103+ if ($ this ->container ->bound ('fof.sentry.tags ' )) {
104+ $ customTags = $ this ->container ->make ('fof.sentry.tags ' );
105+ // Merge custom tags with the default ones
106+ $ config ['tags ' ] = array_merge ($ config ['tags ' ], $ customTags );
93107 }
94108
95109 // Add the config to the document payload
@@ -99,17 +113,18 @@ public function __invoke(Document $document)
99113 $ document ->foot [] = "
100114 <script>
101115 if (window.Sentry) {
116+ const sentryConfig = app.data['fof-sentry'] || {};
102117 const client = Sentry.createClient({
103- dsn: ' $ dsn',
104- environment: ' $ environment',
105- scrubEmails: " .( $ shouldScrubEmailsFromUserData ? ' true ' : ' false ' ). ',
106- showFeedback: ' .( $ showFeedback ? 'true ' : 'false ' ).',
107-
108- captureConsole: ' .($ captureConsole ? 'true ' : 'false ' ).",
109-
110- tracesSampleRate: $ tracesSampleRate ,
111- replaysSessionSampleRate: $ replaysSessionSampleRate ,
112- replaysOnErrorSampleRate: $ replaysErrorSampleRate ,
118+ dsn: sentryConfig.dsn || ' $ dsn',
119+ environment: sentryConfig.environment || ' $ environment',
120+ release: sentryConfig.release || ' $ release ',
121+ scrubEmails: sentryConfig.scrubEmails !== undefined ? sentryConfig.scrubEmails : " .( $ shouldScrubEmailsFromUserData ? 'true ' : 'false ' ).',
122+ showFeedback: sentryConfig.showFeedback !== undefined ? sentryConfig.showFeedback : ' .( $ showFeedback ? ' true ' : ' false ' ). ' ,
123+ captureConsole: sentryConfig.captureConsole !== undefined ? sentryConfig.captureConsole : ' .($ captureConsole ? 'true ' : 'false ' ).",
124+ tracesSampleRate: sentryConfig.tracesSampleRate !== undefined ? sentryConfig.tracesSampleRate : $ tracesSampleRate ,
125+ replaysSessionSampleRate: sentryConfig.replaysSessionSampleRate !== undefined ? sentryConfig.replaysSessionSampleRate : $ replaysSessionSampleRate ,
126+ replaysOnErrorSampleRate: sentryConfig.replaysOnErrorSampleRate !== undefined ? sentryConfig.replaysOnErrorSampleRate : $ replaysErrorSampleRate ,
127+ tags: sentryConfig.tags || {}
113128 });
114129
115130 Sentry.getCurrentHub().bindClient(client);
0 commit comments