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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- 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 Hint object and passed into beforeSend and EventProcessor as @NotNull Hint object ([#2045](https://github.com/getsentry/sentry-java/pull/2045))
- Attachments can be manipulated via hint ([#2046](https://github.com/getsentry/sentry-java/pull/2046))

## 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/Hint;)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.Hint;
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 Hint hint = new Hint();
hint.set(ANDROID_ACTIVITY, activity);

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

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.Hint;
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 Hint hint = new Hint();
hint.set(ANDROID_CONFIGURATION, newConfig);

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

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.Hint;
import io.sentry.protocol.App;
import io.sentry.protocol.Device;
import io.sentry.protocol.OperatingSystem;
Expand Down Expand Up @@ -116,8 +117,7 @@ public DefaultAndroidEventProcessor(
}

@Override
public @NotNull SentryEvent process(
final @NotNull SentryEvent event, final @Nullable Map<String, Object> hint) {
public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) {
final boolean applyScopeData = shouldApplyScopeData(event, hint);
if (applyScopeData) {
// we only set memory data if it's not a hard crash, when it's a hard crash the event is
Expand All @@ -143,7 +143,7 @@ private void setCommons(
}

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

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

if (applyScopeData) {
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.Hint;
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 @@ -58,12 +57,11 @@ public void onEvent(int eventType, @Nullable String relativePath) {

// TODO: Only some event types should be pass through?

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

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

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

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.Hint;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.SentrySpan;
Expand Down Expand Up @@ -42,7 +43,7 @@ final class PerformanceAndroidEventProcessor implements EventProcessor {
*/
@Override
@Nullable
public SentryEvent process(@NotNull SentryEvent event, @Nullable Map<String, Object> hint) {
public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
// 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 Hint hint) {

if (!options.isTracingEnabled()) {
return 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.TypeCheckHint.ANDROID_ACTIVITY;
import static io.sentry.TypeCheckHint.SENTRY_SCREENSHOT;

import android.annotation.SuppressLint;
import android.app.Activity;
Expand All @@ -17,13 +16,12 @@
import io.sentry.EventProcessor;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.hints.Hint;
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 +66,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 Hint hint) {
if (options.isAttachScreenshot() && event.isErrored() && currentActivity != null) {
final Activity activity = currentActivity.get();
if (isActivityValid(activity)
Expand All @@ -93,16 +90,10 @@ 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(
SENTRY_SCREENSHOT,
Attachment.fromScreenshot(byteArrayOutputStream.toByteArray()));
hint.put(ANDROID_ACTIVITY, activity);
hint.setScreenshot(Attachment.fromScreenshot(byteArrayOutputStream.toByteArray()));
hint.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.Hint;
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 Hint hint = new Hint();
hint.set(ANDROID_INTENT, intent);

hub.addBreadcrumb(breadcrumb, hintMap);
hub.addBreadcrumb(breadcrumb, hint);
}
}
}
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.Hint;
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 Hint hint = new Hint();
hint.set(ANDROID_SENSOR_EVENT, event);

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

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.Hint;
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 Hint hint = new Hint();
hint.set(ANDROID_MOTION_EVENT, motionEvent);
hint.set(ANDROID_VIEW, target);

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

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