diff --git a/agent/native/ext/ConfigManager.cpp b/agent/native/ext/ConfigManager.cpp index b27ed5998..dd6fdd0d1 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, devInternalCurlInstrumCreateSpan ) 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, + devInternalCurlInstrumCreateSpan, + ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CREATE_SPAN, + /* defaultValue: */ true ); + ELASTIC_APM_INIT_METADATA( buildStringOptionMetadata, disableInstrumentations, diff --git a/agent/native/ext/ConfigManager.h b/agent/native/ext/ConfigManager.h index fc27fde09..9855d446e 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_devInternalCurlInstrumCreateSpan, 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_CREATE_SPAN "dev_internal_curl_instrum_create_span" #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..ee97ec687 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 devInternalCurlInstrumCreateSpan = 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..fb5ba5d4b 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_CREATE_SPAN ) 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..a33304b53 100644 --- a/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php +++ b/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php @@ -33,6 +33,7 @@ use Elastic\Apm\Impl\Log\LoggableInterface; use Elastic\Apm\Impl\Log\LoggableTrait; use Elastic\Apm\Impl\Log\Logger; +use Elastic\Apm\Impl\NoopSpan; use Elastic\Apm\Impl\Tracer; use Elastic\Apm\Impl\Util\ArrayUtil; use Elastic\Apm\Impl\Util\Assert; @@ -424,13 +425,20 @@ private function curlExecPreHook(): void $spanName = $httpMethod . ' ' . $host; $isHttp = ($this->url !== null) && UrlUtil::isHttp($this->url); - $this->span = AutoInstrumentationUtil::beginCurrentSpan($spanName, Constants::SPAN_TYPE_EXTERNAL, /* subtype: */ $isHttp ? Constants::SPAN_SUBTYPE_HTTP : null); + if ($this->tracer->getConfig()->devInternalCurlInstrumCreateSpan()) { + $this->span = AutoInstrumentationUtil::beginCurrentSpan($spanName, Constants::SPAN_TYPE_EXTERNAL, /* subtype: */ $isHttp ? Constants::SPAN_SUBTYPE_HTTP : null); + } else { + ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__)) + && $loggerProxy->log('dev_internal_curl_instrum_create_span (devInternalCurlInstrumCreateSpan) is set to false - creating no-op span'); + $this->span = NoopSpan::singletonInstance(); + } $this->setContextPreHook(); if ($isHttp) { $headersToInjectFormattedLines = []; - $this->span->injectDistributedTracingHeaders( + $execSeg = $this->span->isNoop() ? $this->tracer->getCurrentTransaction() : $this->span; + $execSeg->injectDistributedTracingHeaders( function (string $headerName, string $headerValue) use (&$headersToInjectFormattedLines): void { $headersToInjectFormattedLines[] = $headerName . ': ' . $headerValue; } diff --git a/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php b/agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php index e3bd9ecd3..2d1a26d31 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_CREATE_SPAN => 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..24f7f2636 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_CREATE_SPAN = 'dev_internal_curl_instrum_create_span'; 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..6623f4d1a 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 $devInternalCurlInstrumCreateSpan; + /** @var ?WildcardListMatcher */ private $disableInstrumentations; @@ -287,6 +290,11 @@ public function devInternal(): SnapshotDevInternal return $this->devInternalParsed; } + public function devInternalCurlInstrumCreateSpan(): bool + { + return $this->devInternalCurlInstrumCreateSpan; + } + public function disableInstrumentations(): ?WildcardListMatcher { return $this->disableInstrumentations; diff --git a/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php b/tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php index a7b553b45..cf84fd55c 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_CREATE_SPAN + => $boolRawToParsedValues(), OptionNames::DISABLE_INSTRUMENTATIONS => $wildcardListRawToParsedValues, OptionNames::DISABLE_SEND => $boolRawToParsedValues(/* valueToExclude: */ true), OptionNames::ENVIRONMENT => $stringRawToParsedValues([" my_environment \t "]),