Skip to content

Commit 736f4a2

Browse files
marandanetoromtsn
andauthored
Ref: Make hints Map<String, Object> instead of only Object (#1929)
Co-authored-by: Roman Zavarnitsyn <[email protected]>
1 parent e948a50 commit 736f4a2

File tree

96 files changed

+1044
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1044
-483
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* Ref: Make hints Map<String, Object> instead of only Object (#1929)
56
* Feat: Enable enableScopeSync by default for Android (#1928)
67

78
## 6.0.0-alpha.2

sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.android.core;
22

33
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
4+
import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY;
45

56
import android.app.Activity;
67
import android.app.ActivityManager;
@@ -22,6 +23,7 @@
2223
import java.io.Closeable;
2324
import java.io.IOException;
2425
import java.util.Date;
26+
import java.util.HashMap;
2527
import java.util.List;
2628
import java.util.Map;
2729
import java.util.WeakHashMap;
@@ -123,7 +125,11 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri
123125
breadcrumb.setData("screen", getActivityName(activity));
124126
breadcrumb.setCategory("ui.lifecycle");
125127
breadcrumb.setLevel(SentryLevel.INFO);
126-
hub.addBreadcrumb(breadcrumb);
128+
129+
final Map<String, Object> hintMap = new HashMap<>();
130+
hintMap.put(ANDROID_ACTIVITY, activity);
131+
132+
hub.addBreadcrumb(breadcrumb, hintMap);
127133
}
128134
}
129135

sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.sentry.android.core;
22

3+
import static io.sentry.TypeCheckHint.ANDROID_CONFIGURATION;
4+
35
import android.content.ComponentCallbacks2;
46
import android.content.Context;
57
import android.content.res.Configuration;
@@ -13,7 +15,9 @@
1315
import io.sentry.util.Objects;
1416
import java.io.Closeable;
1517
import java.io.IOException;
18+
import java.util.HashMap;
1619
import java.util.Locale;
20+
import java.util.Map;
1721
import org.jetbrains.annotations.NotNull;
1822
import org.jetbrains.annotations.Nullable;
1923

@@ -95,7 +99,11 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
9599
breadcrumb.setCategory("device.orientation");
96100
breadcrumb.setData("position", orientation);
97101
breadcrumb.setLevel(SentryLevel.INFO);
98-
hub.addBreadcrumb(breadcrumb);
102+
103+
final Map<String, Object> hintMap = new HashMap<>();
104+
hintMap.put(ANDROID_CONFIGURATION, newConfig);
105+
106+
hub.addBreadcrumb(breadcrumb, hintMap);
99107
}
100108
}
101109

sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import io.sentry.protocol.SentryThread;
3535
import io.sentry.protocol.SentryTransaction;
3636
import io.sentry.protocol.User;
37-
import io.sentry.util.ApplyScopeUtils;
37+
import io.sentry.util.HintUtils;
3838
import io.sentry.util.Objects;
3939
import java.io.BufferedReader;
4040
import java.io.File;
@@ -117,7 +117,7 @@ public DefaultAndroidEventProcessor(
117117

118118
@Override
119119
public @NotNull SentryEvent process(
120-
final @NotNull SentryEvent event, final @Nullable Object hint) {
120+
final @NotNull SentryEvent event, final @Nullable Map<String, Object> hint) {
121121
final boolean applyScopeData = shouldApplyScopeData(event, hint);
122122
if (applyScopeData) {
123123
// we only set memory data if it's not a hard crash, when it's a hard crash the event is
@@ -143,8 +143,8 @@ private void setCommons(
143143
}
144144

145145
private boolean shouldApplyScopeData(
146-
final @NotNull SentryBaseEvent event, final @Nullable Object hint) {
147-
if (ApplyScopeUtils.shouldApplyScopeData(hint)) {
146+
final @NotNull SentryBaseEvent event, final @Nullable Map<String, Object> hint) {
147+
if (HintUtils.shouldApplyScopeData(hint)) {
148148
return true;
149149
} else {
150150
logger.log(
@@ -888,7 +888,7 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {
888888

889889
@Override
890890
public @NotNull SentryTransaction process(
891-
final @NotNull SentryTransaction transaction, final @Nullable Object hint) {
891+
final @NotNull SentryTransaction transaction, final @Nullable Map<String, Object> hint) {
892892
final boolean applyScopeData = shouldApplyScopeData(transaction, hint);
893893

894894
if (applyScopeData) {

sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.android.core;
22

33
import static io.sentry.SentryLevel.ERROR;
4+
import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT;
45

56
import android.os.FileObserver;
67
import io.sentry.IEnvelopeSender;
@@ -14,6 +15,8 @@
1415
import io.sentry.hints.SubmissionResult;
1516
import io.sentry.util.Objects;
1617
import java.io.File;
18+
import java.util.HashMap;
19+
import java.util.Map;
1720
import java.util.concurrent.CountDownLatch;
1821
import java.util.concurrent.TimeUnit;
1922
import org.jetbrains.annotations.NotNull;
@@ -56,7 +59,11 @@ public void onEvent(int eventType, @Nullable String relativePath) {
5659
// TODO: Only some event types should be pass through?
5760

5861
final CachedEnvelopeHint hint = new CachedEnvelopeHint(flushTimeoutMillis, logger);
59-
envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hint);
62+
63+
final Map<String, Object> hintMap = new HashMap<>();
64+
hintMap.put(SENTRY_TYPE_CHECK_HINT, hint);
65+
66+
envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hintMap);
6067
}
6168

6269
private static final class CachedEnvelopeHint

sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class PerformanceAndroidEventProcessor implements EventProcessor {
4242
*/
4343
@Override
4444
@Nullable
45-
public SentryEvent process(@NotNull SentryEvent event, @Nullable Object hint) {
45+
public SentryEvent process(@NotNull SentryEvent event, @Nullable Map<String, Object> hint) {
4646
// that's only necessary because on newer versions of Unity, if not overriding this method, it's
4747
// throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably
4848
// compilation mismatch.
@@ -52,7 +52,7 @@ public SentryEvent process(@NotNull SentryEvent event, @Nullable Object hint) {
5252
@SuppressWarnings("NullAway")
5353
@Override
5454
public synchronized @NotNull SentryTransaction process(
55-
@NotNull SentryTransaction transaction, @Nullable Object hint) {
55+
@NotNull SentryTransaction transaction, @Nullable Map<String, Object> hint) {
5656

5757
if (!options.isTracingEnabled()) {
5858
return transaction;

sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static android.content.Intent.ACTION_SHUTDOWN;
3131
import static android.content.Intent.ACTION_TIMEZONE_CHANGED;
3232
import static android.content.Intent.ACTION_TIME_CHANGED;
33+
import static io.sentry.TypeCheckHint.ANDROID_INTENT;
3334

3435
import android.content.BroadcastReceiver;
3536
import android.content.Context;
@@ -213,7 +214,11 @@ public void onReceive(Context context, Intent intent) {
213214
breadcrumb.setData("extras", newExtras);
214215
}
215216
breadcrumb.setLevel(SentryLevel.INFO);
216-
hub.addBreadcrumb(breadcrumb);
217+
218+
final Map<String, Object> hintMap = new HashMap<>();
219+
hintMap.put(ANDROID_INTENT, intent);
220+
221+
hub.addBreadcrumb(breadcrumb, hintMap);
217222
}
218223
}
219224
}

sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.android.core;
22

33
import static android.content.Context.SENSOR_SERVICE;
4+
import static io.sentry.TypeCheckHint.ANDROID_SENSOR_EVENT;
45

56
import android.content.Context;
67
import android.hardware.Sensor;
@@ -15,6 +16,8 @@
1516
import io.sentry.util.Objects;
1617
import java.io.Closeable;
1718
import java.io.IOException;
19+
import java.util.HashMap;
20+
import java.util.Map;
1821
import org.jetbrains.annotations.NotNull;
1922
import org.jetbrains.annotations.Nullable;
2023
import org.jetbrains.annotations.TestOnly;
@@ -103,7 +106,11 @@ public void onSensorChanged(final @NotNull SensorEvent event) {
103106
breadcrumb.setData("timestamp", event.timestamp);
104107
breadcrumb.setLevel(SentryLevel.INFO);
105108
breadcrumb.setData("degree", event.values[0]); // Celsius
106-
hub.addBreadcrumb(breadcrumb);
109+
110+
final Map<String, Object> hintMap = new HashMap<>();
111+
hintMap.put(ANDROID_SENSOR_EVENT, event);
112+
113+
hub.addBreadcrumb(breadcrumb, hintMap);
107114
}
108115
}
109116

sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.sentry.android.core.internal.gestures;
22

3+
import static io.sentry.TypeCheckHint.ANDROID_MOTION_EVENT;
4+
import static io.sentry.TypeCheckHint.ANDROID_VIEW;
5+
36
import android.view.GestureDetector;
47
import android.view.MotionEvent;
58
import android.view.View;
@@ -10,6 +13,7 @@
1013
import io.sentry.android.core.SentryAndroidOptions;
1114
import java.lang.ref.WeakReference;
1215
import java.util.Collections;
16+
import java.util.HashMap;
1317
import java.util.Map;
1418
import org.jetbrains.annotations.ApiStatus;
1519
import org.jetbrains.annotations.NotNull;
@@ -51,7 +55,11 @@ public void onUp(final @NotNull MotionEvent motionEvent) {
5155
}
5256

5357
final String direction = scrollState.calculateDirection(motionEvent);
54-
addBreadcrumb(scrollTarget, scrollState.type, Collections.singletonMap("direction", direction));
58+
addBreadcrumb(
59+
scrollTarget,
60+
scrollState.type,
61+
Collections.singletonMap("direction", direction),
62+
motionEvent);
5563
scrollState.reset();
5664
}
5765

@@ -88,7 +96,7 @@ public boolean onSingleTapUp(final @Nullable MotionEvent motionEvent) {
8896
return false;
8997
}
9098

91-
addBreadcrumb(target, "click", Collections.emptyMap());
99+
addBreadcrumb(target, "click", Collections.emptyMap(), motionEvent);
92100
return false;
93101
}
94102

@@ -154,7 +162,8 @@ public void onLongPress(MotionEvent motionEvent) {}
154162
private void addBreadcrumb(
155163
final @NotNull View target,
156164
final @NotNull String eventType,
157-
final @NotNull Map<String, Object> additionalData) {
165+
final @NotNull Map<String, Object> additionalData,
166+
final @NotNull MotionEvent motionEvent) {
158167
@NotNull String className;
159168
@Nullable String canonicalName = target.getClass().getCanonicalName();
160169
if (canonicalName != null) {
@@ -163,9 +172,14 @@ private void addBreadcrumb(
163172
className = target.getClass().getSimpleName();
164173
}
165174

175+
final Map<String, Object> hintMap = new HashMap<>();
176+
hintMap.put(ANDROID_MOTION_EVENT, motionEvent);
177+
hintMap.put(ANDROID_VIEW, target);
178+
166179
hub.addBreadcrumb(
167180
Breadcrumb.userInteraction(
168-
eventType, ViewUtils.getResourceId(target), className, additionalData));
181+
eventType, ViewUtils.getResourceId(target), className, additionalData),
182+
hintMap);
169183
}
170184

171185
private @Nullable View ensureWindowDecorView(final @NotNull String caller) {

0 commit comments

Comments
 (0)