33import android .content .Context ;
44import android .content .pm .PackageInfo ;
55import android .content .pm .PackageManager ;
6+ import android .os .Build ;
7+
68import io .sentry .DateUtils ;
79import io .sentry .EventProcessor ;
810import io .sentry .Hint ;
911import io .sentry .IpAddressUtils ;
12+ import io .sentry .NoOpLogger ;
13+ import io .sentry .SentryAttributeType ;
1014import io .sentry .SentryBaseEvent ;
1115import io .sentry .SentryEvent ;
1216import io .sentry .SentryLevel ;
17+ import io .sentry .SentryLogEvent ;
18+ import io .sentry .SentryLogEventAttributeValue ;
1319import io .sentry .SentryReplayEvent ;
1420import io .sentry .android .core .internal .util .AndroidThreadChecker ;
1521import io .sentry .android .core .performance .AppStartMetrics ;
2329import io .sentry .protocol .SentryTransaction ;
2430import io .sentry .protocol .User ;
2531import io .sentry .util .HintUtils ;
32+ import io .sentry .util .LazyEvaluator ;
2633import io .sentry .util .Objects ;
2734import java .util .Collections ;
2835import java .util .List ;
@@ -42,6 +49,7 @@ final class DefaultAndroidEventProcessor implements EventProcessor {
4249 private final @ NotNull BuildInfoProvider buildInfoProvider ;
4350 private final @ NotNull SentryAndroidOptions options ;
4451 private final @ NotNull Future <DeviceInfoUtil > deviceInfoUtil ;
52+ private final @ NotNull LazyEvaluator <String > deviceFamily = new LazyEvaluator <>(() -> ContextUtils .getFamily (NoOpLogger .getInstance ()));
4553
4654 public DefaultAndroidEventProcessor (
4755 final @ NotNull Context context ,
@@ -81,6 +89,13 @@ public DefaultAndroidEventProcessor(
8189 return event ;
8290 }
8391
92+ @ Override
93+ public @ Nullable SentryLogEvent process (@ NotNull SentryLogEvent event ) {
94+ setDevice (event );
95+ setOs (event );
96+ return event ;
97+ }
98+
8499 /**
85100 * The last exception is usually used for picking the issue title, but the convention is to send
86101 * inner exceptions first, e.g. [inner, outer] This doesn't work very well on Android, as some
@@ -199,6 +214,35 @@ private void mergeOS(final @NotNull SentryBaseEvent event) {
199214 }
200215 }
201216
217+ private void setDevice (final @ NotNull SentryLogEvent event ) {
218+ try {
219+ event .setAttribute (
220+ "device.brand" ,
221+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , Build .BRAND ));
222+ event .setAttribute (
223+ "device.model" ,
224+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , Build .MODEL ));
225+ event .setAttribute (
226+ "device.family" ,
227+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , deviceFamily .getValue ()));
228+ } catch (Throwable e ) {
229+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve device info" , e );
230+ }
231+ }
232+
233+ private void setOs (final @ NotNull SentryLogEvent event ) {
234+ try {
235+ event .setAttribute (
236+ "os.name" ,
237+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , "Android" ));
238+ event .setAttribute (
239+ "os.version" ,
240+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , Build .VERSION .RELEASE ));
241+ } catch (Throwable e ) {
242+ options .getLogger ().log (SentryLevel .ERROR , "Failed to retrieve os system" , e );
243+ }
244+ }
245+
202246 // Data to be applied to events that was created in the running process
203247 private void processNonCachedEvent (
204248 final @ NotNull SentryBaseEvent event , final @ NotNull Hint hint ) {
0 commit comments