Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public DefaultAndroidEventProcessor(
return event;
}

@Override
public @Nullable SentryMetricsEvent process(@NotNull SentryMetricsEvent event) {
setDevice(event);
setOs(event);
return event;
}

/**
* The last exception is usually used for picking the issue title, but the convention is to send
* inner exceptions first, e.g. [inner, outer] This doesn't work very well on Android, as some
Expand Down Expand Up @@ -248,6 +255,34 @@ private void setOs(final @NotNull SentryLogEvent event) {
}
}

private void setDevice(final @NotNull SentryMetricsEvent event) {
try {
event.setAttribute(
"device.brand",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.BRAND));
event.setAttribute(
"device.model",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.MODEL));
event.setAttribute(
"device.family",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, deviceFamily.getValue()));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve device info", e);
}
}

private void setOs(final @NotNull SentryMetricsEvent event) {
try {
event.setAttribute(
"os.name", new SentryLogEventAttributeValue(SentryAttributeType.STRING, "Android"));
event.setAttribute(
"os.version",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, Build.VERSION.RELEASE));
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to retrieve os system", e);
}
}

// Data to be applied to events that was created in the running process
private void processNonCachedEvent(
final @NotNull SentryBaseEvent event, final @NotNull Hint hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import android.os.Build
import android.os.Looper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.sentry.DateUtils
import io.sentry.DiagnosticLogger
import io.sentry.Hint
import io.sentry.IScopes
import io.sentry.SentryEvent
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryLogLevel
import io.sentry.SentryMetricsEvent
import io.sentry.SentryTracer
import io.sentry.TransactionContext
import io.sentry.TypeCheckHint.SENTRY_DART_SDK_NAME
import io.sentry.android.core.internal.util.CpuInfoUtils
import io.sentry.protocol.OperatingSystem
import io.sentry.protocol.SdkVersion
import io.sentry.protocol.SentryException
import io.sentry.protocol.SentryId
import io.sentry.protocol.SentryStackFrame
import io.sentry.protocol.SentryStackTrace
import io.sentry.protocol.SentryThread
Expand Down Expand Up @@ -619,4 +624,45 @@ class DefaultAndroidEventProcessorTest {
assertEquals("IllegalArgumentException", it.exceptions!![1].type)
}
}

@Test
fun `device and os are set on metric`() {
val sut = fixture.getSut(context)
val processedEvent: SentryMetricsEvent? =
sut.process(
SentryMetricsEvent(
SentryId("5c1f73d39486827b9e60ceb1fc23277a"),
DateUtils.dateToSeconds(DateUtils.getDateTime("2004-04-10T18:24:03.000Z")),
"42e6bd2a-c45e-414d-8066-ed5196fbc686",
"counter",
123.0,
)
)

assertNotNull(processedEvent?.attributes?.get("device.brand"))
assertNotNull(processedEvent?.attributes?.get("device.model"))
assertNotNull(processedEvent?.attributes?.get("device.family"))
assertNotNull(processedEvent?.attributes?.get("os.name"))
assertNotNull(processedEvent?.attributes?.get("os.version"))
}

@Test
fun `device and os are set on log`() {
val sut = fixture.getSut(context)
val processedEvent: SentryLogEvent? =
sut.process(
SentryLogEvent(
SentryId("5c1f73d39486827b9e60ceb1fc23277a"),
DateUtils.dateToSeconds(DateUtils.getDateTime("2004-04-10T18:24:03.000Z")),
"message",
SentryLogLevel.WARN,
)
)

assertNotNull(processedEvent?.attributes?.get("device.brand"))
assertNotNull(processedEvent?.attributes?.get("device.model"))
assertNotNull(processedEvent?.attributes?.get("device.family"))
assertNotNull(processedEvent?.attributes?.get("os.name"))
assertNotNull(processedEvent?.attributes?.get("os.version"))
}
}
Loading