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 @@ -64,9 +64,6 @@ jobs:
- sample: "sentry-samples-console-otlp"
agent: "false"
agent-auto-init: "true"
- sample: "sentry-samples-logback"
agent: "false"
agent-auto-init: "true"
- sample: "sentry-samples-log4j2"
agent: "false"
agent-auto-init: "true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.sentry.logback

import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.joran.JoranConfigurator
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.slf4j.MDC

class SentryAppenderIntegrationTest {
private val server = MockSentryServer()
private val loggerContext = LoggerContext()

@AfterTest
fun teardown() {
loggerContext.stop()
Sentry.close()
server.close()
MDC.clear()
}

@Test
fun `appender configured from XML sends events, breadcrumbs and logs`() {
loggerContext.putProperty("dsn", server.dsn)
JoranConfigurator()
.apply { context = loggerContext }
.doConfigure(javaClass.getResource("/sentry-appender-integration-test.xml"))
val logger = loggerContext.getLogger(SentryAppenderIntegrationTest::class.java)

logger.debug("Hello Sentry!")
MDC.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.warn("important warning")
logger.info("User has made a purchase of product: {}", 445)
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,18 @@
<configuration>
<appender name="sentry" class="io.sentry.logback.SentryAppender">
<options>
<dsn>${dsn}</dsn>
<contextTag>userId</contextTag>
<logs>
<enabled>true</enabled>
</logs>
</options>
<minimumEventLevel>WARN</minimumEventLevel>
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
<minimumLevel>INFO</minimumLevel>
</appender>

<root level="debug">
<appender-ref ref="sentry"/>
</root>
</configuration>
37 changes: 0 additions & 37 deletions sentry-samples/sentry-samples-logback/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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.logback.Main") }
Expand All @@ -20,23 +16,9 @@ configure<JavaPluginExtension> {
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile>().configureEach {
kotlin {
compilerOptions.freeCompilerArgs = listOf("-Xjsr305=strict")
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

dependencies {
implementation(projects.sentryLogback)
implementation(libs.logback.classic)

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 @@ -54,22 +36,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 @@ -874,7 +874,6 @@ def get_available_modules(self) -> List[ModuleConfig]:
ModuleConfig("sentry-samples-console", "false", "true", "false"),
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