Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .github/workflows/system-tests-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
- sample: "sentry-samples-logback"
agent: "false"
agent-auto-init: "true"
- sample: "sentry-samples-log4j2"
agent: "false"
agent-auto-init: "true"
- sample: "sentry-samples-jul"
agent: "false"
agent-auto-init: "true"
Expand Down
1 change: 1 addition & 0 deletions sentry-log4j2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
// tests
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(libs.google.truth)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.log4j.api)
testImplementation(libs.log4j.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.sentry.log4j2

import com.google.common.truth.Truth.assertThat
import io.sentry.Sentry
import io.sentry.SentryLevel
import io.sentry.test.MockSentryServer
import io.sentry.test.event
import io.sentry.test.hasFlag
import io.sentry.test.logs
import kotlin.test.AfterTest
import kotlin.test.Test
import org.apache.logging.log4j.ThreadContext
import org.apache.logging.log4j.core.LoggerContext

class SentryAppenderIntegrationTest {
private val server = MockSentryServer()

// A context of its own, so the other tests' context keeps its configuration.
private val loggerContext =
LoggerContext(
"sentry-appender-integration-test",
null,
javaClass.getResource("/sentry-appender-integration-test.xml")!!.toURI(),
)

@AfterTest
fun teardown() {
loggerContext.stop()
Sentry.close()
server.close()
ThreadContext.clearAll()
System.clearProperty("integrationTestDsn")
System.clearProperty("sentry.logs.enabled")
}

@Test
fun `appender configured from XML sends events, breadcrumbs and logs`() {
System.setProperty("integrationTestDsn", server.dsn)
// The appender has no attribute for logs, so they're enabled the way an app's sentry.properties
// would: as external configuration.
System.setProperty("sentry.logs.enabled", "true")
loggerContext.start()
val logger = loggerContext.getLogger(SentryAppenderIntegrationTest::class.java.name)

logger.debug("Hello Sentry!")
ThreadContext.put("userId", "user-1")
Sentry.setAttribute("user.type", "admin")
Sentry.setAttribute("feature.version", 2)
Sentry.setAttribute("debug.enabled", true)
Sentry.addFeatureFlag("my-feature-flag", true)
logger.info("User has made a purchase of product: {}", 445)
logger.warn("Important warning")
logger.error("Something went wrong", RuntimeException("Invalid productId=445"))
Sentry.flush(5000)

val warning = server.awaitEnvelope { it.event()?.level == SentryLevel.WARNING }.event()!!
assertThat(warning.message!!.message).isEqualTo("Important warning")
assertThat(warning.tags).containsEntry("userId", "user-1")
assertThat(warning.hasFlag("my-feature-flag", true)).isTrue()

val error = server.awaitEnvelope { it.event()?.level == SentryLevel.ERROR }.event()!!
assertThat(error.message!!.formatted).isEqualTo("Something went wrong")
assertThat(error.exceptions!!.map { it.type to it.value })
.contains("RuntimeException" to "Invalid productId=445")
assertThat(error.breadcrumbs!!.map { it.message to it.level })
.containsAtLeast(
"Hello Sentry!" to SentryLevel.DEBUG,
"User has made a purchase of product: 445" to SentryLevel.INFO,
)

val logs = server.awaitEnvelope { it.logs() != null }.logs()!!
assertThat(logs.items.map { it.body }).contains("User has made a purchase of product: 445")
val failureLog = logs.items.single { it.body == "Something went wrong" }
assertThat(failureLog.attributes!!.mapValues { it.value.value })
.containsAtLeast("user.type", "admin", "feature.version", 2, "debug.enabled", true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Sentry name="Sentry"
dsn="${sys:integrationTestDsn}"
minimumBreadcrumbLevel="DEBUG"
minimumEventLevel="WARN"
minimumLevel="DEBUG"
contextTags="userId"
/>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Sentry"/>
</Root>
</Loggers>
</Configuration>
36 changes: 0 additions & 36 deletions sentry-samples/sentry-samples-log4j2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
application
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.shadow)
id("io.sentry.systemtest")
}

application { mainClass.set("io.sentry.samples.log4j2.Main") }

tasks.withType<KotlinCompile>().configureEach {
kotlin {
compilerOptions.freeCompilerArgs = listOf("-Xjsr305=strict")
}
}

dependencies {
implementation(projects.sentryLog4j2)
implementation(libs.log4j.api)
implementation(libs.log4j.core)

testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(projects.sentry)
testImplementation(projects.sentrySystemTestSupport)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.slf4j.api)
testImplementation(libs.slf4j.jdk14)
}

// Configure the Shadow JAR (executable JAR with all dependencies)
Expand All @@ -50,22 +33,3 @@ tasks.jar {

// Fix the startScripts task dependency
tasks.startScripts { dependsOn(tasks.shadowJar) }

tasks.register<Test>("systemTest").configure {
group = "verification"
description = "Runs the System tests"

val test = project.extensions.getByType<SourceSetContainer>()["test"]
testClassesDirs = test.output.classesDirs
classpath = test.runtimeClasspath

maxParallelForks = 1

filter { includeTestsMatching("io.sentry.systemtest*") }
}

tasks.named("test").configure {
require(this is Test)

filter { excludeTestsMatching("io.sentry.systemtest.*") }
}

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test/system-test-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ def get_available_modules(self) -> List[ModuleConfig]:
ModuleConfig("sentry-samples-console-otlp", "false", "true", "false"),
ModuleConfig("sentry-samples-console-opentelemetry-noagent", "false", "true", "false"),
ModuleConfig("sentry-samples-logback", "false", "true", "false"),
ModuleConfig("sentry-samples-log4j2", "false", "true", "false"),
ModuleConfig("sentry-samples-jul", "false", "true", "false"),
]

Expand Down
Loading