From fa28acb7030412649b6c7e65baa315defc3bffff Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 28 Jul 2023 10:29:15 +0200 Subject: [PATCH 1/3] Add an option for opting out of pretty print --- sentry/api/sentry.api | 2 ++ .../main/java/io/sentry/JsonSerializer.java | 2 +- .../main/java/io/sentry/SentryOptions.java | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 10c1b80af3..4d75f795cd 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -1823,6 +1823,7 @@ public class io/sentry/SentryOptions { public fun isEnableUncaughtExceptionHandler ()Z public fun isEnableUserInteractionBreadcrumbs ()Z public fun isEnableUserInteractionTracing ()Z + public fun isPrettyPrintSerializationOutput ()Z public fun isPrintUncaughtStackTrace ()Z public fun isProfilingEnabled ()Z public fun isSendClientReports ()Z @@ -1877,6 +1878,7 @@ public class io/sentry/SentryOptions { public fun setMaxSpans (I)V public fun setMaxTraceFileSize (J)V public fun setModulesLoader (Lio/sentry/internal/modules/IModulesLoader;)V + public fun setPrettyPrintSerializationOutput (Z)V public fun setPrintUncaughtStackTrace (Z)V public fun setProfilesSampleRate (Ljava/lang/Double;)V public fun setProfilesSampler (Lio/sentry/SentryOptions$ProfilesSamplerCallback;)V diff --git a/sentry/src/main/java/io/sentry/JsonSerializer.java b/sentry/src/main/java/io/sentry/JsonSerializer.java index 8018211d56..d496ea0ea4 100644 --- a/sentry/src/main/java/io/sentry/JsonSerializer.java +++ b/sentry/src/main/java/io/sentry/JsonSerializer.java @@ -183,7 +183,7 @@ public void serialize(@NotNull T entity, @NotNull Writer writer) throws IOEx Objects.requireNonNull(writer, "The Writer object is required."); if (options.getLogger().isEnabled(SentryLevel.DEBUG)) { - String serialized = serializeToString(entity, true); + String serialized = serializeToString(entity, options.isPrettyPrintSerializationOutput()); options.getLogger().log(SentryLevel.DEBUG, "Serializing object: %s", serialized); } JsonObjectWriter jsonObjectWriter = new JsonObjectWriter(writer, options.getMaxDepth()); diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index c5bbb2aeeb..315c998d28 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -434,6 +434,9 @@ public class SentryOptions { private final @NotNull FullyDisplayedReporter fullyDisplayedReporter = FullyDisplayedReporter.getInstance(); + /** Whether to format serialized data, e.g. events logged to console in debug mode */ + private boolean prettyPrintSerializationOutput = true; + /** * Adds an event processor * @@ -2096,6 +2099,24 @@ public void setTraceOptionsRequests(boolean traceOptionsRequests) { this.traceOptionsRequests = traceOptionsRequests; } + /** + * Whether to format serialized data, e.g. events logged to console in debug mode + * + * @return true if data should be pretty printed + */ + public boolean isPrettyPrintSerializationOutput() { + return prettyPrintSerializationOutput; + } + + /** + * Whether to format serialized data, e.g. events logged to console in debug mode + * + * @param prettyPrintSerializationOutput true if output should be pretty printed + */ + public void setPrettyPrintSerializationOutput(boolean prettyPrintSerializationOutput) { + this.prettyPrintSerializationOutput = prettyPrintSerializationOutput; + } + /** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */ @ApiStatus.Internal public @NotNull SentryDateProvider getDateProvider() { From 89079d78c6559737664f57446bdc145ce0b3356a Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 9 Aug 2023 07:42:13 +0200 Subject: [PATCH 2/3] Rename; add to external options --- sentry/api/sentry.api | 4 ++++ .../src/main/java/io/sentry/ExternalOptions.java | 13 +++++++++++++ .../src/main/java/io/sentry/JsonSerializer.java | 2 +- sentry/src/main/java/io/sentry/SentryOptions.java | 15 +++++++++------ .../src/test/java/io/sentry/SentryOptionsTest.kt | 7 +++++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 978f582bed..3e28178bbf 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -284,11 +284,13 @@ public final class io/sentry/ExternalOptions { public fun getTracePropagationTargets ()Ljava/util/List; public fun getTracesSampleRate ()Ljava/lang/Double; public fun getTracingOrigins ()Ljava/util/List; + public fun isEnablePrettySerializationOutput ()Ljava/lang/Boolean; public fun isEnabled ()Ljava/lang/Boolean; public fun setDebug (Ljava/lang/Boolean;)V public fun setDist (Ljava/lang/String;)V public fun setDsn (Ljava/lang/String;)V public fun setEnableDeduplication (Ljava/lang/Boolean;)V + public fun setEnablePrettySerializationOutput (Ljava/lang/Boolean;)V public fun setEnableTracing (Ljava/lang/Boolean;)V public fun setEnableUncaughtExceptionHandler (Ljava/lang/Boolean;)V public fun setEnabled (Ljava/lang/Boolean;)V @@ -1825,6 +1827,7 @@ public class io/sentry/SentryOptions { public fun isEnableDeduplication ()Z public fun isEnableExternalConfiguration ()Z public fun isEnableNdk ()Z + public fun isEnablePrettySerializationOutput ()Z public fun isEnableScopeSync ()Z public fun isEnableShutdownHook ()Z public fun isEnableTimeToFullDisplayTracing ()Z @@ -1859,6 +1862,7 @@ public class io/sentry/SentryOptions { public fun setEnableDeduplication (Z)V public fun setEnableExternalConfiguration (Z)V public fun setEnableNdk (Z)V + public fun setEnablePrettySerializationOutput (Z)V public fun setEnableScopeSync (Z)V public fun setEnableShutdownHook (Z)V public fun setEnableTimeToFullDisplayTracing (Z)V diff --git a/sentry/src/main/java/io/sentry/ExternalOptions.java b/sentry/src/main/java/io/sentry/ExternalOptions.java index 1d5f71431e..0bdd89f247 100644 --- a/sentry/src/main/java/io/sentry/ExternalOptions.java +++ b/sentry/src/main/java/io/sentry/ExternalOptions.java @@ -43,6 +43,7 @@ public final class ExternalOptions { private @Nullable Boolean sendClientReports; private @NotNull Set bundleIds = new CopyOnWriteArraySet<>(); private @Nullable Boolean enabled; + private @Nullable Boolean enablePrettySerializationOutput; @SuppressWarnings("unchecked") public static @NotNull ExternalOptions from( @@ -118,6 +119,9 @@ public final class ExternalOptions { options.setEnabled(propertiesProvider.getBooleanProperty("enabled")); + options.setEnablePrettySerializationOutput( + propertiesProvider.getBooleanProperty("enable-pretty-serialization-output")); + for (final String ignoredExceptionType : propertiesProvider.getList("ignored-exceptions-for-type")) { try { @@ -358,4 +362,13 @@ public void addBundleId(final @NotNull String bundleId) { public void setEnabled(final @Nullable Boolean enabled) { this.enabled = enabled; } + + public @Nullable Boolean isEnablePrettySerializationOutput() { + return enablePrettySerializationOutput; + } + + public void setEnablePrettySerializationOutput( + final @Nullable Boolean enablePrettySerializationOutput) { + this.enablePrettySerializationOutput = enablePrettySerializationOutput; + } } diff --git a/sentry/src/main/java/io/sentry/JsonSerializer.java b/sentry/src/main/java/io/sentry/JsonSerializer.java index d496ea0ea4..a7d0bb10c3 100644 --- a/sentry/src/main/java/io/sentry/JsonSerializer.java +++ b/sentry/src/main/java/io/sentry/JsonSerializer.java @@ -183,7 +183,7 @@ public void serialize(@NotNull T entity, @NotNull Writer writer) throws IOEx Objects.requireNonNull(writer, "The Writer object is required."); if (options.getLogger().isEnabled(SentryLevel.DEBUG)) { - String serialized = serializeToString(entity, options.isPrettyPrintSerializationOutput()); + String serialized = serializeToString(entity, options.isEnablePrettySerializationOutput()); options.getLogger().log(SentryLevel.DEBUG, "Serializing object: %s", serialized); } JsonObjectWriter jsonObjectWriter = new JsonObjectWriter(writer, options.getMaxDepth()); diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 8aa767a453..7a0b0daab7 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -438,7 +438,7 @@ public class SentryOptions { private boolean enabled = true; /** Whether to format serialized data, e.g. events logged to console in debug mode */ - private boolean prettyPrintSerializationOutput = true; + private boolean enablePrettySerializationOutput = true; /** * Adds an event processor @@ -2125,17 +2125,17 @@ public void setEnabled(boolean enabled) { * * @return true if data should be pretty printed */ - public boolean isPrettyPrintSerializationOutput() { - return prettyPrintSerializationOutput; + public boolean isEnablePrettySerializationOutput() { + return enablePrettySerializationOutput; } /** * Whether to format serialized data, e.g. events logged to console in debug mode * - * @param prettyPrintSerializationOutput true if output should be pretty printed + * @param enablePrettySerializationOutput true if output should be pretty printed */ - public void setPrettyPrintSerializationOutput(boolean prettyPrintSerializationOutput) { - this.prettyPrintSerializationOutput = prettyPrintSerializationOutput; + public void setEnablePrettySerializationOutput(boolean enablePrettySerializationOutput) { + this.enablePrettySerializationOutput = enablePrettySerializationOutput; } /** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */ @@ -2379,6 +2379,9 @@ public void merge(final @NotNull ExternalOptions options) { if (options.isEnabled() != null) { setEnabled(options.isEnabled()); } + if (options.isEnablePrettySerializationOutput() != null) { + setEnablePrettySerializationOutput(options.isEnablePrettySerializationOutput()); + } } private @NotNull SdkVersion createSdkVersion() { diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index a5304d7de3..3e34435ac6 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -369,6 +369,7 @@ class SentryOptionsTest { externalOptions.idleTimeout = 1500L externalOptions.bundleIds.addAll(listOf("12ea7a02-46ac-44c0-a5bb-6d1fd9586411 ", " faa3ab42-b1bd-4659-af8e-1682324aa744")) externalOptions.isEnabled = false + externalOptions.isEnablePrettySerializationOutput = false val options = SentryOptions() options.merge(externalOptions) @@ -394,6 +395,7 @@ class SentryOptionsTest { assertEquals(1500L, options.idleTimeout) assertEquals(setOf("12ea7a02-46ac-44c0-a5bb-6d1fd9586411", "faa3ab42-b1bd-4659-af8e-1682324aa744"), options.bundleIds) assertFalse(options.isEnabled) + assertFalse(options.isEnablePrettySerializationOutput) } @Test @@ -490,4 +492,9 @@ class SentryOptionsTest { fun `when options are initialized, enabled is set to true by default`() { assertTrue(SentryOptions().isEnabled) } + + @Test + fun `when options are initialized, enablePrettySerializationOutput is set to true by default`() { + assertTrue(SentryOptions().isEnablePrettySerializationOutput) + } } From 841eb431fed37265c75279bc414ab79e6a1f5b94 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 9 Aug 2023 07:45:45 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f927dd571..d0a8dd6323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Add `enablePrettySerializationOutput` option for opting out of pretty print ([#2871](https://github.com/getsentry/sentry-java/pull/2871)) + ## 6.28.0 ### Features