Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ff555aa
feat(core): Add scope-level attributes API
adinauer Feb 26, 2026
7cd38e6
changelog
adinauer Feb 26, 2026
de80a23
ref: Split out LoggerApi/MetricsApi changes for stacked PR
adinauer Feb 26, 2026
f4e82bf
feat(core): Wire scope attributes into LoggerApi and MetricsApi
adinauer Feb 26, 2026
d535d44
changelog
adinauer Feb 26, 2026
5974800
feat(samples): Showcase scope attributes in Spring Boot 4 samples
adinauer Feb 26, 2026
7189bdc
changelog
adinauer Feb 26, 2026
082fab0
Revert "changelog"
adinauer Feb 26, 2026
f0a2a21
ref: Remove redundant comments from variant controllers
adinauer Feb 26, 2026
12d88f2
ref: Limit scope attributes sample to base Spring Boot 4 variant
adinauer Feb 26, 2026
bb056cc
fix: Detect integer attribute type correctly for all integer Number s…
adinauer Feb 26, 2026
3791872
changelog
adinauer Feb 26, 2026
858da6c
feat: Support collections and arrays in log attribute type inference
adinauer Feb 26, 2026
ff23f6e
changelog
adinauer Feb 26, 2026
8e61d4d
test: Add coverage for arrayAttribute factory method
adinauer Feb 27, 2026
9da8135
feat(samples): Showcase scope attributes in all sample modules
adinauer Mar 3, 2026
afd3c6a
Merge branch 'main' into feat/samples-scope-attributes
adinauer Mar 4, 2026
9cea27a
Format code
getsentry-bot Mar 4, 2026
492014c
ci: trigger CI re-run
adinauer Mar 6, 2026
a14b34d
ci: retrigger CI
adinauer Mar 9, 2026
8607285
Merge branch 'main' into feat/samples-scope-attributes
adinauer Mar 10, 2026
aa6733c
remove duplicate changelog
adinauer Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public static void main(String[] args) throws InterruptedException {

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

Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
captureMetrics();

// Sending exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class ConsoleApplicationSystemTest {
testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0) &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "feature.version", 2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public static void main(String[] args) throws InterruptedException {

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

Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
captureMetrics();

// Sending exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class ConsoleApplicationSystemTest {
testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0) &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "feature.version", 2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static void main(String[] args) throws Exception {
MDC.put("userId", UUID.randomUUID().toString());
MDC.put("requestId", UUID.randomUUID().toString());

Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.addFeatureFlag("my-feature-flag", true);

LOGGER.warning("important warning");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,20 @@ class ConsoleApplicationSystemTest {

testHelper.ensureLogsReceived { logs, _ ->
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
testHelper.doesContainLogWithBody(logs, "Something went wrong")
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static void main(String[] args) {
// ThreadContext tag not listed in log4j2.xml
ThreadContext.put("context-tag", "context-tag-value");

Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.addFeatureFlag("my-feature-flag", true);

// logging arguments are converted to Sentry Event parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@ class ConsoleApplicationSystemTest {

testHelper.ensureLogsReceived { logs, _ ->
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
testHelper.doesContainLogWithBody(logs, "Something went wrong")
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static void main(String[] args) {
// MDC tag not listed in logback.xml
MDC.put("context-tag", "context-tag-value");

Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.addFeatureFlag("my-feature-flag", true);
LOGGER.warn("important warning");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@ class ConsoleApplicationSystemTest {

testHelper.ensureLogsReceived { logs, _ ->
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
testHelper.doesContainLogWithBody(logs, "Something went wrong")
testHelper.doesContainLogWithBody(logs, "Something went wrong") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"Something went wrong",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "Something went wrong", "debug.enabled", true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MetricController {

@GetMapping("count")
String count() {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.metrics().count("countMetric");
return "count metric increased";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable("id") Long id) {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class MetricsSystemTest {
assertEquals(200, restClient.lastKnownStatusCode)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0) &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "feature.version", 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ class PersonSystemTest {
testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
testHelper.doesContainLogWithBody(logs, "hello there world!") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "warn Sentry logging", "debug.enabled", true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MetricController {

@GetMapping("count")
String count() {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.metrics().count("countMetric");
return "count metric increased";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Person person(@PathVariable Long id) {
Sentry.addFeatureFlag("outer-feature-flag", true);
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class MetricsSystemTest {
assertEquals(200, restClient.lastKnownStatusCode)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0) &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "feature.version", 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ class PersonSystemTest {
testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
testHelper.doesContainLogWithBody(logs, "hello there world!") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "warn Sentry logging", "debug.enabled", true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MetricController {

@GetMapping("count")
String count() {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.metrics().count("countMetric");
return "count metric increased";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Person person(@PathVariable Long id) {
Sentry.addFeatureFlag("transaction-feature-flag", true);
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class MetricsSystemTest {
assertEquals(200, restClient.lastKnownStatusCode)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0) &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "feature.version", 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ class PersonSystemTest {
testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
testHelper.doesContainLogWithBody(logs, "hello there world!") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "warn Sentry logging", "debug.enabled", true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MetricController {

@GetMapping("count")
String count() {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.metrics().count("countMetric");
return "count metric increased";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class MetricsSystemTest {
assertEquals(200, restClient.lastKnownStatusCode)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0) &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "feature.version", 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ class PersonSystemTest {
testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
testHelper.doesContainLogWithBody(logs, "hello there world!") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "warn Sentry logging", "debug.enabled", true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MetricController {

@GetMapping("count")
String count() {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.metrics().count("countMetric");
return "count metric increased";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Person person(@PathVariable Long id) {
Sentry.addFeatureFlag("outer-feature-flag", true);
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.setAttribute("user.type", "admin");
Sentry.setAttribute("feature.version", 2);
Sentry.setAttribute("debug.enabled", true);
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class MetricsSystemTest {
assertEquals(200, restClient.lastKnownStatusCode)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0) &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(event, "countMetric", "feature.version", 2)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ class PersonSystemTest {
testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
testHelper.doesContainLogWithBody(logs, "hello there world!") &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"user.type",
"admin",
) &&
testHelper.doesLogWithBodyHaveAttribute(
logs,
"warn Sentry logging",
"feature.version",
2,
) &&
testHelper.doesLogWithBodyHaveAttribute(logs, "warn Sentry logging", "debug.enabled", true)
}
}

Expand Down
Loading
Loading