Skip to content

Commit

Permalink
Added dev_internal_curl_instrum_call_curl config
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKleyman committed Apr 30, 2024
1 parent 1d68a37 commit dca25f1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 7 deletions.
7 changes: 7 additions & 0 deletions agent/native/ext/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( stringValue, 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 )
Expand Down Expand Up @@ -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(
buildStringOptionMetadata,
devInternalCurlInstrumCallCurl,
ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CALL_CURL,
/* defaultValue: */ NULL );

ELASTIC_APM_INIT_METADATA(
buildStringOptionMetadata,
disableInstrumentations,
Expand Down
2 changes: 2 additions & 0 deletions agent/native/ext/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum OptionId
optionId_captureErrors,
optionId_devInternal,
optionId_devInternalBackendCommLogVerbose,
optionId_devInternalCurlInstrumCallCurl,
optionId_disableInstrumentations,
optionId_disableSend,
optionId_enabled,
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions agent/native/ext/ConfigSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct ConfigSnapshot
bool captureErrors = false;
String devInternal = nullptr;
bool devInternalBackendCommLogVerbose = false;
String devInternalCurlInstrumCallCurl = nullptr;
String disableInstrumentations = nullptr;
bool disableSend = false;
bool enabled = false;
Expand Down
1 change: 1 addition & 0 deletions agent/native/ext/elastic_apm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
24 changes: 17 additions & 7 deletions agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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');
}
}

Expand Down
1 change: 1 addition & 0 deletions agent/php/ElasticApm/Impl/Config/AllOptionsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions agent/php/ElasticApm/Impl/Config/OptionNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions agent/php/ElasticApm/Impl/Config/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ final class Snapshot implements LoggableInterface
/** @var SnapshotDevInternal */
private $devInternalParsed;

/** @var bool */
private $devInternalCurlInstrumCallCurl;

/** @var ?WildcardListMatcher */
private $disableInstrumentations;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "]),
Expand Down

0 comments on commit dca25f1

Please sign in to comment.