Skip to content

Commit 6847e31

Browse files
authored
[Logs 7] Add System tests for Logs (#4386)
* Add Log feature to Java SDK * Rate limit for log items * Add options for logs * Add batch processor for logs * Use a separate ExecutorService for log batching * Reduce locking when log event is created * Add system tests for Logs
1 parent 740abb1 commit 6847e31

File tree

39 files changed

+297
-9
lines changed

39 files changed

+297
-9
lines changed

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/java/io/sentry/samples/spring/boot/jakarta/PersonController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public PersonController(PersonService personService, Tracer tracer) {
3333
Person person(@PathVariable Long id) {
3434
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
3535
try (final @NotNull Scope spanScope = span.makeCurrent()) {
36+
Sentry.logger().warn("warn Sentry logging");
37+
Sentry.logger().error("error Sentry logging");
38+
Sentry.logger().info("hello %s %s", "there", "world!");
3639
ISpan currentSpan = Sentry.getSpan();
3740
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
3841
try {

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
1515
sentry.enable-backpressure-handling=true
1616
sentry.enable-spotlight=true
1717
sentry.enablePrettySerializationOutput=false
18+
sentry.experimental.logs.enabled=true
1819
in-app-includes="io.sentry.samples"
1920

2021
# Uncomment and set to true to enable aot compatibility

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class PersonSystemTest {
2525
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
2626
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
2727
}
28+
29+
Thread.sleep(10000)
30+
31+
testHelper.ensureLogsReceived { logs, envelopeHeader ->
32+
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
33+
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
34+
testHelper.doesContainLogWithBody(logs, "hello there world!")
35+
}
2836
}
2937

3038
@Test

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/java/io/sentry/samples/spring/boot/jakarta/PersonController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public PersonController(PersonService personService, Tracer tracer) {
3131
Person person(@PathVariable Long id) {
3232
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
3333
try (final @NotNull Scope spanScope = span.makeCurrent()) {
34+
Sentry.logger().warn("warn Sentry logging");
35+
Sentry.logger().error("error Sentry logging");
36+
Sentry.logger().info("hello %s %s", "there", "world!");
3437
ISpan currentSpan = Sentry.getSpan();
3538
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
3639
try {

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
1515
sentry.enable-backpressure-handling=true
1616
sentry.enable-spotlight=true
1717
sentry.enablePrettySerializationOutput=false
18+
sentry.experimental.logs.enabled=true
1819
in-app-includes="io.sentry.samples"
1920

2021
# Uncomment and set to true to enable aot compatibility

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class PersonSystemTest {
2525
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
2626
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
2727
}
28+
29+
Thread.sleep(10000)
30+
31+
testHelper.ensureLogsReceived { logs, envelopeHeader ->
32+
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
33+
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
34+
testHelper.doesContainLogWithBody(logs, "hello there world!")
35+
}
2836
}
2937

3038
@Test

sentry-samples/sentry-samples-spring-boot-jakarta/src/main/java/io/sentry/samples/spring/boot/jakarta/PersonController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Person person(@PathVariable Long id) {
2626
ISpan currentSpan = Sentry.getSpan();
2727
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
2828
try {
29+
Sentry.logger().warn("warn Sentry logging");
30+
Sentry.logger().error("error Sentry logging");
31+
Sentry.logger().info("hello %s %s", "there", "world!");
2932
LOGGER.error("Trying person with id={}", id, new RuntimeException("error while loading"));
3033
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
3134
} finally {

sentry-samples/sentry-samples-spring-boot-jakarta/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class PersonSystemTest {
2424
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
2525
testHelper.doesTransactionHaveOp(transaction, "http.server")
2626
}
27+
28+
Thread.sleep(10000)
29+
30+
testHelper.ensureLogsReceived { logs, envelopeHeader ->
31+
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
32+
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
33+
testHelper.doesContainLogWithBody(logs, "hello there world!")
34+
}
2735
}
2836

2937
@Test

sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/java/io/sentry/samples/spring/boot/PersonController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public PersonController(PersonService personService, Tracer tracer) {
3333
Person person(@PathVariable Long id) {
3434
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
3535
try (final @NotNull Scope spanScope = span.makeCurrent()) {
36+
Sentry.logger().warn("warn Sentry logging");
37+
Sentry.logger().error("error Sentry logging");
38+
Sentry.logger().info("hello %s %s", "there", "world!");
3639
ISpan currentSpan = Sentry.getSpan();
3740
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
3841
try {

sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ sentry.debug=true
1414
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
1515
sentry.enable-backpressure-handling=true
1616
sentry.enable-spotlight=true
17+
sentry.experimental.logs.enabled=true
1718
in-app-includes="io.sentry.samples"
1819

1920
# Database configuration

0 commit comments

Comments
 (0)