Skip to content

Commit 9da8135

Browse files
adinauerclaude
andcommitted
feat(samples): Showcase scope attributes in all sample modules
Add Sentry.setAttribute() calls to all sample source files and corresponding attribute assertions to all system tests. This extends the scope attributes showcase from sentry-samples-spring-boot-4 to all 19 remaining sample modules with system tests. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8e61d4d commit 9da8135

File tree

66 files changed

+369
-33
lines changed

Some content is hidden

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

66 files changed

+369
-33
lines changed

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
@@ -63,6 +63,8 @@ public static void main(String[] args) throws InterruptedException {
6363

6464
Sentry.addFeatureFlag("my-feature-flag", true);
6565

66+
Sentry.setAttribute("user.type", "admin");
67+
Sentry.setAttribute("feature.version", 2);
6668
captureMetrics();
6769

6870
// Sending exception:

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class ConsoleApplicationSystemTest {
111111
testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
112112
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
113113
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
114-
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
114+
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0) &&
115+
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "user.type", "admin") &&
116+
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "feature.version", 2)
115117
}
116118
}
117119
}

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
@@ -128,6 +128,8 @@ public static void main(String[] args) throws InterruptedException {
128128

129129
Sentry.addFeatureFlag("my-feature-flag", true);
130130

131+
Sentry.setAttribute("user.type", "admin");
132+
Sentry.setAttribute("feature.version", 2);
131133
captureMetrics();
132134

133135
// Sending exception:

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ class ConsoleApplicationSystemTest {
106106
testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
107107
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
108108
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
109-
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
109+
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0) &&
110+
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "user.type", "admin") &&
111+
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "feature.version", 2)
110112
}
111113
}
112114
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void main(String[] args) throws Exception {
2323
MDC.put("userId", UUID.randomUUID().toString());
2424
MDC.put("requestId", UUID.randomUUID().toString());
2525

26+
Sentry.setAttribute("user.type", "admin");
27+
Sentry.setAttribute("feature.version", 2);
28+
Sentry.setAttribute("debug.enabled", true);
2629
Sentry.addFeatureFlag("my-feature-flag", true);
2730

2831
LOGGER.warning("important warning");

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,20 @@ class ConsoleApplicationSystemTest {
6464

6565
testHelper.ensureLogsReceived { logs, _ ->
6666
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
67-
testHelper.doesContainLogWithBody(logs, "Something went wrong")
67+
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
68+
testHelper.doesLogWithBodyHaveAttribute(
69+
logs,
70+
"Something went wrong",
71+
"user.type",
72+
"admin",
73+
) &&
74+
testHelper.doesLogWithBodyHaveAttribute(
75+
logs,
76+
"Something went wrong",
77+
"feature.version",
78+
2,
79+
) &&
80+
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
6881
}
6982
}
7083
}

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
@@ -20,6 +20,9 @@ public static void main(String[] args) {
2020
// ThreadContext tag not listed in log4j2.xml
2121
ThreadContext.put("context-tag", "context-tag-value");
2222

23+
Sentry.setAttribute("user.type", "admin");
24+
Sentry.setAttribute("feature.version", 2);
25+
Sentry.setAttribute("debug.enabled", true);
2326
Sentry.addFeatureFlag("my-feature-flag", true);
2427

2528
// logging arguments are converted to Sentry Event parameters

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,20 @@ class ConsoleApplicationSystemTest {
6666

6767
testHelper.ensureLogsReceived { logs, _ ->
6868
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
69-
testHelper.doesContainLogWithBody(logs, "Something went wrong")
69+
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
70+
testHelper.doesLogWithBodyHaveAttribute(
71+
logs,
72+
"Something went wrong",
73+
"user.type",
74+
"admin",
75+
) &&
76+
testHelper.doesLogWithBodyHaveAttribute(
77+
logs,
78+
"Something went wrong",
79+
"feature.version",
80+
2,
81+
) &&
82+
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
7083
}
7184
}
7285
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public static void main(String[] args) {
1818
// MDC tag not listed in logback.xml
1919
MDC.put("context-tag", "context-tag-value");
2020

21+
Sentry.setAttribute("user.type", "admin");
22+
Sentry.setAttribute("feature.version", 2);
23+
Sentry.setAttribute("debug.enabled", true);
2124
Sentry.addFeatureFlag("my-feature-flag", true);
2225
LOGGER.warn("important warning");
2326

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,20 @@ class ConsoleApplicationSystemTest {
6666

6767
testHelper.ensureLogsReceived { logs, _ ->
6868
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
69-
testHelper.doesContainLogWithBody(logs, "Something went wrong")
69+
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
70+
testHelper.doesLogWithBodyHaveAttribute(
71+
logs,
72+
"Something went wrong",
73+
"user.type",
74+
"admin",
75+
) &&
76+
testHelper.doesLogWithBodyHaveAttribute(
77+
logs,
78+
"Something went wrong",
79+
"feature.version",
80+
2,
81+
) &&
82+
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
7083
}
7184
}
7285
}

0 commit comments

Comments
 (0)