Skip to content

Commit

Permalink
Added PHP part
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKleyman committed Jul 16, 2024
1 parent ddb8c54 commit 20ac820
Show file tree
Hide file tree
Showing 27 changed files with 241 additions and 1,387 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"nyholm/psr7": "^1.8",
"open-telemetry/exporter-otlp": "1.0.4",
"open-telemetry/opentelemetry-auto-laravel": "0.0.25",
"open-telemetry/opentelemetry-auto-slim": "1.0.6",
"open-telemetry/sdk": "1.0.8",
"php-http/guzzle7-adapter": "^1.0",
"symfony/http-client": "6.*||7.*"
Expand All @@ -23,7 +24,7 @@
"require-dev": {
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "1.3.2",
"phpstan/phpstan": "1.10.57",
"phpstan/phpstan": "1.11.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpunit/phpunit": "^9.6||^10.5",
"slevomat/coding-standard": "8.14.1",
Expand Down
6 changes: 3 additions & 3 deletions packaging/test/smokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
echo CGREEN."OK\n".CDEF;

echo "Looking for PhpPartFacade class: ";
if (array_search("Elastic\OTel\AutoInstrument\PhpPartFacade", get_declared_classes()) === false) {
echo CRED."FAILED. Elastic\OTel\AutoInstrument\PhpPartFacade class not found. Bootstrap failed\n".CDEF;
if (array_search("Elastic\OTel\PhpPartFacade", get_declared_classes()) === false) {
echo CRED."FAILED. Elastic\OTel\PhpPartFacade class not found. Bootstrap failed\n".CDEF;
exit(1);
}
echo CGREEN."OK\n".CDEF;

echo "Trying to log something to stderr: ";
Elastic\OTel\AutoInstrument\BootstrapStageLogger::logCritical("This is just a message to test logger", __LINE__, __FUNCTION__);
Elastic\OTel\BootstrapStageLogger::logCritical("This is just a message to test logger", __LINE__, __FUNCTION__);
echo CGREEN."OK\n".CDEF;

echo CGREEN."Smoke test passed\n".CDEF;
4 changes: 2 additions & 2 deletions packaging/test/smokeTestUninstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
echo CGREEN."OK\n".CDEF;

echo "Looking for PhpPartFacade class: ";
if (array_search("Elastic\OTel\AutoInstrument\PhpPartFacade", get_declared_classes()) !== false) {
echo CRED."FAILED. Elastic\OTel\AutoInstrument\PhpPartFacade class not found. Bootstrap failed\n".CDEF;
if (array_search("Elastic\OTel\PhpPartFacade", get_declared_classes()) !== false) {
echo CRED."FAILED. Elastic\OTel\PhpPartFacade class not found. Bootstrap failed\n".CDEF;
exit(1);
}
echo CGREEN."OK\n".CDEF;
Expand Down
2 changes: 1 addition & 1 deletion prod/native/extension/code/ModuleEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PHP_GSHUTDOWN_FUNCTION(elastic_otel) {
}

// if (elastic_otel_globals->lastErrorData) {
// // elastic_otel_LOG_DIRECT_WARNING( "%s: still holding error", __FUNCTION__);
// // ELASTIC_OTEL_LOG_DIRECT_WARNING( "%s: still holding error", __FUNCTION__);
// // we need to relese any dangling php error data beacause it is already freed (it was allocated in request pool)
// elastic_otel_globals->lastErrorData.release();
// }
Expand Down
10 changes: 5 additions & 5 deletions prod/native/extension/code/ModuleInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ void elasticApmModuleShutdown( int moduleType, int moduleNumber ) {
// }

// array_init( return_value );
// ELASTIC_APM_ZEND_ADD_ASSOC(return_value, "type", long, static_cast<zend_long>(ELASTICAPM_G(lastErrorData)->getType()));
// ELASTIC_APM_ZEND_ADD_ASSOC_NULLABLE_STRING( return_value, "fileName", ELASTICAPM_G(lastErrorData)->getFileName().data() );
// ELASTIC_APM_ZEND_ADD_ASSOC(return_value, "lineNumber", long, static_cast<zend_long>(ELASTICAPM_G(lastErrorData)->getLineNumber()));
// ELASTIC_APM_ZEND_ADD_ASSOC_NULLABLE_STRING( return_value, "message", ELASTICAPM_G(lastErrorData)->getMessage().data());
// ELASTIC_OTEL_ZEND_ADD_ASSOC(return_value, "type", long, static_cast<zend_long>(ELASTICAPM_G(lastErrorData)->getType()));
// ELASTIC_OTEL_ZEND_ADD_ASSOC_NULLABLE_STRING( return_value, "fileName", ELASTICAPM_G(lastErrorData)->getFileName().data() );
// ELASTIC_OTEL_ZEND_ADD_ASSOC(return_value, "lineNumber", long, static_cast<zend_long>(ELASTICAPM_G(lastErrorData)->getLineNumber()));
// ELASTIC_OTEL_ZEND_ADD_ASSOC_NULLABLE_STRING( return_value, "message", ELASTICAPM_G(lastErrorData)->getMessage().data());
// Z_TRY_ADDREF_P((ELASTICAPM_G(lastErrorData)->getStackTrace()));
// ELASTIC_APM_ZEND_ADD_ASSOC(return_value, "stackTrace", zval, (ELASTICAPM_G(lastErrorData)->getStackTrace()));
// ELASTIC_OTEL_ZEND_ADD_ASSOC(return_value, "stackTrace", zval, (ELASTICAPM_G(lastErrorData)->getStackTrace()));
// }
//
// void elasticApmGetLastThrown(zval *return_value) {
Expand Down
14 changes: 7 additions & 7 deletions prod/native/extension/code/util_for_PHP.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@



#define ELASTIC_APM_PP_CONCAT_IMPL( token1, token2 ) token1##token2
#define ELASTIC_APM_PP_CONCAT( token1, token2 ) ELASTIC_APM_PP_CONCAT_IMPL( token1, token2 )
#define ELASTIC_OTEL_PP_CONCAT_IMPL( token1, token2 ) token1##token2
#define ELASTIC_OTEL_PP_CONCAT( token1, token2 ) ELASTIC_OTEL_PP_CONCAT_IMPL( token1, token2 )

#define ELASTIC_APM_ZEND_ADD_ASSOC( map, key, valueType, value ) ELASTIC_APM_PP_CONCAT( ELASTIC_APM_PP_CONCAT( add_assoc_, valueType ), _ex)( (map), (key), sizeof( key ) - 1, (value) )
#define ELASTIC_OTEL_ZEND_ADD_ASSOC( map, key, valueType, value ) ELASTIC_OTEL_PP_CONCAT( ELASTIC_OTEL_PP_CONCAT( add_assoc_, valueType ), _ex)( (map), (key), sizeof( key ) - 1, (value) )

#define ELASTIC_APM_ZEND_ADD_ASSOC_NULLABLE_STRING( map, key, value ) \
#define ELASTIC_OTEL_ZEND_ADD_ASSOC_NULLABLE_STRING( map, key, value ) \
do { \
if ( (value) == NULL ) \
{ \
zval elastic_apm_zend_add_assoc_nullable_string_aux_zval; \
ZVAL_NULL( &elastic_apm_zend_add_assoc_nullable_string_aux_zval ); \
add_assoc_zval_ex( (map), (key), sizeof( key ) - 1, &elastic_apm_zend_add_assoc_nullable_string_aux_zval ); \
zval elastic_otel_zend_add_assoc_nullable_string_aux_zval; \
ZVAL_NULL( &elastic_otel_zend_add_assoc_nullable_string_aux_zval ); \
add_assoc_zval_ex( (map), (key), sizeof( key ) - 1, &elastic_otel_zend_add_assoc_nullable_string_aux_zval ); \
} \
else \
{ \
Expand Down
1 change: 0 additions & 1 deletion prod/native/extension/phpt/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ cp -R "${TESTS_TO_RUN}" "${LOCAL_TMP_DIR}/${TESTS_TO_RUN}"
docker run --rm \
--platform ${DOCKER_PLATFORM} \
-v ${LOCAL_TMP_DIR}/tests:/phpt-tests/tests \
-v ./tests_util:/phpt-tests/tests_util \
-v ${LOCAL_LOG_FAILED_TESTS}:${LOG_FAILED_TESTS} \
-v ${LOCAL_LOG_TEST_RUN}:${LOG_TEST_RUN} \
-v ${ELASTIC_AGENT_PHP_PATH}:/elastic/php \
Expand Down
20 changes: 3 additions & 17 deletions prod/native/extension/phpt/tests/includes/bootstrap_mock.inc
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
<?php

declare(strict_types=1);
namespace Elastic\OTel\AutoInstrument;

namespace Elastic\OTel;

final class PhpPartFacade
{
private static $singletonInstance = null;

public static function bootstrap(int $maxEnabledLogLevel, float $requestInitStartTime): bool {
self::$singletonInstance = new self();
return true;
}

private static function singletonInstance(): self {
if (self::$singletonInstance === null) {
self::$singletonInstance = new self();
}
return self::$singletonInstance;
}

public static function ensureHaveLatestDataDeferredByExtension(): void {
}

public static function shutdown(): void {
self::$singletonInstance = null;
}

public static function handle_error(): void {
public static function handleError(): void {
}

}
12 changes: 6 additions & 6 deletions prod/native/extension/phpt/tests/includes/tests_util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ function sharedChecks(): void
// die('Extension elastic_apm must be installed');
// }

// elasticApmAssertSame("getenv('ELASTIC_APM_LOG_LEVEL_STDERR')", getenv('ELASTIC_APM_LOG_LEVEL_STDERR'), 'CRITICAL');
// elasticApmAssertSame("getenv('ELASTIC_OTEL_LOG_LEVEL_STDERR')", getenv('ELASTIC_OTEL_LOG_LEVEL_STDERR'), 'CRITICAL');
// /** @noinspection PhpUndefinedFunctionInspection, PhpUndefinedConstantInspection */
// elasticApmAssertSame(
// "elastic_apm_get_config_option_by_name('log_level_stderr')",
// elastic_apm_get_config_option_by_name('log_level_stderr'),
// ELASTIC_APM_LOG_LEVEL_CRITICAL
// "elastic_otel_get_config_option_by_name('log_level_stderr')",
// elastic_otel_get_config_option_by_name('log_level_stderr'),
// ELASTIC_OTEL_LOG_LEVEL_CRITICAL
// );

// $expected_bootstrap_php_part_file = '../../php/bootstrap_php_part.php';
Expand All @@ -101,8 +101,8 @@ function sharedChecks(): void
// );
// /** @noinspection PhpUndefinedFunctionInspection, PhpUndefinedConstantInspection */
// elasticApmAssertSame(
// "elastic_apm_get_config_option_by_name('bootstrap_php_part_file')",
// elastic_apm_get_config_option_by_name('bootstrap_php_part_file'),
// "elastic_otel_get_config_option_by_name('bootstrap_php_part_file')",
// elastic_otel_get_config_option_by_name('bootstrap_php_part_file'),
// $expected_bootstrap_php_part_file
// );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "Test completed\n";
args:
array(6) {
[0]=>
object(DateTime)#4 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2010-01-01 00:00:00.000000"
["timezone_type"]=>
Expand All @@ -59,7 +59,7 @@ array(6) {
args:
array(8) {
[0]=>
object(DateTime)#4 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2010-01-01 00:00:00.000000"
["timezone_type"]=>
Expand Down
4 changes: 2 additions & 2 deletions prod/native/libcommon/code/basic_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

#define ELASTIC_APM_PP_STRINGIZE_IMPL( token ) #token
#define EL_STRINGIFY( token ) ELASTIC_APM_PP_STRINGIZE_IMPL( token )
#define ELASTIC_OTEL_PP_STRINGIZE_IMPL( token ) #token
#define EL_STRINGIFY( token ) ELASTIC_OTEL_PP_STRINGIZE_IMPL( token )
16 changes: 8 additions & 8 deletions prod/native/libphpbridge/code/PhpBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::optional<std::string_view> PhpBridge::getCurrentExceptionMessage() const {
}

bool PhpBridge::callInferredSpans(std::chrono::milliseconds duration) const {
auto phpPartFacadeClass = findClassEntry("elastic\\apm\\impl\\autoinstrument\\phppartfacade"sv);
auto phpPartFacadeClass = findClassEntry("elastic\\apm\\impl\\phppartfacade"sv);
if (!phpPartFacadeClass) {
return false;
}
Expand All @@ -63,7 +63,7 @@ bool PhpBridge::callInferredSpans(std::chrono::milliseconds duration) const {
}

auto transactionForExtensionRequest = getClassPropertyValue(phpPartFacadeClass, objectOfPhpPartFacade, "transactionForExtensionRequest"sv);
if (!isObjectOfClass(transactionForExtensionRequest, "Elastic\\Apm\\Impl\\AutoInstrument\\TransactionForExtensionRequest")) {
if (!isObjectOfClass(transactionForExtensionRequest, "Elastic\\Apm\\Impl\\TransactionForExtensionRequest")) {
return false;
}

Expand Down Expand Up @@ -174,36 +174,36 @@ void PhpBridge::compileAndExecuteFile(std::string_view fileName) const {
}

bool PhpBridge::callPHPSideEntryPoint(LogLevel logLevel, std::chrono::time_point<std::chrono::system_clock> requestInitStart) const {
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\autoinstrument\\phppartfacade"sv);
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\phppartfacade"sv);
if (!phpPartFacadeClass) {
return false;
}

std::array<AutoZval, 2> arguments{logLevel, (double)std::chrono::duration_cast<std::chrono::microseconds>(requestInitStart.time_since_epoch()).count()};
AutoZval rv;
return callMethod(nullptr, "\\Elastic\\OTel\\AutoInstrument\\PhpPartFacade::bootstrap"sv, arguments.data()->get(), arguments.size(), rv.get());
return callMethod(nullptr, "\\Elastic\\OTel\\PhpPartFacade::bootstrap"sv, arguments.data()->get(), arguments.size(), rv.get());
}

bool PhpBridge::callPHPSideExitPoint() const {
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\autoinstrument\\phppartfacade"sv);
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\phppartfacade"sv);
if (!phpPartFacadeClass) {
return false;
}

AutoZval rv;
return callMethod(nullptr, "Elastic\\OTel\\AutoInstrument\\PhpPartFacade::shutdown"sv, nullptr, 0, rv.get());
return callMethod(nullptr, "Elastic\\OTel\\PhpPartFacade::shutdown"sv, nullptr, 0, rv.get());
}

bool PhpBridge::callPHPSideErrorHandler(int type, std::string_view errorFilename, uint32_t errorLineno, std::string_view message) const {
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\autoinstrument\\phppartfacade"sv);
auto phpPartFacadeClass = findClassEntry("elastic\\otel\\phppartfacade"sv);
if (!phpPartFacadeClass) {
return false;
}

std::array<AutoZval, 4> arguments{type, errorFilename, errorLineno, message};

AutoZval rv;
return callMethod(nullptr, "\\Elastic\\OTel\\AutoInstrument\\PhpPartFacade::handle_error"sv, arguments.data()->get(), arguments.size(), rv.get());
return callMethod(nullptr, "\\Elastic\\OTel\\PhpPartFacade::handleError"sv, arguments.data()->get(), arguments.size(), rv.get());
}


Expand Down
103 changes: 0 additions & 103 deletions prod/php/ElasticOTel/AutoInstrument/Autoloader.php

This file was deleted.

Loading

0 comments on commit 20ac820

Please sign in to comment.