@@ -143,6 +143,17 @@ private function helperForTestOneStackTrace(InferredSpansBuilder $builder): arra
143143 return $ stackTrace ;
144144 }
145145
146+ public function isSpanStackTraceEnabled (SpanDto $ span ): bool
147+ {
148+ $ dummyTx = $ this ->tracer ->beginTransaction ('dummy_temp_TX_name ' , 'dummy_temp_TX_type ' );
149+ $ result =
150+ $ dummyTx instanceof Transaction
151+ && $ dummyTx ->shouldCollectStackTraceForSpanDuration ($ span ->duration )
152+ && (StackTraceUtil::convertLimitConfigToMaxNumberOfFrames ($ dummyTx ->getStackTraceLimitConfig ()) !== 0 );
153+ $ dummyTx ->discard ();
154+ return $ result ;
155+ }
156+
146157 public function testOneStackTrace (): void
147158 {
148159 AssertMessageStack::newScope (/* out */ $ dbgCtx );
@@ -190,8 +201,12 @@ function (InferredSpansBuilder $builder) use (&$expectedStackTrace, $expectedTim
190201 TraceValidator::validate (new TraceActual ($ this ->mockEventSink ->idToTransaction (), $ this ->mockEventSink ->idToSpan ()));
191202
192203 $ expectedStackTraceConvertedToApm = StackTraceUtil::convertClassicToApmFormat ($ expectedStackTrace , /* maxNumberOfFrames */ null );
193- self ::assertNotNull ($ span ->stackTrace );
194- StackTraceExpectations::fromFrames ($ expectedStackTraceConvertedToApm )->assertMatches ($ span ->stackTrace );
204+ if ($ this ->isSpanStackTraceEnabled ($ span )) {
205+ self ::assertNotNull ($ span ->stackTrace );
206+ StackTraceExpectations::fromFrames ($ expectedStackTraceConvertedToApm )->assertMatches ($ span ->stackTrace );
207+ } else {
208+ self ::assertNull ($ span ->stackTrace );
209+ }
195210 }
196211
197212 private function charDiagramFuncNameToStackTraceFrame (string $ funcName ): ClassicFormatStackTraceFrame
@@ -1358,22 +1373,24 @@ function (InferredSpansBuilder $builder) use ($stackDepthVariants): void {
13581373 TestCaseBase::assertNull ($ span ->stackTrace );
13591374 continue ;
13601375 }
1361- TestCaseBase::assertNotNull ($ span ->stackTrace );
1362-
1363- if ($ expectedMaxNumberOfFrames !== null ) {
1364- TestCaseBase::assertLessThanOrEqual ($ expectedMaxNumberOfFrames , count ($ span ->stackTrace ));
1365- }
1366-
1367- $ dbgCtx ->pushSubScope ();
1368- foreach (RangeUtil::generateUpTo (count ($ span ->stackTrace )) as $ stackFrameIndex ) {
1369- $ dbgCtx ->add (['stackFrameIndex ' => $ stackFrameIndex ]);
1370- $ currentExpectedClassicFormatFrame = self ::genFrameForSpanWithStackDepth ($ spanIndex , $ stackFrameIndex , $ stackDepth );
1371- $ dbgCtx ->add (['currentExpectedClassicFormatFrame ' => $ currentExpectedClassicFormatFrame ]);
1372- $ prevExpectedClassicFormatFrame = $ stackFrameIndex === 0 ? null : self ::genFrameForSpanWithStackDepth ($ spanIndex , $ stackFrameIndex - 1 , $ stackDepth );
1373- $ dbgCtx ->add (['prevExpectedClassicFormatFrame ' => $ prevExpectedClassicFormatFrame ]);
1374- StackTraceFrameExpectations::fromClassicFormat ($ currentExpectedClassicFormatFrame , $ prevExpectedClassicFormatFrame )->assertMatches ($ span ->stackTrace [$ stackFrameIndex ]);
1376+ if ($ this ->isSpanStackTraceEnabled ($ span )) {
1377+ self ::assertNotNull ($ span ->stackTrace );
1378+ if ($ expectedMaxNumberOfFrames !== null ) {
1379+ TestCaseBase::assertLessThanOrEqual ($ expectedMaxNumberOfFrames , count ($ span ->stackTrace ));
1380+ }
1381+ $ dbgCtx ->pushSubScope ();
1382+ foreach (RangeUtil::generateUpTo (count ($ span ->stackTrace )) as $ stackFrameIndex ) {
1383+ $ dbgCtx ->add (['stackFrameIndex ' => $ stackFrameIndex ]);
1384+ $ currentExpectedClassicFormatFrame = self ::genFrameForSpanWithStackDepth ($ spanIndex , $ stackFrameIndex , $ stackDepth );
1385+ $ dbgCtx ->add (['currentExpectedClassicFormatFrame ' => $ currentExpectedClassicFormatFrame ]);
1386+ $ prevExpectedClassicFormatFrame = $ stackFrameIndex === 0 ? null : self ::genFrameForSpanWithStackDepth ($ spanIndex , $ stackFrameIndex - 1 , $ stackDepth );
1387+ $ dbgCtx ->add (['prevExpectedClassicFormatFrame ' => $ prevExpectedClassicFormatFrame ]);
1388+ StackTraceFrameExpectations::fromClassicFormat ($ currentExpectedClassicFormatFrame , $ prevExpectedClassicFormatFrame )->assertMatches ($ span ->stackTrace [$ stackFrameIndex ]);
1389+ }
1390+ $ dbgCtx ->popSubScope ();
1391+ } else {
1392+ self ::assertNull ($ span ->stackTrace );
13751393 }
1376- $ dbgCtx ->popSubScope ();
13771394 }
13781395 $ dbgCtx ->popSubScope ();
13791396 }
0 commit comments