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-jul"
agent: "false"
agent-auto-init: "true"
- sample: "sentry-samples-spring-boot-4-otlp"
agent: "false"
agent-auto-init: "true"
Expand Down
1 change: 1 addition & 0 deletions sentry-jul/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
// tests
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(libs.google.truth)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.logback.classic)
testImplementation(libs.mockito.kotlin)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.sentry.jul

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 java.util.logging.Level
import java.util.logging.LogManager
import java.util.logging.Logger
import kotlin.test.AfterTest
import kotlin.test.Test

class SentryHandlerIntegrationTest {
private val server = MockSentryServer()

@AfterTest
fun teardown() {
// Back to the configuration the other tests read, which also closes this test's handler.
LogManager.getLogManager().readConfiguration()
Sentry.close()
server.close()
System.clearProperty("sentry.dsn")
}

@Test
fun `handler configured from logging properties sends events, breadcrumbs and logs`() {
// The handler reads the DSN as external configuration, as an app's sentry.properties would
// set it. The module's test sentry.properties enables logs.
System.setProperty("sentry.dsn", server.dsn)
javaClass.getResourceAsStream("/sentry-handler-integration-test.properties")!!.use {
LogManager.getLogManager().readConfiguration(it)
}
// Outside io.sentry, whose loggers the handler drops so it doesn't capture the SDK's own logs.
val logger = Logger.getLogger("com.example.App")

logger.config("Hello Sentry!")
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")
logger.log(Level.INFO, "User has made a purchase of product: %d", 445)
logger.log(Level.SEVERE, "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.hasFlag("my-feature-flag", true)).isTrue()

val error = server.awaitEnvelope { it.event()?.level == SentryLevel.ERROR }.event()!!
assertThat(error.message!!.message).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,7 @@
handlers=io.sentry.jul.SentryHandler
.level=FINEST
io.sentry.jul.SentryHandler.level=FINEST
io.sentry.jul.SentryHandler.minimumEventLevel=INFO
io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG
io.sentry.jul.SentryHandler.minimumLevel=INFO
io.sentry.jul.SentryHandler.printfStyle=true
37 changes: 0 additions & 37 deletions sentry-samples/sentry-samples-jul/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.jul.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.sentryJul)
implementation(libs.slf4j.jdk14)

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 @@ -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-jul", "false", "true", "false"),
]

def _find_module_number(self, module_name: str, agent: str, auto_init: str) -> int:
Expand Down
Loading