@@ -34,6 +34,28 @@ public function initialize(): void
3434 $ this ->initializeBugsnag ();
3535 }
3636
37+ /**
38+ * Checks if the build date is older than the given number of months.
39+ *
40+ * @param string|null $buildDate The build date string (any strtotime-compatible format).
41+ * @param int $months Number of months to compare.
42+ * @param int|null $now Optional timestamp to use as 'now' (for testing).
43+ * @return bool True if build date is older than given months, false otherwise.
44+ */
45+ public static function isBuildDateOlderThanMonths (?string $ buildDate , int $ months , ?int $ now = null ): bool
46+ {
47+ if (!$ buildDate ) {
48+ return false ;
49+ }
50+ $ buildTimestamp = strtotime ($ buildDate );
51+ if ($ buildTimestamp === false ) {
52+ return false ;
53+ }
54+ $ now = $ now ?? time ();
55+ $ interval = 60 * 60 * 24 * 30 * $ months ;
56+ return ($ now - $ buildTimestamp ) > $ interval ;
57+ }
58+
3759 public function initializeBugsnag (): void
3860 {
3961 if (empty ($ this ->bugSnagKey )) {
@@ -42,6 +64,12 @@ public function initializeBugsnag(): void
4264 if (!$ this ->telemetryEnabled ()) {
4365 return ;
4466 }
67+ // Check build date: suppress Bugsnag if more than 3 months old.
68+ $ buildDate = $ this ->application ->getBuildDate ();
69+ if (self ::isBuildDateOlderThanMonths ($ buildDate , 3 )) {
70+ // Too old, do not send Bugsnag reports.
71+ return ;
72+ }
4573 // It's safe-ish to make this key public.
4674 // @see https://github.com/bugsnag/bugsnag-js/issues/595
4775 $ bugsnag = Client::make ($ this ->bugSnagKey );
@@ -151,12 +179,12 @@ public function getTelemetryUserData(): array
151179 {
152180 $ data = [
153181 'ah_app_uuid ' => getenv ('AH_APPLICATION_UUID ' ),
154- 'ah_env ' => $ this -> normalizeAhEnv (AcquiaDrupalEnvironmentDetector::getAhEnv ()),
182+ 'ah_env ' => self :: normalizeAhEnv (AcquiaDrupalEnvironmentDetector::getAhEnv ()),
155183 'ah_group ' => AcquiaDrupalEnvironmentDetector::getAhGroup (),
156184 'ah_non_production ' => getenv ('AH_NON_PRODUCTION ' ),
157185 'ah_realm ' => getenv ('AH_REALM ' ),
158186 'CI ' => getenv ('CI ' ),
159- 'env_provider ' => $ this -> getEnvironmentProvider (),
187+ 'env_provider ' => self :: getEnvironmentProvider (),
160188 'php_version ' => PHP_MAJOR_VERSION . '. ' . PHP_MINOR_VERSION ,
161189 ];
162190 try {
0 commit comments