36
36
import java .util .concurrent .ConcurrentMap ;
37
37
import java .util .concurrent .CopyOnWriteArrayList ;
38
38
import java .util .concurrent .TimeUnit ;
39
+
40
+ import de .thetaphi .forbiddenapis .SuppressForbidden ;
39
41
import org .slf4j .Logger ;
40
42
import org .slf4j .LoggerFactory ;
41
43
@@ -122,6 +124,7 @@ private AgentScope.Continuation captureSpan(Context context, byte source, AgentS
122
124
return new ScopeContinuation (this , context , source , traceCollector ).register ();
123
125
}
124
126
127
+ @ SuppressForbidden
125
128
private AgentScope activate (
126
129
final AgentSpan span ,
127
130
final byte source ,
@@ -155,12 +158,20 @@ private AgentScope activate(
155
158
156
159
final ContinuableScope scope =
157
160
new ContinuableScope (this , context , source , asyncPropagation , createScopeState (context ));
161
+ System .out .println ("Scope size prior: " + scopeStack .depth ());
158
162
scopeStack .push (scope );
163
+ System .out .println ("Scope size prior: " + scopeStack .depth ());
159
164
healthMetrics .onActivateScope ();
160
165
166
+ if (iterationKeepAlive > 0 && currentDepth == 0 ) {
167
+ // For context-based scopes, only add them if they're going to be long-lived
168
+ scheduleRootIterationScopeCleanup (scopeStack , scope );
169
+ }
170
+
161
171
return scope ;
162
172
}
163
173
174
+ @ SuppressForbidden
164
175
private AgentScope activate (final Context context ) {
165
176
ScopeStack scopeStack = scopeStack ();
166
177
@@ -185,9 +196,17 @@ private AgentScope activate(final Context context) {
185
196
186
197
final ContinuableScope scope =
187
198
new ContinuableScope (this , context , CONTEXT , asyncPropagation , createScopeState (context ));
199
+ System .out .println ("Context: " + context );
200
+ System .out .println ("Scope size prior: " + scopeStack .depth ());
188
201
scopeStack .push (scope );
202
+ System .out .println ("Scope size prior: " + scopeStack .depth ());
189
203
healthMetrics .onActivateScope ();
190
204
205
+ if (iterationKeepAlive > 0 && currentDepth == 0 ) {
206
+ // For context-based scopes, only add them if they're going to be long-lived
207
+ scheduleRootIterationScopeCleanup (scopeStack , scope );
208
+ }
209
+
191
210
return scope ;
192
211
}
193
212
@@ -304,8 +323,13 @@ public void rollbackActiveToCheckpoint() {
304
323
}
305
324
}
306
325
326
+ @ SuppressForbidden
307
327
public AgentSpan activeSpan () {
308
328
final ContinuableScope active = scopeStack ().active ();
329
+
330
+ System .out .println ("Scope size prior: " + scopeStack ().depth ());
331
+ System .out .println ("scopeStack(): " + scopeStack ());
332
+ System .out .println ("active: " + active );
309
333
return active == null ? null : active .span ();
310
334
}
311
335
0 commit comments