diff --git a/agent/native/ext/ConfigManager.cpp b/agent/native/ext/ConfigManager.cpp index b27ed5998..9ce2ed392 100644 --- a/agent/native/ext/ConfigManager.cpp +++ b/agent/native/ext/ConfigManager.cpp @@ -803,6 +803,7 @@ ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, breakdownMetrics ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, captureErrors ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, devInternal ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, devInternalBackendCommLogVerbose ) +ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, devInternalCurlInstrumCallCurl ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, disableInstrumentations ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, disableSend ) ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, enabled ) @@ -1020,6 +1021,12 @@ static void initOptionsMetadata( OptionMetadata* optsMeta ) ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_BACKEND_COMM_LOG_VERBOSE, /* defaultValue: */ false ); + ELASTIC_APM_INIT_METADATA( + buildBoolOptionMetadata, + devInternalCurlInstrumCallCurl, + ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CALL_CURL, + /* defaultValue: */ true ); + ELASTIC_APM_INIT_METADATA( buildStringOptionMetadata, disableInstrumentations, diff --git a/agent/native/ext/ConfigManager.h b/agent/native/ext/ConfigManager.h index fc27fde09..5b08d73d7 100644 --- a/agent/native/ext/ConfigManager.h +++ b/agent/native/ext/ConfigManager.h @@ -76,6 +76,7 @@ enum OptionId optionId_captureErrors, optionId_devInternal, optionId_devInternalBackendCommLogVerbose, + optionId_devInternalCurlInstrumCallCurl, optionId_disableInstrumentations, optionId_disableSend, optionId_enabled, @@ -267,6 +268,7 @@ const ConfigSnapshot* getGlobalCurrentConfigSnapshot(); */ #define ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL "dev_internal" #define ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_BACKEND_COMM_LOG_VERBOSE "dev_internal_backend_comm_log_verbose" +#define ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CALL_CURL "dev_internal_curl_instrum_call_curl" #define ELASTIC_APM_CFG_OPT_NAME_DISABLE_INSTRUMENTATIONS "disable_instrumentations" #define ELASTIC_APM_CFG_OPT_NAME_DISABLE_SEND "disable_send" diff --git a/agent/native/ext/ConfigSnapshot.h b/agent/native/ext/ConfigSnapshot.h index 9c96a58fd..554eea01f 100644 --- a/agent/native/ext/ConfigSnapshot.h +++ b/agent/native/ext/ConfigSnapshot.h @@ -47,6 +47,7 @@ struct ConfigSnapshot bool captureErrors = false; String devInternal = nullptr; bool devInternalBackendCommLogVerbose = false; + bool devInternalCurlInstrumCallCurl = true; String disableInstrumentations = nullptr; bool disableSend = false; bool enabled = false; diff --git a/agent/native/ext/elastic_apm.cpp b/agent/native/ext/elastic_apm.cpp index 66c03feaa..203558019 100644 --- a/agent/native/ext/elastic_apm.cpp +++ b/agent/native/ext/elastic_apm.cpp @@ -153,6 +153,7 @@ PHP_INI_BEGIN() ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_CAPTURE_ERRORS ) ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL ) ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_BACKEND_COMM_LOG_VERBOSE ) + ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CALL_CURL ) ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DISABLE_INSTRUMENTATIONS ) ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_DISABLE_SEND ) ELASTIC_APM_NOT_RELOADABLE_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_ENABLED ) diff --git a/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php b/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php index a4c6fbbe2..e991008ae 100644 --- a/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php +++ b/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php @@ -585,7 +585,12 @@ private function setContextPostHook(): void */ private function curlExecPostHook(int $numberOfStackFramesToSkip, $returnValue): void { - $this->setContextPostHook(); + if ($this->tracer->getConfig()->devInternalCurlInstrumCallCurl()) { + $this->setContextPostHook(); + } else { + ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__)) + && $loggerProxy->log('dev_internal_curl_instrum_call_curl (devInternalCurlInstrumCallCurl) is set to false - skipping setContextPostHook'); + } AutoInstrumentationUtil::endSpan($numberOfStackFramesToSkip + 1, $this->span, /* hasExitedByException */ false, $returnValue); } @@ -607,13 +612,18 @@ private function injectDistributedTracingHeaders(array $headersToInjectFormatted ($loggerProxy = $logger->ifTraceLevelEnabled(__LINE__, __FUNCTION__)) && $loggerProxy->log('Injecting outgoing HTTP request headers for distributed tracing...'); - $setOptRetVal = $this->curlHandle->setOpt(CURLOPT_HTTPHEADER, $headers); - if ($setOptRetVal) { - ($loggerProxy = $logger->ifTraceLevelEnabled(__LINE__, __FUNCTION__)) - && $loggerProxy->log('Successfully injected outgoing HTTP request headers for distributed tracing'); + if ($this->tracer->getConfig()->devInternalCurlInstrumCallCurl()) { + $setOptRetVal = $this->curlHandle->setOpt(CURLOPT_HTTPHEADER, $headers); + if ($setOptRetVal) { + ($loggerProxy = $logger->ifTraceLevelEnabled(__LINE__, __FUNCTION__)) + && $loggerProxy->log('Successfully injected outgoing HTTP request headers for distributed tracing'); + } else { + ($loggerProxy = $logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__)) + && $loggerProxy->log('Failed to inject outgoing HTTP request headers for distributed tracing'); + } } else { - ($loggerProxy = $logger->ifErrorLevelEnabled(__LINE__, __FUNCTION__)) - && $loggerProxy->log('Failed to inject outgoing HTTP request headers for distributed tracing'); + ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__)) + && $loggerProxy->log('dev_internal_curl_instrum_call_curl (devInternalCurlInstrumCallCurl) is set to false - NOT injecting outgoing HTTP request headers for distributed tracing'); } } diff --git a/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php b/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php index e3bd9ecd3..7cc7a0f3c 100644 --- a/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php +++ b/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php @@ -91,6 +91,7 @@ public static function get(): array OptionNames::BREAKDOWN_METRICS => new BoolOptionMetadata(/* default */ true), OptionNames::CAPTURE_ERRORS => new BoolOptionMetadata(/* default */ true), OptionNames::DEV_INTERNAL => new NullableWildcardListOptionMetadata(), + OptionNames::DEV_INTERNAL_CURL_INSTRUM_CALL_CURL => new BoolOptionMetadata(/* default */ true), OptionNames::DISABLE_INSTRUMENTATIONS => new NullableWildcardListOptionMetadata(), OptionNames::DISABLE_SEND => new BoolOptionMetadata(/* default */ false), OptionNames::ENABLED => new BoolOptionMetadata(/* default */ true), diff --git a/agent/php/ElasticApm/Impl/Config/OptionNames.php b/agent/php/ElasticApm/Impl/Config/OptionNames.php index 7c9ca7be6..cd53e1fd0 100644 --- a/agent/php/ElasticApm/Impl/Config/OptionNames.php +++ b/agent/php/ElasticApm/Impl/Config/OptionNames.php @@ -43,6 +43,7 @@ final class OptionNames public const BREAKDOWN_METRICS = 'breakdown_metrics'; public const CAPTURE_ERRORS = 'capture_errors'; public const DEV_INTERNAL = 'dev_internal'; + public const DEV_INTERNAL_CURL_INSTRUM_CALL_CURL = 'dev_internal_curl_instrum_call_curl'; public const DISABLE_INSTRUMENTATIONS = 'disable_instrumentations'; public const DISABLE_SEND = 'disable_send'; public const ENABLED = 'enabled'; diff --git a/agent/php/ElasticApm/Impl/Config/Snapshot.php b/agent/php/ElasticApm/Impl/Config/Snapshot.php index a6aab762b..2e5872d3e 100644 --- a/agent/php/ElasticApm/Impl/Config/Snapshot.php +++ b/agent/php/ElasticApm/Impl/Config/Snapshot.php @@ -125,6 +125,9 @@ final class Snapshot implements LoggableInterface /** @var SnapshotDevInternal */ private $devInternalParsed; + /** @var bool */ + private $devInternalCurlInstrumCallCurl; + /** @var ?WildcardListMatcher */ private $disableInstrumentations; @@ -287,6 +290,11 @@ public function devInternal(): SnapshotDevInternal return $this->devInternalParsed; } + public function devInternalCurlInstrumCallCurl(): bool + { + return $this->devInternalCurlInstrumCallCurl; + } + public function disableInstrumentations(): ?WildcardListMatcher { return $this->disableInstrumentations; diff --git a/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php b/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php index a7b553b45..6404de1d7 100644 --- a/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php +++ b/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php @@ -140,6 +140,8 @@ private static function buildOptionNameToRawToValue(): array OptionNames::CAPTURE_ERRORS => $boolRawToParsedValues(), OptionNames::ENABLED => $boolRawToParsedValues(/* valueToExclude: */ false), OptionNames::DEV_INTERNAL => $wildcardListRawToParsedValues, + OptionNames::DEV_INTERNAL_CURL_INSTRUM_CALL_CURL + => $boolRawToParsedValues(), OptionNames::DISABLE_INSTRUMENTATIONS => $wildcardListRawToParsedValues, OptionNames::DISABLE_SEND => $boolRawToParsedValues(/* valueToExclude: */ true), OptionNames::ENVIRONMENT => $stringRawToParsedValues([" my_environment \t "]),