diff --git a/sentry/src/main/java/io/sentry/SentryLogEventAttributeValue.java b/sentry/src/main/java/io/sentry/SentryLogEventAttributeValue.java index a733b42ad0..5ff1252d23 100644 --- a/sentry/src/main/java/io/sentry/SentryLogEventAttributeValue.java +++ b/sentry/src/main/java/io/sentry/SentryLogEventAttributeValue.java @@ -15,7 +15,11 @@ public final class SentryLogEventAttributeValue implements JsonUnknown, JsonSeri public SentryLogEventAttributeValue(final @NotNull String type, final @Nullable Object value) { this.type = type; - this.value = value; + if (value != null && type.equals("string")) { + this.value = value.toString(); + } else { + this.value = value; + } } public @NotNull String getType() { diff --git a/sentry/src/test/java/io/sentry/protocol/SentryLogsSerializationTest.kt b/sentry/src/test/java/io/sentry/protocol/SentryLogsSerializationTest.kt index be1343024e..9610efe2bb 100644 --- a/sentry/src/test/java/io/sentry/protocol/SentryLogsSerializationTest.kt +++ b/sentry/src/test/java/io/sentry/protocol/SentryLogsSerializationTest.kt @@ -32,7 +32,11 @@ class SentryLogsSerializationTest { "sentry.sdk.name" to SentryLogEventAttributeValue("string", "sentry.java.spring-boot.jakarta"), "sentry.environment" to SentryLogEventAttributeValue("string", "production"), "sentry.sdk.version" to SentryLogEventAttributeValue("string", "8.11.1"), - "sentry.trace.parent_span_id" to SentryLogEventAttributeValue("string", "f28b86350e534671") + "sentry.trace.parent_span_id" to SentryLogEventAttributeValue("string", "f28b86350e534671"), + "custom.boolean" to SentryLogEventAttributeValue("boolean", true), + "custom.double" to SentryLogEventAttributeValue("double", 11.12.toDouble()), + "custom.point" to SentryLogEventAttributeValue("string", Point(20, 30)), + "custom.integer" to SentryLogEventAttributeValue("integer", 10) ) it.severityNumber = 10 } @@ -75,4 +79,12 @@ class SentryLogsSerializationTest { val reader = JsonObjectReader(StringReader(json)) return SentryLogEvents.Deserializer().deserialize(reader, fixture.logger) } + + companion object { + data class Point(val x: Int, val y: Int) { + override fun toString(): String { + return "Point{x:$x,y:$y}-Hello" + } + } + } } diff --git a/sentry/src/test/resources/json/sentry_logs.json b/sentry/src/test/resources/json/sentry_logs.json index 120ddec7db..7040012c29 100644 --- a/sentry/src/test/resources/json/sentry_logs.json +++ b/sentry/src/test/resources/json/sentry_logs.json @@ -28,6 +28,24 @@ { "type": "string", "value": "f28b86350e534671" + }, + "custom.boolean": + { + "type": "boolean", + "value": true + }, + "custom.double": { + "type": "double", + "value": 11.12 + }, + "custom.point": { + "type": "string", + "value": "Point{x:20,y:30}-Hello" + }, + "custom.integer": + { + "type": "integer", + "value": 10 } } }