1111import java .io .Closeable ;
1212import java .lang .Thread .UncaughtExceptionHandler ;
1313import java .net .Proxy ;
14+ import java .util .Collection ;
1415import java .util .Collections ;
1516import java .util .Date ;
1617import java .util .Set ;
@@ -57,6 +58,7 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
5758
5859 private Configuration config ;
5960 private final SessionTracker sessionTracker ;
61+ private final FeatureFlagStore featureFlagStore ;
6062
6163 private static final ThreadLocal <Metadata > THREAD_METADATA = new ThreadLocal <Metadata >() {
6264 @ Override
@@ -91,6 +93,7 @@ public Bugsnag(String apiKey, boolean sendUncaughtExceptions) {
9193
9294 config = new Configuration (apiKey );
9395 sessionTracker = new SessionTracker (config );
96+ featureFlagStore = config .copyFeatureFlagStore ();
9497
9598 // Automatically send unhandled exceptions to Bugsnag using this Bugsnag
9699 config .setSendUncaughtExceptions (sendUncaughtExceptions );
@@ -348,7 +351,9 @@ public void setTimeout(int timeout) {
348351 * @see #notify(com.bugsnag.Report)
349352 */
350353 public Report buildReport (Throwable throwable ) {
351- return new Report (config , throwable );
354+ HandledState handledState = HandledState .newInstance (
355+ HandledState .SeverityReasonType .REASON_HANDLED_EXCEPTION );
356+ return new Report (config , throwable , handledState , Thread .currentThread (), featureFlagStore );
352357 }
353358
354359 /**
@@ -404,7 +409,7 @@ public boolean notify(Throwable throwable, Severity severity, Callback callback)
404409
405410 HandledState handledState = HandledState .newInstance (
406411 HandledState .SeverityReasonType .REASON_USER_SPECIFIED , severity );
407- Report report = new Report (config , throwable , handledState , Thread .currentThread ());
412+ Report report = new Report (config , throwable , handledState , Thread .currentThread (), featureFlagStore );
408413 return notify (report , callback );
409414 }
410415
@@ -422,7 +427,7 @@ public boolean notify(Report report) {
422427 }
423428
424429 boolean notify (Throwable throwable , HandledState handledState , Thread currentThread ) {
425- Report report = new Report (config , throwable , handledState , currentThread );
430+ Report report = new Report (config , throwable , handledState , currentThread , featureFlagStore );
426431 return notify (report , null );
427432 }
428433
@@ -679,4 +684,59 @@ public static Set<Bugsnag> uncaughtExceptionClients() {
679684 void addOnSession (OnSession onSession ) {
680685 sessionTracker .addOnSession (onSession );
681686 }
687+
688+ /**
689+ * Add a feature flag with the specified name and variant.
690+ * If the name already exists, the variant will be updated.
691+ *
692+ * @param name the feature flag name
693+ * @param variant the feature flag variant (can be null)
694+ */
695+ public void addFeatureFlag (String name , String variant ) {
696+ featureFlagStore .addFeatureFlag (name , variant );
697+ }
698+
699+ /**
700+ * Add a feature flag with the specified name and no variant.
701+ *
702+ * @param name the feature flag name
703+ */
704+ public void addFeatureFlag (String name ) {
705+ addFeatureFlag (name , null );
706+ }
707+
708+ /**
709+ * Add multiple feature flags.
710+ * If any names already exist, their variants will be updated.
711+ *
712+ * @param featureFlags the feature flags to add
713+ */
714+ public void addFeatureFlags (Collection <FeatureFlag > featureFlags ) {
715+ featureFlagStore .addFeatureFlags (featureFlags );
716+ }
717+
718+ /**
719+ * Remove the feature flag with the specified name.
720+ *
721+ * @param name the feature flag name to remove
722+ */
723+ public void clearFeatureFlag (String name ) {
724+ featureFlagStore .clearFeatureFlag (name );
725+ }
726+
727+ /**
728+ * Remove all feature flags.
729+ */
730+ public void clearFeatureFlags () {
731+ featureFlagStore .clearFeatureFlags ();
732+ }
733+
734+ /**
735+ * Get a copy of the feature flag store.
736+ *
737+ * @return a copy of the feature flag store
738+ */
739+ FeatureFlagStore copyFeatureFlagStore () {
740+ return featureFlagStore .copy ();
741+ }
682742}
0 commit comments