diff --git a/agent/php/ElasticApm/Impl/AutoInstrument/Util/AutoInstrumentationUtil.php b/agent/php/ElasticApm/Impl/AutoInstrument/Util/AutoInstrumentationUtil.php index 76cf4bdbf..930166783 100644 --- a/agent/php/ElasticApm/Impl/AutoInstrument/Util/AutoInstrumentationUtil.php +++ b/agent/php/ElasticApm/Impl/AutoInstrument/Util/AutoInstrumentationUtil.php @@ -31,6 +31,7 @@ use Elastic\Apm\Impl\Span; use Elastic\Apm\Impl\Util\Assert; use Elastic\Apm\Impl\Util\DbgUtil; +use Elastic\Apm\Impl\Util\StackTraceUtil; use Elastic\Apm\SpanInterface; use Throwable; @@ -56,7 +57,7 @@ public function __construct(LoggerFactory $loggerFactory) public static function buildSpanNameFromCall(?string $className, string $funcName): string { - return ($className === null) ? $funcName : ($className . '->' . $funcName); + return ($className === null) ? $funcName : ($className . StackTraceUtil::CLASS_AND_METHOD_SEPARATOR . $funcName); } private static function processNewSpan(SpanInterface $span): void diff --git a/agent/php/ElasticApm/Impl/Util/StackTraceUtil.php b/agent/php/ElasticApm/Impl/Util/StackTraceUtil.php index e28ced68d..4e7f7b3f6 100644 --- a/agent/php/ElasticApm/Impl/Util/StackTraceUtil.php +++ b/agent/php/ElasticApm/Impl/Util/StackTraceUtil.php @@ -43,6 +43,7 @@ final class StackTraceUtil public const TYPE_KEY = 'type'; public const FUNCTION_IS_STATIC_METHOD_TYPE_VALUE = '::'; public const FUNCTION_IS_METHOD_TYPE_VALUE = '->'; + public const CLASS_AND_METHOD_SEPARATOR = '::'; public const THIS_OBJECT_KEY = 'object'; public const ARGS_KEY = 'args'; @@ -270,8 +271,7 @@ public static function buildApmFormatFunctionForClassMethod(?string $classicName return $methodName; } - $classMethodSep = ($isStaticMethod === null) ? '.' : ($isStaticMethod ? StackTraceUtil::FUNCTION_IS_STATIC_METHOD_TYPE_VALUE : StackTraceUtil::FUNCTION_IS_METHOD_TYPE_VALUE); - return $classicName . $classMethodSep . $methodName; + return $classicName . StackTraceUtil::CLASS_AND_METHOD_SEPARATOR . $methodName; } private static function isTrampolineCall(ClassicFormatStackTraceFrame $frame): bool diff --git a/tests/ElasticApmTests/UnitTests/InferredSpansBuilderTest.php b/tests/ElasticApmTests/UnitTests/InferredSpansBuilderTest.php index 3cf85ff67..bfacb222a 100644 --- a/tests/ElasticApmTests/UnitTests/InferredSpansBuilderTest.php +++ b/tests/ElasticApmTests/UnitTests/InferredSpansBuilderTest.php @@ -183,7 +183,7 @@ function (InferredSpansBuilder $builder) use (&$expectedStackTrace, $expectedTim self::assertSame('InferredSpansBuilderTest', ClassNameUtil::fqToShort(__CLASS__)); self::assertSame('helperForTestOneStackTrace', $expectedStackTrace[0]->function); - self::assertSame('InferredSpansBuilderTest->helperForTestOneStackTrace', $span->name); + self::assertSame('InferredSpansBuilderTest::helperForTestOneStackTrace', $span->name); self::assertSame(InferredSpanExpectationsBuilder::DEFAULT_SPAN_TYPE, $span->type); self::assertSame($expectedTimestampMicroseconds, $span->timestamp); self::assertSame($expectedDurationMilliseconds, $span->duration); diff --git a/tests/ElasticApmTests/UnitTests/UtilTests/StackTraceUtilTest.php b/tests/ElasticApmTests/UnitTests/UtilTests/StackTraceUtilTest.php index 6d2ba2bd7..c08e04229 100644 --- a/tests/ElasticApmTests/UnitTests/UtilTests/StackTraceUtilTest.php +++ b/tests/ElasticApmTests/UnitTests/UtilTests/StackTraceUtilTest.php @@ -111,18 +111,18 @@ public static function testStaticClosureExpections(): void public function dataProviderForTestConvertClassAndMethodToFunctionName(): iterable { yield ['MyClass', /* isStaticMethod */ true, 'myMethod', 'MyClass::myMethod']; - yield ['MyClass', /* isStaticMethod */ false, 'myMethod', 'MyClass->myMethod']; - yield ['MyClass', /* isStaticMethod */ null, 'myMethod', 'MyClass.myMethod']; + yield ['MyClass', /* isStaticMethod */ false, 'myMethod', 'MyClass::myMethod']; + yield ['MyClass', /* isStaticMethod */ null, 'myMethod', 'MyClass::myMethod']; - yield ['MyNamespace\\MyClass', /* isStaticMethod */ false, 'myMethod', 'MyNamespace\\MyClass->myMethod']; - yield ['', /* isStaticMethod */ false, 'myMethod', '->myMethod']; + yield ['MyNamespace\\MyClass', /* isStaticMethod */ false, 'myMethod', 'MyNamespace\\MyClass::myMethod']; + yield ['', /* isStaticMethod */ false, 'myMethod', '::myMethod']; yield ['', /* isStaticMethod */ true, 'myMethod', '::myMethod']; - yield ['', /* isStaticMethod */ null, 'myMethod', '.myMethod']; + yield ['', /* isStaticMethod */ null, 'myMethod', '::myMethod']; yield [null, /* isStaticMethod */ true, 'myMethod', 'myMethod']; yield [null, /* isStaticMethod */ false, 'myMethod', 'myMethod']; yield [null, /* isStaticMethod */ null, 'myMethod', 'myMethod']; - yield ['MyClass', /* isStaticMethod */ false, '', 'MyClass->']; + yield ['MyClass', /* isStaticMethod */ false, '', 'MyClass::']; yield ['MyClass', /* isStaticMethod */ true, '', 'MyClass::']; yield ['MyClass', /* isStaticMethod */ true, null, null]; yield ['MyClass', /* isStaticMethod */ false, null, null]; diff --git a/tests/ElasticApmTests/Util/StackTraceFrameExpectations.php b/tests/ElasticApmTests/Util/StackTraceFrameExpectations.php index 3a1fb9a1b..cf4b8f4b9 100644 --- a/tests/ElasticApmTests/Util/StackTraceFrameExpectations.php +++ b/tests/ElasticApmTests/Util/StackTraceFrameExpectations.php @@ -59,7 +59,7 @@ public static function fromFrame(StackTraceFrame $frame): self private static function buildFunctionFromClassMethod(string $class, bool $isStatic, string $method): string { - return $class . ($isStatic ? '::' : '->') . $method; + return $class . StackTraceUtil::CLASS_AND_METHOD_SEPARATOR . $method; } public static function fromClassMethod(string $fileName, int $lineNumber, string $class, bool $isStatic, string $method): self