Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dev_internal_curl_instrum_create_span config #1152

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( 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 )
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(
buildBoolOptionMetadata,
devInternalCurlInstrumCreateSpan,
ELASTIC_APM_CFG_OPT_NAME_DEV_INTERNAL_CURL_INSTRUM_CREATE_SPAN,
/* defaultValue: */ true );

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_devInternalCurlInstrumCreateSpan,
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_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"
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;
bool devInternalCurlInstrumCreateSpan = true;
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_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 )
Expand Down
12 changes: 10 additions & 2 deletions agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
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_CREATE_SPAN => 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_CREATE_SPAN = 'dev_internal_curl_instrum_create_span';
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 $devInternalCurlInstrumCreateSpan;

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

Expand Down Expand Up @@ -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;
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_CREATE_SPAN
=> $boolRawToParsedValues(),
OptionNames::DISABLE_INSTRUMENTATIONS => $wildcardListRawToParsedValues,
OptionNames::DISABLE_SEND => $boolRawToParsedValues(/* valueToExclude: */ true),
OptionNames::ENVIRONMENT => $stringRawToParsedValues([" my_environment \t "]),
Expand Down
Loading