@@ -52,7 +52,10 @@ public final class SentryTracer implements ITransaction {
5252 private @ NotNull TransactionNameSource transactionNameSource ;
5353 private final @ NotNull Contexts contexts = new Contexts ();
5454 private final @ Nullable CompositePerformanceCollector compositePerformanceCollector ;
55- private final @ NotNull TransactionOptions transactionOptions ;
55+ private final boolean waitForChildren ;
56+ private final @ Nullable Long idleTimeout ;
57+ private final @ Nullable Long deadlineTimeout ;
58+ private final @ Nullable TransactionFinishedCallback transactionFinishedCallback ;
5659
5760 public SentryTracer (final @ NotNull TransactionContext context , final @ NotNull IScopes scopes ) {
5861 this (context , scopes , new TransactionOptions (), null );
@@ -81,7 +84,10 @@ public SentryTracer(
8184 this .compositePerformanceCollector =
8285 Boolean .TRUE .equals (isSampled ()) ? compositePerformanceCollector : null ;
8386 this .transactionNameSource = context .getTransactionNameSource ();
84- this .transactionOptions = transactionOptions ;
87+ this .waitForChildren = transactionOptions .isWaitForChildren ();
88+ this .idleTimeout = transactionOptions .getIdleTimeout ();
89+ this .deadlineTimeout = transactionOptions .getDeadlineTimeout ();
90+ this .transactionFinishedCallback = transactionOptions .getTransactionFinishedCallback ();
8591
8692 setDefaultSpanData (root );
8793
@@ -97,8 +103,7 @@ public SentryTracer(
97103 this .compositePerformanceCollector .start (this );
98104 }
99105
100- if (transactionOptions .getIdleTimeout () != null
101- || transactionOptions .getDeadlineTimeout () != null ) {
106+ if (idleTimeout != null || deadlineTimeout != null ) {
102107 timersEnabled = true ;
103108
104109 scheduleDeadlineTimeout ();
@@ -110,8 +115,6 @@ public SentryTracer(
110115 public void scheduleFinish () {
111116 try (final @ NotNull ISentryLifecycleToken ignored = timerLock .acquire ()) {
112117 if (timersEnabled ) {
113- final @ Nullable Long idleTimeout = transactionOptions .getIdleTimeout ();
114-
115118 if (idleTimeout != null ) {
116119 cancelIdleTimer ();
117120 isIdleFinishTimerRunning .set (true );
@@ -145,9 +148,7 @@ private void onIdleTimeoutReached() {
145148 private void onDeadlineTimeoutReached () {
146149 final @ Nullable SpanStatus status = getStatus ();
147150 forceFinish (
148- (status != null ) ? status : SpanStatus .DEADLINE_EXCEEDED ,
149- transactionOptions .getIdleTimeout () != null ,
150- null );
151+ (status != null ) ? status : SpanStatus .DEADLINE_EXCEEDED , idleTimeout != null , null );
151152 isDeadlineTimerRunning .set (false );
152153 }
153154
@@ -195,14 +196,13 @@ public void finish(
195196
196197 // auto-finish any idle spans first
197198 for (final Span span : children ) {
198- if (span .getOptions (). isIdle ()) {
199+ if (span .isIdle ()) {
199200 span .finish ((status != null ) ? status : getSpanContext ().status , finishTimestamp );
200201 }
201202 }
202203
203204 this .finishStatus = FinishStatus .finishing (status );
204- if (!root .isFinished ()
205- && (!transactionOptions .isWaitForChildren () || hasAllChildrenFinished ())) {
205+ if (!root .isFinished () && (!waitForChildren || hasAllChildrenFinished ())) {
206206
207207 final @ NotNull AtomicReference <List <PerformanceCollectionData >> performanceCollectionData =
208208 new AtomicReference <>();
@@ -218,7 +218,7 @@ public void finish(
218218 // Let's call the finishCallback here, when the root span has a finished date but it's
219219 // not finished, yet
220220 final @ Nullable TransactionFinishedCallback finishedCallback =
221- transactionOptions . getTransactionFinishedCallback () ;
221+ transactionFinishedCallback ;
222222 if (finishedCallback != null ) {
223223 finishedCallback .execute (this );
224224 }
@@ -274,7 +274,7 @@ public void finish(
274274 }
275275 }
276276
277- if (dropIfNoChildren && children .isEmpty () && transactionOptions . getIdleTimeout () != null ) {
277+ if (dropIfNoChildren && children .isEmpty () && idleTimeout != null ) {
278278 // if it's an idle transaction which has no children, we drop it to save user's quota
279279 scopes
280280 .getOptions ()
@@ -302,7 +302,7 @@ private void cancelIdleTimer() {
302302 }
303303
304304 private void scheduleDeadlineTimeout () {
305- final @ Nullable Long deadlineTimeOut = transactionOptions . getDeadlineTimeout () ;
305+ final @ Nullable Long deadlineTimeOut = deadlineTimeout ;
306306 if (deadlineTimeOut != null ) {
307307 try (final @ NotNull ISentryLifecycleToken ignored = timerLock .acquire ()) {
308308 if (timersEnabled ) {
@@ -393,8 +393,9 @@ ISpan startChild(
393393 final @ Nullable String description ,
394394 final @ Nullable SentryDate timestamp ,
395395 final @ NotNull SpanOptions spanOptions ) {
396- spanOptions .setStartTimestamp (timestamp );
397- return createChild (parentSpanId , operation , description , spanOptions );
396+ final @ NotNull SpanOptions spanOptionsSnapshot = new SpanOptions (spanOptions );
397+ spanOptionsSnapshot .setStartTimestamp (timestamp );
398+ return createChild (parentSpanId , operation , description , spanOptionsSnapshot );
398399 }
399400
400401 /**
@@ -449,11 +450,11 @@ private ISpan createChild(
449450 compositePerformanceCollector .onSpanFinished (finishingSpan );
450451 }
451452 final FinishStatus finishStatus = this .finishStatus ;
452- if (transactionOptions . getIdleTimeout () != null ) {
453+ if (idleTimeout != null ) {
453454 // if it's an idle transaction, no matter the status, we'll reset the timeout here
454455 // so the transaction will either idle and finish itself, or a new child will be
455456 // added and we'll wait for it again
456- if (!transactionOptions . isWaitForChildren () || hasAllChildrenFinished ()) {
457+ if (!waitForChildren || hasAllChildrenFinished ()) {
457458 scheduleFinish ();
458459 }
459460 } else if (finishStatus .isFinishing ) {
@@ -475,13 +476,13 @@ private ISpan createChild(
475476 // compositePerformanceCollector.onSpanFinished(finishingSpan);
476477 // }
477478 // final FinishStatus finishStatus = this.finishStatus;
478- // if (transactionOptions.getIdleTimeout() != null) {
479+ // if (idleTimeout != null) {
479480 // // if it's an idle transaction, no matter the status, we'll reset the
480481 // timeout here
481482 // // so the transaction will either idle and finish itself, or a new child
482483 // will be
483484 // // added and we'll wait for it again
484- // if (!transactionOptions.isWaitForChildren() || hasAllChildrenFinished()) {
485+ // if (!waitForChildren || hasAllChildrenFinished()) {
485486 // scheduleFinish();
486487 // }
487488 // } else if (finishStatus.isFinishing) {
0 commit comments