Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions sentry/src/main/java/io/sentry/logger/LoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ private void captureLog(
final @NotNull SpanId spanId,
final @Nullable Object... args) {
final @NotNull HashMap<String, SentryLogEventAttributeValue> 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();

Expand Down
37 changes: 37 additions & 0 deletions sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Loading