Skip to content

Commit a373f02

Browse files
authored
Merge 5a3f296 into f1fdb9f
2 parents f1fdb9f + 5a3f296 commit a373f02

File tree

355 files changed

+10819
-4788
lines changed

Some content is hidden

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

355 files changed

+10819
-4788
lines changed

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
# Changelog
22

3+
## 8.0.0-alpha.1
4+
5+
Version 8 of the Sentry Android/Java SDK brings a variety of features and fixes. The most notable changes are:
6+
7+
- New `Scope` types have been introduced, see "Behavioural Changes" for more details.
8+
- Lifecycle tokens have been introduced to manage `Scope` lifecycle, see "Behavioural Changes" for more details.
9+
- `Hub` has been replaced by `Scopes`
10+
11+
### Behavioural Changes
12+
13+
- We're introducing some new `Scope` types in the SDK, allowing for better control over what data is attached where. Previously there was a stack of scopes that was pushed and popped. Instead we now fork scopes for a given lifecycle and then restore the previous scopes. Since `Hub` is gone, it is also never cloned anymore. Separation of data now happens through the different scope types while making it easier to manipulate exactly what you need without having to attach data at the right time to have it apply where wanted.
14+
- Global scope is attached to all events created by the SDK. It can also be modified before `Sentry.init` has been called. It can be manipulated using `Sentry.configureScope(ScopeType.GLOBAL, (scope) -> { ... })`.
15+
- Isolation scope can be used e.g. to attach data to all events that come up while handling an incoming request. It can also be used for other isolation purposes. It can be manipulated using `Sentry.configureScope(ScopeType.ISOLATION, (scope) -> { ... })`. The SDK automatically forks isolation scope in certain cases like incoming requests, CRON jobs, Spring `@Async` and more.
16+
- Current scope is forked often and data added to it is only added to events that are created while this scope is active. Data is also passed on to newly forked child scopes but not to parents.
17+
- `Sentry.popScope` has been deprecated, please call `.close()` on the token returned by `Sentry.pushScope` instead or use it in a way described in more detail in "Migration Guide".
18+
- We have chosen a default scope that is used for `Sentry.configureScope()` as well as API like `Sentry.setTag()`
19+
- For Android the type defaults to `CURRENT` scope
20+
- For Backend and other JVM applicatons it defaults to `ISOLATION` scope
21+
- Event processors on `Scope` can now be ordered by overriding the `getOrder` method on implementations of `EventProcessor`. NOTE: This order only applies to event processors on `Scope` but not `SentryOptions` at the moment. Feel free to request this if you need it.
22+
- `Hub` is deprecated in favor of `Scopes`, alongside some `Hub` relevant APIs. More details can be found in the "Migration Guide" section.
23+
24+
### Breaking Changes
25+
26+
- `Contexts` no longer extends `ConcurrentHashMap`, instead we offer a selected set of methods.
27+
28+
### Migration Guide / Deprecations
29+
30+
- `Hub` has been deprecated, we're replacing the following:
31+
- `IHub` has been replaced by `IScopes`, however you should be able to simply pass `IHub` instances to code expecting `IScopes`, allowing for an easier migration.
32+
- `HubAdapter.getInstance()` has been replaced by `ScopesAdapter.getInstance()`
33+
- The `.clone()` method on `IHub`/`IScopes` has been deprecated, please use `.pushScope()` or `.pushIsolationScope()` instead
34+
- Some internal methods like `.getCurrentHub()` and `.setCurrentHub()` have also been replaced.
35+
- `Sentry.popScope` has been replaced by calling `.close()` on the token returned by `Sentry.pushScope()` and `Sentry.pushIsolationScope()`. The token can also be used in a `try` block like this:
36+
37+
```
38+
try (final @NotNull ISentryLifecycleToken ignored = Sentry.pushScope()) {
39+
// this block has its separate current scope
40+
}
41+
```
42+
43+
as well as:
44+
45+
46+
```
47+
try (final @NotNull ISentryLifecycleToken ignored = Sentry.pushIsolationScope()) {
48+
// this block has its separate isolation scope
49+
}
50+
```
51+
52+
You may also use `LifecycleHelper.close(token)`, e.g. in case you need to pass the token around for closing later.
53+
54+
### Features
55+
56+
- Report exceptions returned by Throwable.getSuppressed() to Sentry as exception groups ([#3396] https://github.com/getsentry/sentry-java/pull/3396)
57+
358
## 7.9.0
459

560
### Features

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ allprojects {
9999
dependsOn("cleanTest")
100100
}
101101
withType<JavaCompile> {
102-
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile", "-Xlint:-processing"))
102+
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile", "-Xlint:-processing", "-Xlint:-try"))
103103
}
104104
}
105105
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android.useAndroidX=true
1010
android.defaults.buildfeatures.buildconfig=true
1111

1212
# Release information
13-
versionName=7.9.0
13+
versionName=8.0.0-alpha.1
1414

1515
# Override the SDK name on native crashes on Android
1616
sentryAndroidSdkName=sentry.native.android

sentry-android-core/api/sentry-android-core.api

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public final class io/sentry/android/core/ActivityBreadcrumbsIntegration : andro
88
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
99
public fun onActivityStarted (Landroid/app/Activity;)V
1010
public fun onActivityStopped (Landroid/app/Activity;)V
11-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
11+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
1212
}
1313

1414
public final class io/sentry/android/core/ActivityFramesTracker {
@@ -33,7 +33,7 @@ public final class io/sentry/android/core/ActivityLifecycleIntegration : android
3333
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
3434
public fun onActivityStarted (Landroid/app/Activity;)V
3535
public fun onActivityStopped (Landroid/app/Activity;)V
36-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
36+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
3737
}
3838

3939
public final class io/sentry/android/core/AndroidCpuCollector : io/sentry/IPerformanceSnapshotCollector {
@@ -87,7 +87,7 @@ public class io/sentry/android/core/AndroidProfiler$ProfileStartData {
8787
public final class io/sentry/android/core/AnrIntegration : io/sentry/Integration, java/io/Closeable {
8888
public fun <init> (Landroid/content/Context;)V
8989
public fun close ()V
90-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
90+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
9191
}
9292

9393
public final class io/sentry/android/core/AnrIntegrationFactory {
@@ -97,14 +97,15 @@ public final class io/sentry/android/core/AnrIntegrationFactory {
9797

9898
public final class io/sentry/android/core/AnrV2EventProcessor : io/sentry/BackfillingEventProcessor {
9999
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
100+
public fun getOrder ()Ljava/lang/Long;
100101
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
101102
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
102103
}
103104

104105
public class io/sentry/android/core/AnrV2Integration : io/sentry/Integration, java/io/Closeable {
105106
public fun <init> (Landroid/content/Context;)V
106107
public fun close ()V
107-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
108+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
108109
}
109110

110111
public final class io/sentry/android/core/AnrV2Integration$AnrV2Hint : io/sentry/hints/BlockingFlushHint, io/sentry/hints/AbnormalExit, io/sentry/hints/Backfillable {
@@ -123,13 +124,13 @@ public final class io/sentry/android/core/AppComponentsBreadcrumbsIntegration :
123124
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
124125
public fun onLowMemory ()V
125126
public fun onTrimMemory (I)V
126-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
127+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
127128
}
128129

129130
public final class io/sentry/android/core/AppLifecycleIntegration : io/sentry/Integration, java/io/Closeable {
130131
public fun <init> ()V
131132
public fun close ()V
132-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
133+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
133134
}
134135

135136
public final class io/sentry/android/core/AppState {
@@ -177,7 +178,7 @@ public final class io/sentry/android/core/CurrentActivityIntegration : android/a
177178
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
178179
public fun onActivityStarted (Landroid/app/Activity;)V
179180
public fun onActivityStopped (Landroid/app/Activity;)V
180-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
181+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
181182
}
182183

183184
public final class io/sentry/android/core/DeviceInfoUtil {
@@ -193,7 +194,7 @@ public abstract class io/sentry/android/core/EnvelopeFileObserverIntegration : i
193194
public fun <init> ()V
194195
public fun close ()V
195196
public static fun getOutboxFileObserver ()Lio/sentry/android/core/EnvelopeFileObserverIntegration;
196-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
197+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
197198
}
198199

199200
public abstract interface class io/sentry/android/core/IDebugImagesLoader {
@@ -219,23 +220,24 @@ public final class io/sentry/android/core/NdkIntegration : io/sentry/Integration
219220
public static final field SENTRY_NDK_CLASS_NAME Ljava/lang/String;
220221
public fun <init> (Ljava/lang/Class;)V
221222
public fun close ()V
222-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
223+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
223224
}
224225

225226
public final class io/sentry/android/core/NetworkBreadcrumbsIntegration : io/sentry/Integration, java/io/Closeable {
226227
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/BuildInfoProvider;Lio/sentry/ILogger;)V
227228
public fun close ()V
228-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
229+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
229230
}
230231

231232
public final class io/sentry/android/core/PhoneStateBreadcrumbsIntegration : io/sentry/Integration, java/io/Closeable {
232233
public fun <init> (Landroid/content/Context;)V
233234
public fun close ()V
234-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
235+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
235236
}
236237

237238
public final class io/sentry/android/core/ScreenshotEventProcessor : io/sentry/EventProcessor {
238239
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
240+
public fun getOrder ()Ljava/lang/Long;
239241
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
240242
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
241243
}
@@ -360,15 +362,15 @@ public final class io/sentry/android/core/SystemEventsBreadcrumbsIntegration : i
360362
public fun <init> (Landroid/content/Context;)V
361363
public fun <init> (Landroid/content/Context;Ljava/util/List;)V
362364
public fun close ()V
363-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
365+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
364366
}
365367

366368
public final class io/sentry/android/core/TempSensorBreadcrumbsIntegration : android/hardware/SensorEventListener, io/sentry/Integration, java/io/Closeable {
367369
public fun <init> (Landroid/content/Context;)V
368370
public fun close ()V
369371
public fun onAccuracyChanged (Landroid/hardware/Sensor;I)V
370372
public fun onSensorChanged (Landroid/hardware/SensorEvent;)V
371-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
373+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
372374
}
373375

374376
public final class io/sentry/android/core/UserInteractionIntegration : android/app/Application$ActivityLifecycleCallbacks, io/sentry/Integration, java/io/Closeable {
@@ -381,11 +383,12 @@ public final class io/sentry/android/core/UserInteractionIntegration : android/a
381383
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
382384
public fun onActivityStarted (Landroid/app/Activity;)V
383385
public fun onActivityStopped (Landroid/app/Activity;)V
384-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
386+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
385387
}
386388

387389
public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentry/EventProcessor {
388390
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;)V
391+
public fun getOrder ()Ljava/lang/Long;
389392
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
390393
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
391394
public static fun snapshotViewHierarchy (Landroid/app/Activity;Lio/sentry/ILogger;)Lio/sentry/protocol/ViewHierarchy;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.os.Bundle;
99
import io.sentry.Breadcrumb;
1010
import io.sentry.Hint;
11-
import io.sentry.IHub;
11+
import io.sentry.IScopes;
1212
import io.sentry.Integration;
1313
import io.sentry.SentryLevel;
1414
import io.sentry.SentryOptions;
@@ -23,21 +23,21 @@ public final class ActivityBreadcrumbsIntegration
2323
implements Integration, Closeable, Application.ActivityLifecycleCallbacks {
2424

2525
private final @NotNull Application application;
26-
private @Nullable IHub hub;
26+
private @Nullable IScopes scopes;
2727
private boolean enabled;
2828

2929
public ActivityBreadcrumbsIntegration(final @NotNull Application application) {
3030
this.application = Objects.requireNonNull(application, "Application is required");
3131
}
3232

3333
@Override
34-
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
34+
public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
3535
final SentryAndroidOptions androidOptions =
3636
Objects.requireNonNull(
3737
(options instanceof SentryAndroidOptions) ? (SentryAndroidOptions) options : null,
3838
"SentryAndroidOptions is required");
3939

40-
this.hub = Objects.requireNonNull(hub, "Hub is required");
40+
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
4141
this.enabled = androidOptions.isEnableActivityLifecycleBreadcrumbs();
4242
options
4343
.getLogger()
@@ -54,8 +54,9 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
5454
public void close() throws IOException {
5555
if (enabled) {
5656
application.unregisterActivityLifecycleCallbacks(this);
57-
if (hub != null) {
58-
hub.getOptions()
57+
if (scopes != null) {
58+
scopes
59+
.getOptions()
5960
.getLogger()
6061
.log(SentryLevel.DEBUG, "ActivityBreadcrumbsIntegration removed.");
6162
}
@@ -100,7 +101,7 @@ public synchronized void onActivityDestroyed(final @NotNull Activity activity) {
100101
}
101102

102103
private void addBreadcrumb(final @NotNull Activity activity, final @NotNull String state) {
103-
if (hub == null) {
104+
if (scopes == null) {
104105
return;
105106
}
106107

@@ -114,7 +115,7 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri
114115
final Hint hint = new Hint();
115116
hint.set(ANDROID_ACTIVITY, activity);
116117

117-
hub.addBreadcrumb(breadcrumb, hint);
118+
scopes.addBreadcrumb(breadcrumb, hint);
118119
}
119120

120121
private @NotNull String getActivityName(final @NotNull Activity activity) {

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import android.view.View;
1313
import androidx.annotation.NonNull;
1414
import io.sentry.FullyDisplayedReporter;
15-
import io.sentry.IHub;
1615
import io.sentry.IScope;
16+
import io.sentry.IScopes;
1717
import io.sentry.ISpan;
1818
import io.sentry.ITransaction;
1919
import io.sentry.Instrumenter;
@@ -60,7 +60,7 @@ public final class ActivityLifecycleIntegration
6060

6161
private final @NotNull Application application;
6262
private final @NotNull BuildInfoProvider buildInfoProvider;
63-
private @Nullable IHub hub;
63+
private @Nullable IScopes scopes;
6464
private @Nullable SentryAndroidOptions options;
6565

6666
private boolean performanceEnabled = false;
@@ -102,13 +102,13 @@ public ActivityLifecycleIntegration(
102102
}
103103

104104
@Override
105-
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
105+
public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
106106
this.options =
107107
Objects.requireNonNull(
108108
(options instanceof SentryAndroidOptions) ? (SentryAndroidOptions) options : null,
109109
"SentryAndroidOptions is required");
110110

111-
this.hub = Objects.requireNonNull(hub, "Hub is required");
111+
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
112112

113113
performanceEnabled = isPerformanceEnabled(this.options);
114114
fullyDisplayedReporter = this.options.getFullyDisplayedReporter();
@@ -150,10 +150,10 @@ private void stopPreviousTransactions() {
150150

151151
private void startTracing(final @NotNull Activity activity) {
152152
WeakReference<Activity> weakActivity = new WeakReference<>(activity);
153-
if (hub != null && !isRunningTransactionOrTrace(activity)) {
153+
if (scopes != null && !isRunningTransactionOrTrace(activity)) {
154154
if (!performanceEnabled) {
155155
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
156-
TracingUtils.startNewTrace(hub);
156+
TracingUtils.startNewTrace(scopes);
157157
} else {
158158
// as we allow a single transaction running on the bound Scope, we finish the previous ones
159159
stopPreviousTransactions();
@@ -225,7 +225,7 @@ private void startTracing(final @NotNull Activity activity) {
225225

226226
// we can only bind to the scope if there's no running transaction
227227
ITransaction transaction =
228-
hub.startTransaction(
228+
scopes.startTransaction(
229229
new TransactionContext(
230230
activityName,
231231
TransactionNameSource.COMPONENT,
@@ -278,7 +278,7 @@ private void startTracing(final @NotNull Activity activity) {
278278
}
279279

280280
// lets bind to the scope so other integrations can pick it up
281-
hub.configureScope(
281+
scopes.configureScope(
282282
scope -> {
283283
applyScope(scope, transaction);
284284
});
@@ -356,10 +356,10 @@ private void finishTransaction(
356356
status = SpanStatus.OK;
357357
}
358358
transaction.finish(status);
359-
if (hub != null) {
359+
if (scopes != null) {
360360
// make sure to remove the transaction from scope, as it may contain running children,
361361
// therefore `finish` method will not remove it from scope
362-
hub.configureScope(
362+
scopes.configureScope(
363363
scope -> {
364364
clearScope(scope, transaction);
365365
});
@@ -371,9 +371,9 @@ private void finishTransaction(
371371
public synchronized void onActivityCreated(
372372
final @NotNull Activity activity, final @Nullable Bundle savedInstanceState) {
373373
setColdStart(savedInstanceState);
374-
if (hub != null) {
374+
if (scopes != null) {
375375
final @Nullable String activityClassName = ClassUtil.getClassName(activity);
376-
hub.configureScope(scope -> scope.setScreen(activityClassName));
376+
scopes.configureScope(scope -> scope.setScreen(activityClassName));
377377
}
378378
startTracing(activity);
379379
final @Nullable ISpan ttfdSpan = ttfdSpanMap.get(activity);
@@ -429,10 +429,10 @@ public void onActivityPrePaused(@NonNull Activity activity) {
429429
// well
430430
// this ensures any newly launched activity will not use the app start timestamp as txn start
431431
firstActivityCreated = true;
432-
if (hub == null) {
432+
if (scopes == null) {
433433
lastPausedTime = AndroidDateUtils.getCurrentSentryDateTime();
434434
} else {
435-
lastPausedTime = hub.getOptions().getDateProvider().now();
435+
lastPausedTime = scopes.getOptions().getDateProvider().now();
436436
}
437437
}
438438
}
@@ -445,10 +445,10 @@ public synchronized void onActivityPaused(final @NotNull Activity activity) {
445445
// well
446446
// this ensures any newly launched activity will not use the app start timestamp as txn start
447447
firstActivityCreated = true;
448-
if (hub == null) {
448+
if (scopes == null) {
449449
lastPausedTime = AndroidDateUtils.getCurrentSentryDateTime();
450450
} else {
451-
lastPausedTime = hub.getOptions().getDateProvider().now();
451+
lastPausedTime = scopes.getOptions().getDateProvider().now();
452452
}
453453
}
454454
}

0 commit comments

Comments
 (0)