From b5a31c5c453b93729131c44978cf3bd2e426fa58 Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 3 Apr 2025 16:24:58 +0200 Subject: [PATCH 1/7] Read build tool info from sentry-debug-meta.properties and attach it to events --- sentry/api/sentry.api | 3 + .../util/DebugMetaPropertiesApplier.java | 37 ++++++++++ .../debugmeta/ResourcesDebugMetaLoaderTest.kt | 72 +++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 796284690d8..637f19ccdb3 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -6364,7 +6364,10 @@ public abstract interface class io/sentry/util/CollectionUtils$Predicate { public final class io/sentry/util/DebugMetaPropertiesApplier { public static field DEBUG_META_PROPERTIES_FILENAME Ljava/lang/String; public fun ()V + public static fun apply (Lio/sentry/SentryOptions;Ljava/util/List;)V public static fun applyToOptions (Lio/sentry/SentryOptions;Ljava/util/List;)V + public static fun getBuildTool (Ljava/util/Properties;)Ljava/lang/String; + public static fun getBuildToolVersion (Ljava/util/Properties;)Ljava/lang/String; public static fun getProguardUuid (Ljava/util/Properties;)Ljava/lang/String; } diff --git a/sentry/src/main/java/io/sentry/util/DebugMetaPropertiesApplier.java b/sentry/src/main/java/io/sentry/util/DebugMetaPropertiesApplier.java index 86278459670..236e9626826 100644 --- a/sentry/src/main/java/io/sentry/util/DebugMetaPropertiesApplier.java +++ b/sentry/src/main/java/io/sentry/util/DebugMetaPropertiesApplier.java @@ -1,5 +1,6 @@ package io.sentry.util; +import io.sentry.SentryIntegrationPackageStorage; import io.sentry.SentryLevel; import io.sentry.SentryOptions; import java.util.List; @@ -11,6 +12,14 @@ public final class DebugMetaPropertiesApplier { public static @NotNull String DEBUG_META_PROPERTIES_FILENAME = "sentry-debug-meta.properties"; + public static void apply( + final @NotNull SentryOptions options, final @Nullable List debugMetaProperties) { + if (debugMetaProperties != null) { + applyToOptions(options, debugMetaProperties); + applyBuildTool(options, debugMetaProperties); + } + } + public static void applyToOptions( final @NotNull SentryOptions options, final @Nullable List debugMetaProperties) { if (debugMetaProperties != null) { @@ -49,7 +58,35 @@ private static void applyProguardUuid( } } + private static void applyBuildTool( + final @NotNull SentryOptions options, @NotNull List debugMetaProperties) { + for (Properties properties : debugMetaProperties) { + final @Nullable String buildTool = getBuildTool(properties); + if (buildTool != null) { + @Nullable String buildToolVersion = getBuildToolVersion(properties); + if (buildToolVersion == null) { + buildToolVersion = "unknown"; + } + options + .getLogger() + .log( + SentryLevel.DEBUG, "Build tool found: %s, version %s", buildTool, buildToolVersion); + SentryIntegrationPackageStorage.getInstance().addPackage(buildTool, buildToolVersion); + break; + } + } + } + public static @Nullable String getProguardUuid(final @NotNull Properties debugMetaProperties) { return debugMetaProperties.getProperty("io.sentry.ProguardUuids"); } + + public static @Nullable String getBuildTool(final @NotNull Properties debugMetaProperties) { + return debugMetaProperties.getProperty("io.sentry.build-tool"); + } + + public static @Nullable String getBuildToolVersion( + final @NotNull Properties debugMetaProperties) { + return debugMetaProperties.getProperty("io.sentry.build-tool-version"); + } } diff --git a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt index d9a22224b5e..970e9bb2141 100644 --- a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt @@ -1,7 +1,9 @@ package io.sentry.internal.debugmeta import io.sentry.ILogger +import io.sentry.SentryIntegrationPackageStorage import io.sentry.SentryOptions +import io.sentry.protocol.SentryPackage import io.sentry.util.DebugMetaPropertiesApplier import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -9,7 +11,9 @@ import java.net.URL import java.nio.charset.Charset import java.util.Collections import kotlin.test.Test +import kotlin.test.assertContains import kotlin.test.assertEquals +import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -132,4 +136,72 @@ class ResourcesDebugMetaLoaderTest { assertNull(sut.loadDebugMeta()) } + + @Test + fun `reads build-tool and build-version and adds them to packages`() { + val sut = fixture.getSut( + content = listOf( + """ + #Generated by sentry-maven-plugin + #Wed May 17 15:33:34 CEST 2023 + io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b + io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 + io.sentry.build-tool=maven + io.sentry.build-tool-version=1.0 + """.trimIndent() + ) + ) + + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { + DebugMetaPropertiesApplier.apply(options, it) + } + + val expected = SentryPackage("maven", "1.0") + assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) + } + + @Test + fun `reads build-tool and adds it to packages with unknown version if build-tool-version is absent`() { + val sut = fixture.getSut( + content = listOf( + """ + #Generated by sentry-maven-plugin + #Wed May 17 15:33:34 CEST 2023 + io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b + io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 + io.sentry.build-tool=maven + """.trimIndent() + ) + ) + + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { + DebugMetaPropertiesApplier.apply(options, it) + } + + val expected = SentryPackage("maven", "unknown") + assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) + } + + @Test + fun `does not add build-tool to packages if absent`() { + val sut = fixture.getSut( + content = listOf( + """ + #Generated manually + #Wed May 17 15:33:34 CEST 2023 + io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b + io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 + """.trimIndent() + ) + ) + + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { + DebugMetaPropertiesApplier.apply(options, it) + } + + assertFalse { SentryIntegrationPackageStorage.getInstance().packages.any { it.name.equals("io.sentry.build-tool") } } + } } From 2a4fb268f200254e8ccc615af0b3cfe549d6866a Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 3 Apr 2025 16:55:13 +0200 Subject: [PATCH 2/7] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64bb9941951..9cd7aaaa5b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Internal + +- Read build tool info from `sentry-debug-meta.properties` and attach it to events ([#4314](https://github.com/getsentry/sentry-java/pull/4314)) + ## 8.6.0 ### Behavioral Changes From b58cbd0987f81b7fd22d69c050a2bd95d2b62af5 Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 3 Jul 2025 15:42:20 +0200 Subject: [PATCH 3/7] update --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07b3ec102d1..c774f3da7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,6 @@ - Use thread context classloader when available ([#4320](https://github.com/getsentry/sentry-java/pull/4320)) - This ensures correct resource loading in environments like Spring Boot where the thread context classloader is used for resource loading. -### Internal - -- Read build tool info from `sentry-debug-meta.properties` and attach it to events ([#4314](https://github.com/getsentry/sentry-java/pull/4314)) - ## 8.7.0 ### Features From 8d180649871cc2c4c6a75098abc951058af8227e Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 3 Jul 2025 13:47:31 +0000 Subject: [PATCH 4/7] Format code --- .../debugmeta/ResourcesDebugMetaLoaderTest.kt | 95 ++++++++++--------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt index 372426c594c..6871f542c93 100644 --- a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt @@ -41,7 +41,7 @@ class ResourcesDebugMetaLoaderTest { return ResourcesDebugMetaLoader(logger, classLoader) } } - + private val fixture = Fixture() @Test @@ -145,70 +145,77 @@ class ResourcesDebugMetaLoaderTest { } @Test - fun `reads build-tool and build-version and adds them to packages`() { - val sut = fixture.getSut( - content = listOf( - """ + fun `reads build-tool and build-version and adds them to packages`() { + val sut = + fixture.getSut( + content = + listOf( + """ #Generated by sentry-maven-plugin #Wed May 17 15:33:34 CEST 2023 io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 io.sentry.build-tool=maven io.sentry.build-tool-version=1.0 - """.trimIndent() - ) - ) + """ + .trimIndent() + ) + ) - val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { - DebugMetaPropertiesApplier.apply(options, it) - } + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } - val expected = SentryPackage("maven", "1.0") - assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) - } + val expected = SentryPackage("maven", "1.0") + assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) + } - @Test - fun `reads build-tool and adds it to packages with unknown version if build-tool-version is absent`() { - val sut = fixture.getSut( - content = listOf( - """ + @Test + fun `reads build-tool and adds it to packages with unknown version if build-tool-version is absent`() { + val sut = + fixture.getSut( + content = + listOf( + """ #Generated by sentry-maven-plugin #Wed May 17 15:33:34 CEST 2023 io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 io.sentry.build-tool=maven - """.trimIndent() - ) - ) + """ + .trimIndent() + ) + ) - val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { - DebugMetaPropertiesApplier.apply(options, it) - } + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } - val expected = SentryPackage("maven", "unknown") - assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) - } + val expected = SentryPackage("maven", "unknown") + assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected) + } - @Test - fun `does not add build-tool to packages if absent`() { - val sut = fixture.getSut( - content = listOf( - """ + @Test + fun `does not add build-tool to packages if absent`() { + val sut = + fixture.getSut( + content = + listOf( + """ #Generated manually #Wed May 17 15:33:34 CEST 2023 io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68 - """.trimIndent() - ) - ) + """ + .trimIndent() + ) + ) - val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { - DebugMetaPropertiesApplier.apply(options, it) - } + val options = SentryOptions() + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } - assertFalse { SentryIntegrationPackageStorage.getInstance().packages.any { it.name.equals("io.sentry.build-tool") } } - } + assertFalse { + SentryIntegrationPackageStorage.getInstance().packages.any { + it.name.equals("io.sentry.build-tool") + } + } + } } From e1b00ac80c846ec61ceacd33012e6205b51bf930 Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 3 Jul 2025 15:47:53 +0200 Subject: [PATCH 5/7] improve --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8664c008b6a..cb014d09c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Read build tool info from `sentry-debug-meta.properties` and attach it to events ([#4314](https://github.com/getsentry/sentry-java/pull/4314)) + ### Fixes - Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504)) From 2f9b72860a29216630f28e339853e6e0718d509e Mon Sep 17 00:00:00 2001 From: lcian Date: Mon, 7 Jul 2025 11:12:09 +0200 Subject: [PATCH 6/7] changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58805235811..15284b55eda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog -## 8.16.1-alpha.2 +## Unreleased ### Features - Read build tool info from `sentry-debug-meta.properties` and attach it to events ([#4314](https://github.com/getsentry/sentry-java/pull/4314)) +## 8.16.1-alpha.2 + ### Fixes - Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504)) From bea38598fa9777495926912f91cc760c0c5722ea Mon Sep 17 00:00:00 2001 From: lcian Date: Mon, 7 Jul 2025 14:51:23 +0200 Subject: [PATCH 7/7] update --- sentry/src/main/java/io/sentry/Sentry.java | 2 +- .../internal/debugmeta/ResourcesDebugMetaLoaderTest.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index 1aa03ff3049..0596f8f2ffb 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -645,7 +645,7 @@ private static void initConfigurations(final @NotNull SentryOptions options) { options.setDebugMetaLoader(new ResourcesDebugMetaLoader(options.getLogger())); } final @Nullable List propertiesList = options.getDebugMetaLoader().loadDebugMeta(); - DebugMetaPropertiesApplier.applyToOptions(options, propertiesList); + DebugMetaPropertiesApplier.apply(options, propertiesList); final IThreadChecker threadChecker = options.getThreadChecker(); // only override the ThreadChecker if it's not already set by Android diff --git a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt index 6871f542c93..0e776717436 100644 --- a/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt @@ -63,7 +63,7 @@ class ResourcesDebugMetaLoaderTest { val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.applyToOptions(options, it) } + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } assertEquals(options.bundleIds, setOf("88ba82db-cd26-4c09-8b31-21461d286b68")) assertEquals(options.proguardUuid, "34077988-a0e5-4839-9618-7400e1616d1b") @@ -88,7 +88,7 @@ class ResourcesDebugMetaLoaderTest { val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.applyToOptions(options, it) } + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } assertEquals( options.bundleIds, @@ -124,7 +124,7 @@ class ResourcesDebugMetaLoaderTest { val options = SentryOptions() - assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.applyToOptions(options, it) } + assertNotNull(sut.loadDebugMeta()) { DebugMetaPropertiesApplier.apply(options, it) } assertEquals( options.bundleIds,