Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object #2045

Merged
merged 10 commits into from
May 23, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016))
- Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035))
- Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045](https://github.com/getsentry/sentry-java/pull/2045))

## 6.0.0-beta.3

Expand Down
2 changes: 1 addition & 1 deletion sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public final class io/sentry/android/core/ScreenshotEventProcessor : android/app
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityStarted (Landroid/app/Activity;)V
public fun onActivityStopped (Landroid/app/Activity;)V
public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent;
public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent;
}

public final class io/sentry/android/core/SentryAndroid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.SpanStatus;
import io.sentry.hints.Hints;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -126,10 +126,10 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri
breadcrumb.setCategory("ui.lifecycle");
breadcrumb.setLevel(SentryLevel.INFO);

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(ANDROID_ACTIVITY, activity);
final Hints hints = new Hints();
hints.set(ANDROID_ACTIVITY, activity);

hub.addBreadcrumb(breadcrumb, hintMap);
hub.addBreadcrumb(breadcrumb, hints);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.android.core.internal.util.DeviceOrientations;
import io.sentry.hints.Hints;
import io.sentry.protocol.Device;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -100,10 +99,10 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
breadcrumb.setData("position", orientation);
breadcrumb.setLevel(SentryLevel.INFO);

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(ANDROID_CONFIGURATION, newConfig);
final Hints hints = new Hints();
hints.set(ANDROID_CONFIGURATION, newConfig);

hub.addBreadcrumb(breadcrumb, hintMap);
hub.addBreadcrumb(breadcrumb, hints);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.sentry.android.core.internal.util.DeviceOrientations;
import io.sentry.android.core.internal.util.MainThreadChecker;
import io.sentry.android.core.internal.util.RootChecker;
import io.sentry.hints.Hints;
import io.sentry.protocol.App;
import io.sentry.protocol.Device;
import io.sentry.protocol.OperatingSystem;
Expand Down Expand Up @@ -117,8 +118,8 @@ public DefaultAndroidEventProcessor(

@Override
public @NotNull SentryEvent process(
final @NotNull SentryEvent event, final @Nullable Map<String, Object> hint) {
final boolean applyScopeData = shouldApplyScopeData(event, hint);
final @NotNull SentryEvent event, final @NotNull Hints hints) {
final boolean applyScopeData = shouldApplyScopeData(event, hints);
if (applyScopeData) {
// we only set memory data if it's not a hard crash, when it's a hard crash the event is
// enriched on restart, so non static data might be wrong, eg lowMemory or availMem will
Expand All @@ -143,8 +144,8 @@ private void setCommons(
}

private boolean shouldApplyScopeData(
final @NotNull SentryBaseEvent event, final @Nullable Map<String, Object> hint) {
if (HintUtils.shouldApplyScopeData(hint)) {
final @NotNull SentryBaseEvent event, final @NotNull Hints hints) {
if (HintUtils.shouldApplyScopeData(hints)) {
return true;
} else {
logger.log(
Expand Down Expand Up @@ -857,8 +858,8 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {

@Override
public @NotNull SentryTransaction process(
final @NotNull SentryTransaction transaction, final @Nullable Map<String, Object> hint) {
final boolean applyScopeData = shouldApplyScopeData(transaction, hint);
final @NotNull SentryTransaction transaction, final @NotNull Hints hints) {
final boolean applyScopeData = shouldApplyScopeData(transaction, hints);

if (applyScopeData) {
processNonCachedEvent(transaction);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.sentry.android.core;

import static io.sentry.SentryLevel.ERROR;
import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT;

import android.os.FileObserver;
import io.sentry.IEnvelopeSender;
Expand All @@ -10,13 +9,13 @@
import io.sentry.hints.ApplyScopeData;
import io.sentry.hints.Cached;
import io.sentry.hints.Flushable;
import io.sentry.hints.Hints;
import io.sentry.hints.Resettable;
import io.sentry.hints.Retryable;
import io.sentry.hints.SubmissionResult;
import io.sentry.util.HintUtils;
import io.sentry.util.Objects;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -60,10 +59,9 @@ public void onEvent(int eventType, @Nullable String relativePath) {

final CachedEnvelopeHint hint = new CachedEnvelopeHint(flushTimeoutMillis, logger);

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(SENTRY_TYPE_CHECK_HINT, hint);
final Hints hints = HintUtils.createWithTypeCheckHint(hint);

envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hintMap);
envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hints);
}

private static final class CachedEnvelopeHint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.sentry.EventProcessor;
import io.sentry.SentryEvent;
import io.sentry.SpanContext;
import io.sentry.hints.Hints;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.SentrySpan;
Expand Down Expand Up @@ -37,12 +38,12 @@ final class PerformanceAndroidEventProcessor implements EventProcessor {
* Returns the event itself
*
* @param event the SentryEvent the SentryEvent
* @param hint the Hint the Hint
* @param hints the Hint the Hint
* @return returns the event itself
*/
@Override
@Nullable
public SentryEvent process(@NotNull SentryEvent event, @Nullable Map<String, Object> hint) {
public SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) {
// that's only necessary because on newer versions of Unity, if not overriding this method, it's
// throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably
// compilation mismatch.
Expand All @@ -52,7 +53,7 @@ public SentryEvent process(@NotNull SentryEvent event, @Nullable Map<String, Obj
@SuppressWarnings("NullAway")
@Override
public synchronized @NotNull SentryTransaction process(
@NotNull SentryTransaction transaction, @Nullable Map<String, Object> hint) {
@NotNull SentryTransaction transaction, @NotNull Hints hints) {

if (!options.isTracingEnabled()) {
return transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import io.sentry.EventProcessor;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.hints.Hints;
import io.sentry.util.Objects;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -68,8 +67,7 @@ public ScreenshotEventProcessor(

@SuppressWarnings("NullAway")
@Override
public @NotNull SentryEvent process(
final @NotNull SentryEvent event, @Nullable Map<String, Object> hint) {
public @NotNull SentryEvent process(final @NotNull SentryEvent event, @NotNull Hints hints) {
if (options.isAttachScreenshot() && event.isErrored() && currentActivity != null) {
final Activity activity = currentActivity.get();
if (isActivityValid(activity)
Expand All @@ -93,16 +91,12 @@ public ScreenshotEventProcessor(
// Some formats, like PNG which is lossless, will ignore the quality setting.
bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream);

if (hint == null) {
hint = new HashMap<>();
}

if (byteArrayOutputStream.size() > 0) {
// screenshot png is around ~100-150 kb
hint.put(
hints.set(
SENTRY_SCREENSHOT,
Attachment.fromScreenshot(byteArrayOutputStream.toByteArray()));
hint.put(ANDROID_ACTIVITY, activity);
hints.set(ANDROID_ACTIVITY, activity);
} else {
this.options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.sentry.Integration;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.hints.Hints;
import io.sentry.util.Objects;
import io.sentry.util.StringUtils;
import java.io.Closeable;
Expand Down Expand Up @@ -215,10 +216,10 @@ public void onReceive(Context context, Intent intent) {
}
breadcrumb.setLevel(SentryLevel.INFO);

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(ANDROID_INTENT, intent);
final Hints hints = new Hints();
hints.set(ANDROID_INTENT, intent);

hub.addBreadcrumb(breadcrumb, hintMap);
hub.addBreadcrumb(breadcrumb, hints);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
import io.sentry.Integration;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.hints.Hints;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -107,10 +106,10 @@ public void onSensorChanged(final @NotNull SensorEvent event) {
breadcrumb.setLevel(SentryLevel.INFO);
breadcrumb.setData("degree", event.values[0]); // Celsius

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(ANDROID_SENSOR_EVENT, event);
final Hints hints = new Hints();
hints.set(ANDROID_SENSOR_EVENT, event);

hub.addBreadcrumb(breadcrumb, hintMap);
hub.addBreadcrumb(breadcrumb, hints);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import io.sentry.IHub;
import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.hints.Hints;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -172,14 +172,14 @@ private void addBreadcrumb(
className = target.getClass().getSimpleName();
}

final Map<String, Object> hintMap = new HashMap<>();
hintMap.put(ANDROID_MOTION_EVENT, motionEvent);
hintMap.put(ANDROID_VIEW, target);
final Hints hints = new Hints();
hints.set(ANDROID_MOTION_EVENT, motionEvent);
hints.set(ANDROID_VIEW, target);

hub.addBreadcrumb(
Breadcrumb.userInteraction(
eventType, ViewUtils.getResourceId(target), className, additionalData),
hintMap);
hints);
}

private @Nullable View ensureWindowDecorView(final @NotNull String caller) {
Expand Down
Loading