Skip to content

Commit 8daa4ed

Browse files
authored
Merge 2d26033 into 98da9ff
2 parents 98da9ff + 2d26033 commit 8daa4ed

File tree

9 files changed

+270
-21
lines changed

9 files changed

+270
-21
lines changed

sentry/src/main/java/io/sentry/Hub.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ public void removeExtra(final @NotNull String key) {
539539
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
540540
}
541541

542+
@Override
543+
public @NotNull ISentryLifecycleToken pushIsolationScope() {
544+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
545+
}
546+
542547
@Override
543548
public @NotNull SentryOptions getOptions() {
544549
return this.stack.peek().getOptions();
@@ -652,6 +657,31 @@ public void flush(long timeoutMillis) {
652657
return new Hub(this.options, new Stack(this.stack));
653658
}
654659

660+
@Override
661+
public @NotNull IScopes forkedScopes(@NotNull String creator) {
662+
return Sentry.forkedScopes(creator);
663+
}
664+
665+
@Override
666+
public @NotNull IScopes forkedCurrentScope(@NotNull String creator) {
667+
return Sentry.forkedCurrentScope(creator);
668+
}
669+
670+
@Override
671+
public @NotNull ISentryLifecycleToken makeCurrent() {
672+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
673+
}
674+
675+
@Override
676+
public @NotNull IScope getScope() {
677+
return Sentry.getCurrentScopes().getScope();
678+
}
679+
680+
@Override
681+
public @NotNull IScope getIsolationScope() {
682+
return Sentry.getCurrentScopes().getIsolationScope();
683+
}
684+
655685
@ApiStatus.Internal
656686
@Override
657687
public @NotNull SentryId captureTransaction(

sentry/src/main/java/io/sentry/HubAdapter.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public void removeExtra(@NotNull String key) {
158158
return Sentry.pushScope();
159159
}
160160

161+
@Override
162+
public @NotNull ISentryLifecycleToken pushIsolationScope() {
163+
return Sentry.pushIsolationScope();
164+
}
165+
161166
@Override
162167
public void popScope() {
163168
Sentry.popScope();
@@ -193,6 +198,32 @@ public void flush(long timeoutMillis) {
193198
return Sentry.getCurrentScopes().clone();
194199
}
195200

201+
@Override
202+
public @NotNull IScopes forkedScopes(@NotNull String creator) {
203+
return Sentry.forkedScopes(creator);
204+
}
205+
206+
@Override
207+
public @NotNull IScopes forkedCurrentScope(@NotNull String creator) {
208+
return Sentry.forkedCurrentScope(creator);
209+
}
210+
211+
@Override
212+
public @NotNull ISentryLifecycleToken makeCurrent() {
213+
// TODO this wouldn't do anything since it replaced the current with the same Scopes
214+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
215+
}
216+
217+
@Override
218+
public @NotNull IScope getScope() {
219+
return Sentry.getCurrentScopes().getScope();
220+
}
221+
222+
@Override
223+
public @NotNull IScope getIsolationScope() {
224+
return Sentry.getCurrentScopes().getIsolationScope();
225+
}
226+
196227
@Override
197228
public @NotNull SentryId captureTransaction(
198229
@NotNull SentryTransaction transaction,

sentry/src/main/java/io/sentry/HubScopesWrapper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public void removeExtra(@NotNull String key) {
153153
return scopes.pushScope();
154154
}
155155

156+
@Override
157+
public @NotNull ISentryLifecycleToken pushIsolationScope() {
158+
return scopes.pushIsolationScope();
159+
}
160+
156161
@Override
157162
public void popScope() {
158163
scopes.popScope();
@@ -188,6 +193,31 @@ public void flush(long timeoutMillis) {
188193
return scopes.clone();
189194
}
190195

196+
@Override
197+
public @NotNull IScopes forkedScopes(@NotNull String creator) {
198+
return scopes.forkedScopes(creator);
199+
}
200+
201+
@Override
202+
public @NotNull IScopes forkedCurrentScope(@NotNull String creator) {
203+
return scopes.forkedCurrentScope(creator);
204+
}
205+
206+
@Override
207+
public @NotNull ISentryLifecycleToken makeCurrent() {
208+
return scopes.makeCurrent();
209+
}
210+
211+
@Override
212+
public @NotNull IScope getScope() {
213+
return scopes.getScope();
214+
}
215+
216+
@Override
217+
public @NotNull IScope getIsolationScope() {
218+
return scopes.getIsolationScope();
219+
}
220+
191221
@ApiStatus.Internal
192222
@Override
193223
public @NotNull SentryId captureTransaction(

sentry/src/main/java/io/sentry/IScopes.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) {
309309
@NotNull
310310
ISentryLifecycleToken pushScope();
311311

312+
@NotNull
313+
ISentryLifecycleToken pushIsolationScope();
314+
312315
/** Removes the first scope */
313316
void popScope();
314317

@@ -354,12 +357,54 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) {
354357
/**
355358
* Clones the Hub
356359
*
360+
* @deprecated please use {@link IScopes#forkedScopes(String)} or {@link
361+
* IScopes#forkedCurrentScope(String)} instead.
357362
* @return the cloned Hub
358363
*/
359364
@NotNull
360365
@Deprecated
361366
IHub clone();
362367

368+
/**
369+
* Creates a fork of both current and isolation scope.
370+
*
371+
* @param creator debug information to see why scopes where forked
372+
* @return forked Scopes
373+
*/
374+
@NotNull
375+
IScopes forkedScopes(final @NotNull String creator);
376+
377+
/**
378+
* Creates a fork of current scope without forking isolation scope.
379+
*
380+
* @param creator debug information to see why scopes where forked
381+
* @return forked Scopes
382+
*/
383+
@NotNull
384+
IScopes forkedCurrentScope(final @NotNull String creator);
385+
386+
/**
387+
* Stores this Scopes in store, making it the current one that is used by static API.
388+
*
389+
* @return a token you should call .close() on when you're done.
390+
*/
391+
@NotNull
392+
ISentryLifecycleToken makeCurrent();
393+
394+
/**
395+
* Returns the current scope of this Scopes.
396+
*
397+
* @return scope
398+
*/
399+
public @NotNull IScope getScope();
400+
401+
/**
402+
* Returns the isolation scope of this Scopes.
403+
*
404+
* @return isolation scope
405+
*/
406+
public @NotNull IScope getIsolationScope();
407+
363408
/**
364409
* Captures the transaction and enqueues it for sending to Sentry server.
365410
*

sentry/src/main/java/io/sentry/NoOpHub.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public void removeExtra(@NotNull String key) {}
128128
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
129129
}
130130

131+
@Override
132+
public @NotNull ISentryLifecycleToken pushIsolationScope() {
133+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
134+
}
135+
131136
@Override
132137
public void popScope() {}
133138

@@ -155,6 +160,31 @@ public void flush(long timeoutMillis) {}
155160
return instance;
156161
}
157162

163+
@Override
164+
public @NotNull IScopes forkedScopes(@NotNull String creator) {
165+
return NoOpScopes.getInstance();
166+
}
167+
168+
@Override
169+
public @NotNull IScopes forkedCurrentScope(@NotNull String creator) {
170+
return NoOpScopes.getInstance();
171+
}
172+
173+
@Override
174+
public @NotNull ISentryLifecycleToken makeCurrent() {
175+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
176+
}
177+
178+
@Override
179+
public @NotNull IScope getScope() {
180+
return NoOpScope.getInstance();
181+
}
182+
183+
@Override
184+
public @NotNull IScope getIsolationScope() {
185+
return NoOpScope.getInstance();
186+
}
187+
158188
@Override
159189
public @NotNull SentryId captureTransaction(
160190
final @NotNull SentryTransaction transaction,

sentry/src/main/java/io/sentry/NoOpScopes.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public void removeExtra(@NotNull String key) {}
126126
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
127127
}
128128

129+
@Override
130+
public @NotNull ISentryLifecycleToken pushIsolationScope() {
131+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
132+
}
133+
129134
@Override
130135
public void popScope() {}
131136

@@ -154,6 +159,31 @@ public void flush(long timeoutMillis) {}
154159
return NoOpHub.getInstance();
155160
}
156161

162+
@Override
163+
public @NotNull IScopes forkedScopes(@NotNull String creator) {
164+
return NoOpScopes.getInstance();
165+
}
166+
167+
@Override
168+
public @NotNull IScopes forkedCurrentScope(@NotNull String creator) {
169+
return NoOpScopes.getInstance();
170+
}
171+
172+
@Override
173+
public @NotNull ISentryLifecycleToken makeCurrent() {
174+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
175+
}
176+
177+
@Override
178+
public @NotNull IScope getScope() {
179+
return NoOpScope.getInstance();
180+
}
181+
182+
@Override
183+
public @NotNull IScope getIsolationScope() {
184+
return NoOpScope.getInstance();
185+
}
186+
157187
@Override
158188
public @NotNull SentryId captureTransaction(
159189
final @NotNull SentryTransaction transaction,

sentry/src/main/java/io/sentry/Scopes.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ private Scopes(
7272
return creator;
7373
}
7474

75-
// TODO add to IScopes interface
75+
@Override
7676
public @NotNull IScope getScope() {
7777
return scope;
7878
}
7979

80-
// TODO add to IScopes interface
80+
@Override
8181
public @NotNull IScope getIsolationScope() {
8282
return isolationScope;
8383
}
@@ -105,25 +105,16 @@ public boolean isAncestorOf(final @Nullable Scopes otherScopes) {
105105
return false;
106106
}
107107

108-
// TODO add to IScopes interface
109-
public @NotNull Scopes forkedScopes(final @NotNull String creator) {
108+
@Override
109+
public @NotNull IScopes forkedScopes(final @NotNull String creator) {
110110
return new Scopes(scope.clone(), isolationScope.clone(), this, options, creator);
111111
}
112112

113-
// TODO add to IScopes interface
114-
public @NotNull Scopes forkedCurrentScope(final @NotNull String creator) {
115-
IScope clone = scope.clone();
116-
// TODO should use isolation scope
117-
// return new Scopes(clone, isolationScope, this, options, creator);
118-
return new Scopes(clone, clone, this, options, creator);
113+
@Override
114+
public @NotNull IScopes forkedCurrentScope(final @NotNull String creator) {
115+
return new Scopes(scope.clone(), isolationScope, this, options, creator);
119116
}
120117

121-
// // TODO in Sentry.init?
122-
// public static Scopes forkedRoots(final @NotNull SentryOptions options, final @NotNull String
123-
// creator) {
124-
// return new Scopes(ROOT_SCOPE.clone(), ROOT_ISOLATION_SCOPE.clone(), options, creator);
125-
// }
126-
127118
// TODO always read from root scope?
128119
@Override
129120
public boolean isEnabled() {
@@ -602,12 +593,28 @@ public ISentryLifecycleToken pushScope() {
602593
.log(SentryLevel.WARNING, "Instance is disabled and this 'pushScope' call is a no-op.");
603594
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
604595
} else {
605-
Scopes scopes = this.forkedCurrentScope("pushScope");
596+
final @NotNull IScopes scopes = this.forkedCurrentScope("pushScope");
606597
return scopes.makeCurrent();
607598
}
608599
}
609600

610-
public ISentryLifecycleToken makeCurrent() {
601+
@Override
602+
public ISentryLifecycleToken pushIsolationScope() {
603+
if (!isEnabled()) {
604+
options
605+
.getLogger()
606+
.log(
607+
SentryLevel.WARNING,
608+
"Instance is disabled and this 'pushIsolationScope' call is a no-op.");
609+
return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance();
610+
} else {
611+
final @NotNull IScopes scopes = this.forkedScopes("pushIsolationScope");
612+
return scopes.makeCurrent();
613+
}
614+
}
615+
616+
@Override
617+
public @NotNull ISentryLifecycleToken makeCurrent() {
611618
return Sentry.setCurrentScopes(this);
612619
}
613620

@@ -638,7 +645,7 @@ public void withScope(final @NotNull ScopeCallback callback) {
638645
}
639646

640647
} else {
641-
Scopes forkedScopes = forkedCurrentScope("withScope");
648+
final @NotNull IScopes forkedScopes = forkedCurrentScope("withScope");
642649
// TODO should forkedScopes be made current inside callback?
643650
// TODO forkedScopes.makeCurrent()?
644651
try {

0 commit comments

Comments
 (0)