diff --git a/CHANGELOG.md b/CHANGELOG.md index 4551f8ca2e..4bb577a438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Improvements + +- Do not send manual log origin ([#4897](https://github.com/getsentry/sentry-java/pull/4897)) + ## 8.26.0 ### Features diff --git a/sentry/src/main/java/io/sentry/logger/LoggerApi.java b/sentry/src/main/java/io/sentry/logger/LoggerApi.java index 1af9beb400..568bd6ac05 100644 --- a/sentry/src/main/java/io/sentry/logger/LoggerApi.java +++ b/sentry/src/main/java/io/sentry/logger/LoggerApi.java @@ -163,9 +163,11 @@ private void captureLog( final @NotNull SpanId spanId, final @Nullable Object... args) { final @NotNull HashMap attributes = new HashMap<>(); - attributes.put( - "sentry.origin", - new SentryLogEventAttributeValue(SentryAttributeType.STRING, params.getOrigin())); + final @NotNull String origin = params.getOrigin(); + if (!"manual".equalsIgnoreCase(origin)) { + attributes.put( + "sentry.origin", new SentryLogEventAttributeValue(SentryAttributeType.STRING, origin)); + } final @Nullable SentryAttributes incomingAttributes = params.getAttributes(); diff --git a/sentry/src/test/java/io/sentry/ScopesTest.kt b/sentry/src/test/java/io/sentry/ScopesTest.kt index 4a45e18d84..4eee9d1636 100644 --- a/sentry/src/test/java/io/sentry/ScopesTest.kt +++ b/sentry/src/test/java/io/sentry/ScopesTest.kt @@ -2585,6 +2585,43 @@ class ScopesTest { ) } + @Test + fun `log with manual origin does not have origin attribute`() { + val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true } + + sut.logger().log(SentryLogLevel.WARN, "log message") + + verify(mockClient) + .captureLog( + check { + assertEquals("log message", it.body) + assertNull(it.attributes!!.get("sentry.origin")) + }, + anyOrNull(), + ) + } + + @Test + fun `log with non manual origin does have origin attribute`() { + val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true } + + sut + .logger() + .log(SentryLogLevel.WARN, SentryLogParameters().also { it.origin = "other" }, "log message") + + verify(mockClient) + .captureLog( + check { + assertEquals("log message", it.body) + assertEquals( + "other", + (it.attributes!!.get("sentry.origin") as? SentryLogEventAttributeValue)?.value, + ) + }, + anyOrNull(), + ) + } + @Test fun `creating log with format string works`() { val (sut, mockClient) =