Skip to content

Commit 5d8a2df

Browse files
adinauerlciangetsentry-bot
authored
Add scope based feature flags (#4812)
* Add scope based feature flags * fix equals * add serialization tests * Create new reference on buffer clone * add comment explaining the merge method * optimize merge method * make flag and result nullable params * handle empty/noop buffer on merge and add tests for it * optimize add method * format; fix test * Fix duplicate check * Update sentry/src/main/java/io/sentry/SentryOptions.java Co-authored-by: Lorenzo Cian <[email protected]> * Format code * changelog * nullable getFeatureFlags --------- Co-authored-by: Lorenzo Cian <[email protected]> Co-authored-by: Sentry Github Bot <[email protected]>
1 parent d464089 commit 5d8a2df

File tree

76 files changed

+1538
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1538
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add feature flags API ([#4812](https://github.com/getsentry/sentry-java/pull/4812))
8+
- You may now keep track of your feature flag evaluations and have them show up in Sentry.
9+
- You may use top level API (`Sentry.addFeatureFlag("my-feature-flag", true);`) or `IScope` and `IScopes` API
10+
- Feature flag evaluations tracked on scope(s) will be added to any errors reported to Sentry.
11+
- The SDK keeps the latest 100 evaluations from scope(s), replacing old entries as new evaluations are added.
12+
513
### Fixes
614

715
- Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846))

sentry-samples/sentry-samples-console-opentelemetry-noagent/src/main/java/io/sentry/samples/console/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public static void main(String[] args) throws InterruptedException {
6161
// Only data added to the scope on `configureScope` above is included.
6262
Sentry.captureMessage("Some warning!", SentryLevel.WARNING);
6363

64+
Sentry.addFeatureFlag("my-feature-flag", true);
65+
6466
// Sending exception:
6567
Exception exception = new RuntimeException("Some error!");
6668
Sentry.captureException(exception);

sentry-samples/sentry-samples-console-opentelemetry-noagent/src/test/kotlin/sentry/systemtest/ConsoleApplicationSystemTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ConsoleApplicationSystemTest {
5555
// Verify we received the RuntimeException
5656
testHelper.ensureErrorReceived { event ->
5757
event.exceptions?.any { ex -> ex.type == "RuntimeException" && ex.value == "Some error!" } ==
58-
true
58+
true && testHelper.doesEventHaveFlag(event, "my-feature-flag", true)
5959
}
6060

6161
// Verify we received the detailed event with fingerprint

sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public static void main(String[] args) throws InterruptedException {
126126
// Only data added to the scope on `configureScope` above is included.
127127
Sentry.captureMessage("Some warning!", SentryLevel.WARNING);
128128

129+
Sentry.addFeatureFlag("my-feature-flag", true);
130+
129131
// Sending exception:
130132
Exception exception = new RuntimeException("Some error!");
131133
Sentry.captureException(exception);

sentry-samples/sentry-samples-console/src/test/kotlin/io/sentry/systemtest/ConsoleApplicationSystemTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ConsoleApplicationSystemTest {
5151
// Verify we received the RuntimeException
5252
testHelper.ensureErrorReceived { event ->
5353
event.exceptions?.any { ex -> ex.type == "RuntimeException" && ex.value == "Some error!" } ==
54-
true
54+
true && testHelper.doesEventHaveFlag(event, "my-feature-flag", true)
5555
}
5656

5757
// Verify we received the detailed event with fingerprint

sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.samples.jul;
22

3+
import io.sentry.Sentry;
34
import java.util.UUID;
45
import java.util.logging.Level;
56
import java.util.logging.LogManager;
@@ -22,6 +23,10 @@ public static void main(String[] args) throws Exception {
2223
MDC.put("userId", UUID.randomUUID().toString());
2324
MDC.put("requestId", UUID.randomUUID().toString());
2425

26+
Sentry.addFeatureFlag("my-feature-flag", true);
27+
28+
LOGGER.warning("important warning");
29+
2530
// logging arguments are converted to Sentry Event parameters
2631
LOGGER.log(Level.INFO, "User has made a purchase of product: %d", 445);
2732

sentry-samples/sentry-samples-jul/src/test/kotlin/io/sentry/systemtest/ConsoleApplicationSystemTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class ConsoleApplicationSystemTest {
5757
} != null
5858
}
5959

60+
testHelper.ensureErrorReceived { event ->
61+
event.message?.message == "important warning" &&
62+
testHelper.doesEventHaveFlag(event, "my-feature-flag", true)
63+
}
64+
6065
testHelper.ensureLogsReceived { logs, _ ->
6166
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
6267
testHelper.doesContainLogWithBody(logs, "Something went wrong")

sentry-samples/sentry-samples-log4j2/src/main/java/io/sentry/samples/log4j2/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.samples.log4j2;
22

3+
import io.sentry.Sentry;
34
import java.util.UUID;
45
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
@@ -19,6 +20,8 @@ public static void main(String[] args) {
1920
// ThreadContext tag not listed in log4j2.xml
2021
ThreadContext.put("context-tag", "context-tag-value");
2122

23+
Sentry.addFeatureFlag("my-feature-flag", true);
24+
2225
// logging arguments are converted to Sentry Event parameters
2326
LOGGER.info("User has made a purchase of product: {}", 445);
2427
// because minimumEventLevel is set to WARN this raises an event

sentry-samples/sentry-samples-log4j2/src/test/kotlin/io/sentry/systemtest/ConsoleApplicationSystemTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class ConsoleApplicationSystemTest {
4747
event.level?.name == "ERROR"
4848
}
4949

50+
testHelper.ensureErrorReceived { event ->
51+
event.message?.message == "Important warning" &&
52+
testHelper.doesEventHaveFlag(event, "my-feature-flag", true)
53+
}
54+
5055
testHelper.ensureErrorReceived { event ->
5156
event.breadcrumbs?.firstOrNull {
5257
it.message == "Hello Sentry!" && it.level == SentryLevel.DEBUG

sentry-samples/sentry-samples-logback/src/main/java/io/sentry/samples/logback/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.samples.logback;
22

3+
import io.sentry.Sentry;
34
import java.util.UUID;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
@@ -17,6 +18,9 @@ public static void main(String[] args) {
1718
// MDC tag not listed in logback.xml
1819
MDC.put("context-tag", "context-tag-value");
1920

21+
Sentry.addFeatureFlag("my-feature-flag", true);
22+
LOGGER.warn("important warning");
23+
2024
// logging arguments are converted to Sentry Event parameters
2125
LOGGER.info("User has made a purchase of product: {}", 445);
2226

0 commit comments

Comments
 (0)