Skip to content

Commit 81e1075

Browse files
runningcodeclaude
andcommitted
test(logback): Move the logback sample's system test into sentry-logback
The test now configures the appender from XML in-process and sends to MockSentryServer, so it runs as part of :sentry-logback:test instead of needing the Python runner and a shadow JAR. It also checks that the XML contextTag reaches the event. The logback sample has no tests left, so its system-test wiring, CI matrix entry and runner entry are removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent c7cf960 commit 81e1075

7 files changed

Lines changed: 86 additions & 137 deletions

File tree

‎.github/workflows/system-tests-backend.yml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ jobs:
6464
- sample: "sentry-samples-console-otlp"
6565
agent: "false"
6666
agent-auto-init: "true"
67-
- sample: "sentry-samples-logback"
68-
agent: "false"
69-
agent-auto-init: "true"
7067
- sample: "sentry-samples-log4j2"
7168
agent: "false"
7269
agent-auto-init: "true"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.sentry.logback
2+
3+
import ch.qos.logback.classic.LoggerContext
4+
import ch.qos.logback.classic.joran.JoranConfigurator
5+
import com.google.common.truth.Truth.assertThat
6+
import io.sentry.Sentry
7+
import io.sentry.SentryLevel
8+
import io.sentry.test.MockSentryServer
9+
import io.sentry.test.event
10+
import io.sentry.test.hasFlag
11+
import io.sentry.test.logs
12+
import kotlin.test.AfterTest
13+
import kotlin.test.Test
14+
import org.slf4j.MDC
15+
16+
class SentryAppenderIntegrationTest {
17+
private val server = MockSentryServer()
18+
private val loggerContext = LoggerContext()
19+
20+
@AfterTest
21+
fun teardown() {
22+
loggerContext.stop()
23+
Sentry.close()
24+
server.close()
25+
MDC.clear()
26+
}
27+
28+
@Test
29+
fun `appender configured from XML sends events, breadcrumbs and logs`() {
30+
loggerContext.putProperty("dsn", server.dsn)
31+
JoranConfigurator()
32+
.apply { context = loggerContext }
33+
.doConfigure(javaClass.getResource("/sentry-appender-integration-test.xml"))
34+
val logger = loggerContext.getLogger(SentryAppenderIntegrationTest::class.java)
35+
36+
logger.debug("Hello Sentry!")
37+
MDC.put("userId", "user-1")
38+
Sentry.setAttribute("user.type", "admin")
39+
Sentry.setAttribute("feature.version", 2)
40+
Sentry.setAttribute("debug.enabled", true)
41+
Sentry.addFeatureFlag("my-feature-flag", true)
42+
logger.warn("important warning")
43+
logger.info("User has made a purchase of product: {}", 445)
44+
logger.error("Something went wrong", RuntimeException("Invalid productId=445"))
45+
Sentry.flush(5000)
46+
47+
val warning = server.awaitEnvelope { it.event()?.level == SentryLevel.WARNING }.event()!!
48+
assertThat(warning.message!!.message).isEqualTo("important warning")
49+
assertThat(warning.tags).containsEntry("userId", "user-1")
50+
assertThat(warning.hasFlag("my-feature-flag", true)).isTrue()
51+
52+
val error = server.awaitEnvelope { it.event()?.level == SentryLevel.ERROR }.event()!!
53+
assertThat(error.message!!.formatted).isEqualTo("Something went wrong")
54+
assertThat(error.exceptions!!.map { it.type to it.value })
55+
.contains("RuntimeException" to "Invalid productId=445")
56+
assertThat(error.breadcrumbs!!.map { it.message to it.level })
57+
.containsAtLeast(
58+
"Hello Sentry!" to SentryLevel.DEBUG,
59+
"User has made a purchase of product: 445" to SentryLevel.INFO,
60+
)
61+
62+
val logs = server.awaitEnvelope { it.logs() != null }.logs()!!
63+
assertThat(logs.items.map { it.body }).contains("User has made a purchase of product: 445")
64+
val failureLog = logs.items.single { it.body == "Something went wrong" }
65+
assertThat(failureLog.attributes!!.mapValues { it.value.value })
66+
.containsAtLeast("user.type", "admin", "feature.version", 2, "debug.enabled", true)
67+
}
68+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<configuration>
2+
<appender name="sentry" class="io.sentry.logback.SentryAppender">
3+
<options>
4+
<dsn>${dsn}</dsn>
5+
<contextTag>userId</contextTag>
6+
<logs>
7+
<enabled>true</enabled>
8+
</logs>
9+
</options>
10+
<minimumEventLevel>WARN</minimumEventLevel>
11+
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
12+
<minimumLevel>INFO</minimumLevel>
13+
</appender>
14+
15+
<root level="debug">
16+
<appender-ref ref="sentry"/>
17+
</root>
18+
</configuration>
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2-
31
plugins {
42
java
53
application
6-
alias(libs.plugins.kotlin.jvm)
74
alias(libs.plugins.gradle.versions)
85
alias(libs.plugins.shadow)
9-
id("io.sentry.systemtest")
106
}
117

128
application { mainClass.set("io.sentry.samples.logback.Main") }
139

14-
tasks.withType<KotlinCompile>().configureEach {
15-
kotlin {
16-
compilerOptions.freeCompilerArgs = listOf("-Xjsr305=strict")
17-
}
18-
}
19-
2010
dependencies {
2111
implementation(projects.sentryLogback)
2212
implementation(libs.logback.classic)
23-
24-
testImplementation(kotlin(Config.kotlinStdLib))
25-
testImplementation(projects.sentry)
26-
testImplementation(projects.sentrySystemTestSupport)
27-
testImplementation(libs.kotlin.test.junit)
28-
testImplementation(libs.slf4j.api)
29-
testImplementation(libs.slf4j.jdk14)
3013
}
3114

3215
// Configure the Shadow JAR (executable JAR with all dependencies)
@@ -44,22 +27,3 @@ tasks.jar {
4427

4528
// Fix the startScripts task dependency
4629
tasks.startScripts { dependsOn(tasks.shadowJar) }
47-
48-
tasks.register<Test>("systemTest").configure {
49-
group = "verification"
50-
description = "Runs the System tests"
51-
52-
val test = project.extensions.getByType<SourceSetContainer>()["test"]
53-
testClassesDirs = test.output.classesDirs
54-
classpath = test.runtimeClasspath
55-
56-
maxParallelForks = 1
57-
58-
filter { includeTestsMatching("io.sentry.systemtest*") }
59-
}
60-
61-
tasks.named("test").configure {
62-
require(this is Test)
63-
64-
filter { excludeTestsMatching("io.sentry.systemtest.*") }
65-
}

‎sentry-samples/sentry-samples-logback/src/test/kotlin/io/sentry/DummyTest.kt‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 85 deletions
This file was deleted.

‎test/system-test-runner.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ def get_available_modules(self) -> List[ModuleConfig]:
874874
ModuleConfig("sentry-samples-console", "false", "true", "false"),
875875
ModuleConfig("sentry-samples-console-otlp", "false", "true", "false"),
876876
ModuleConfig("sentry-samples-console-opentelemetry-noagent", "false", "true", "false"),
877-
ModuleConfig("sentry-samples-logback", "false", "true", "false"),
878877
ModuleConfig("sentry-samples-log4j2", "false", "true", "false"),
879878
ModuleConfig("sentry-samples-jul", "false", "true", "false"),
880879
]

0 commit comments

Comments
 (0)