Skip to content

Commit

Permalink
Added SPAN_STACK_TRACE_MIN_DURATION configuration option (#996)
Browse files Browse the repository at this point in the history
* Set g_elasticApmDirectLogLevel* to default values so that they can be used even before configuration is parsed

* Added documentation for configuration options

* Added options to AllOptionsMetadata.php

* Added SPAN_COMPRESSION_* option names to OptionNames.php

* Added Span Compression options to Config/Snapshot.php

* Added COMPRESSION_STRATEGY_* constants

* Added implementation

* Added Span Compression related options to src/ext/ConfigManager.c

* Added Span Compression related options to src/ext/ConfigManager.h

* Added Span Compression related options to src/ext/elastic_apm.c

* Added Span Compression related options to tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php

* MySQLiTest: Disable Span Compression feature to have all the expected spans individually

* PDOTest: Disable Span Compression feature to have all the expected spans individually

* Added tests/ElasticApmTests/ComponentTests/SpanCompressionComponentTest.php

* Clarified comment about "Disable Span Compression"

* StackTraceComponentTest: Disable Span Compression feature to have all the expected spans individually

* Added TracerUnitTestCaseBase::isCompatibleWithSpanCompression

* InferredSpansBuilderTest: Disable Span Compression feature to have all the expected spans individually

* StackTraceUnitTest: Disable Span Compression feature to have all the expected spans individually

* Added tests/ElasticApmTests/UnitTests/SpanCompressionUnitTest.php

* Added tests\ElasticApmTests\Util\AssertValidTrait::assertValidNonNullableString

* Updated ElasticApmTests\Util\SpanDto

* Updated SpanExpectations

* Added optional dbgParamName for better diagnostics

* Distinguish between plugin name and keywords

Both name and keywords can be used to disable a plugin

* Removed unused imports

* Added 'internal-func' to names related to existing instrumentation (part 2)

to distinguish from other instrumentation mechanisms (for example the upcoming AST processing based)

* Added 'internal-func' to names related to existing instrumentation (part 3)

to distinguish from other instrumentation mechanisms (for example the upcoming AST processing based)

* Added 'internal-func' to names related to existing instrumentation (part 3)

to distinguish from other instrumentation mechanisms (for example the upcoming AST processing based)

* Added verifyExactArgsCount

* Implemented WordPress instrumentation - part 1

* Added AST_PROCESS_* options to AllOptionsMetadata.php

* Added option names to OptionNames.php

* Added AST processing options to Config/Snapshot.php

* Switch to span types wordpress_plugin and wordpress_theme

* Fixed issue with assertDirectoryDoesNotExist

assertDirectoryDoesNotExist that was added only in PHPUnit 9 and it does not exist in PHPUnit 8.5 that we still use when testing under older PHP versions

* Removed unused imports

* Added isStringViewSuffix

* Added new .c files to src/ext/config.m4

* Added AST processing related options to src/ext/ConfigManager.c

* Added AST processing related options to src/ext/ConfigManager.h

* Added ELASTIC_APM_WORDPRESS_DIRECT_CALL_METHOD_SET_READY_TO_WRAP_FILTER_CALLBACKS* constants

* Added AST processing related options to src/ext/elastic_apm.c

* Added AST processing related API from extension (native part) to PHP part of the agent

* Added AST processing related APIs to src/ext/elastic_apm_API.h

* Added calls for AST processing from lifecycle stages

* Instrumentation using AST processing (files src/ext/tracer_PHP_part.c|h)

files src/ext/tracer_PHP_part.h and src/ext/tracer_PHP_part.c)

* Removed duplicate isStringViewSuffix

* Added streamZVal

* Added ELASTIC_APM_PHP_TESTS_COMPARE_AST_CONVERTED_BACK_TO_SOURCE

* Added AppCodeHostParams::setAgentOptionIfNotDefaultValue

* Added AppCodeHostParams::setAgentOptions

* Excluded WordPress mock source from static analysis

* Instrumentation using AST processing (file tests/ElasticApmTests/ComponentTests/Util/ComponentTestCaseBase.php)

* Added ELASTIC_APM_PHP_TESTS_COMPARE_AST_CONVERTED_BACK_TO_SOURCE (part 2)

* Added AppCodeHostParams::setAgentOptionIfNotDefaultValue (part 2)

* Moved ArrayUtil::append back to ArrayUtilForTests::append

* Removed unused imports

* Added AST processing related options to tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php

* Added testReferencesInArray

* Added FileUtilForTests::createTempSubDir

* Added missing import

* Removed redundant local variable

* Added clarifying comments

* Reverted references of ELASTIC_APM_EMPTY_STRING_VIEW back to makeEmptyStringView()

since ELASTIC_APM_EMPTY_STRING_VIEW is added in a later PR

* Fixed incorrect merge

* Reverted references of ELASTIC_APM_EMPTY_STRING_VIEW back to makeEmptyStringView()

since ELASTIC_APM_EMPTY_STRING_VIEW is added in a later PR

* Fixed incorrect merge

* Added documentation for configuration options

* Added options to AllOptionsMetadata.php

* Added SPAN_COMPRESSION_* option names to OptionNames.php

* Added Span Compression options to Config/Snapshot.php

* Added COMPRESSION_STRATEGY_* constants

* Added implementation

* Added Span Compression related options to src/ext/ConfigManager.c

* Added Span Compression related options to src/ext/ConfigManager.h

* Added Span Compression related options to src/ext/elastic_apm.c

* Added Span Compression related options to tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php

* MySQLiTest: Disable Span Compression feature to have all the expected spans individually

* PDOTest: Disable Span Compression feature to have all the expected spans individually

* Added tests/ElasticApmTests/ComponentTests/SpanCompressionComponentTest.php

* Clarified comment about "Disable Span Compression"

* StackTraceComponentTest: Disable Span Compression feature to have all the expected spans individually

* Added TracerUnitTestCaseBase::isCompatibleWithSpanCompression

* InferredSpansBuilderTest: Disable Span Compression feature to have all the expected spans individually

* StackTraceUnitTest: Disable Span Compression feature to have all the expected spans individually

* Added tests/ElasticApmTests/UnitTests/SpanCompressionUnitTest.php

* Added tests\ElasticApmTests\Util\AssertValidTrait::assertValidNonNullableString

* Updated ElasticApmTests\Util\SpanDto

* Updated SpanExpectations

* Removed unused imports

* Extended span compression to spans without service target

* Removed redundant comment

* Clarified docs

* Added workaround for false positives from static analysis

* Simplified parallel-lint invocation

* Fixed unit tests failing on PHP 7.2

* Fixed issue found by static analysis

* Fixed formatting

* Fixed formatting

* Added --exclude ./tests/polyfills/

* Removed TestCaseBaseShim

* Fixed failing unit test

* Added ELASTIC_APM_PHP_TESTS_IS_LONG_RUN_MODE

* Reduced number of datasets from dataProviderForTestReasonsCompressionStops

* Run testOneCompressedSequence only in isLongRunMode

* Added check for isLongRunMode dataProviderForTestReasonsCompressionStops

* Fixed static analysis issue

* Fixed failing unit tests

* Removed unused import

* Fixed merge

* Fixed merge

* Fixed merge

* Fixed merge

* Temporarily hide TransactionMaxSpansUnitTest behind isLongRunMode

* Temporarily disable unit tests

* Fixed unit tests

* Added diagnostics

* Fixed failing unit tests

* Added re-run with escalated log level to HttpTransactionTest::testHttpStatus

* Fixed failing component test

* Revert "Temporarily disable unit tests"

This reverts commit 3c26cc5.

* Re-enabled SpanCompressionUnitTest::testReasonsCompressionStops

* Fixed merge

* Temporarily disabled component tests

* Fixed bad merge

* Temporarily run only PDOAutoInstrumentationTest

* Fixed merge

* Re-enabled component tests

* Fixed line endings

* Fixed line endings (CRLF -> LF)

* Fixed not cleaning up connection data in sync backend comm. mode

* Fixed not joining background sender thread if there was fork

Fixed not joining background sender thread if there was fork after module init

* Fixed system.container.id being detected but not stored in metadata

* Added component test for metadata's system.container.id detection

* Updated docs for service_node_name configuration option

* Set metadata's service.framework to WordPress/<version>

* Added check for stack trace to WordPressAutoInstrumentationTest

* Fixed ErrorComponentTest

* Fixed ErrorComponentTest

* Added WordPress and MySQLi to supported technologies

* Converted file path to Linux directory separators

* Added count for number of calls to WordPressFilterCallbackWrapper ctor/dtor

For supportability and component tests

* Replaced emalloc in cloneAstDecl with an array on stack

* Run composer install with retries for unit tests as well

* Converted StackTraceUtil from static class to class with instance state

* Added option part 1

* Remove outdated comment

* Added AssertMessageStack begin/end markers

* Added verification of top stack frame in WordPressAutoInstrumentationTest

* Make all properties of StackTraceFrameExpectations be Optional

* Made StackTraceUtil instance class

* Refactored call stack trace capturing code

* Refactor AutoInstrumentationUtil->captureCurrentSpan

* Fixed static analysis failure

* Use StackTraceFrameExpectations for $expectedCallbackStackTraceTopFrame

* Added docs for stack_trace_limit config

* Added tests

* Fixed failing component test

* Removed redundant import

* Added timestamps to static-check-unit-test.sh

* Added timeout to .phpt tests runs

* Added SPAN_STACK_TRACE_MIN_DURATION config to native part

* Removed unrelated changes

* Removed ELASTIC_APM_PHP_TESTS_PHPT_TIMEOUT_SECONDS

* Use fixed run-tests.php from PHP8.0

* modified run-tests.php

* disabled non-blocking read on std streams

* changed reading method

* Added test for config STACK_TRACE_LIMIT for inferred spans

* Updated documentation

* Removed redundant redirection

* Removed redundant comments

* Revert changes related to phpt_timeout to merge them separately

* Added documentation

* Allow any integer value for STACK_TRACE_LIMIT

* Added adaptToSmoke to StackTraceLimitComponentTest

* Fixed $cachedStackTraceLimitConfig type hint

* Removed redundant static analysis suppression

* Updated description in the documentation

* Implemented SPAN_STACK_TRACE_MIN_DURATION (production code)

* Added tests for SPAN_STACK_TRACE_MIN_DURATION

* Added tests for SPAN_STACK_TRACE_MIN_DURATION part 2

* Fixed failing SpanStackTraceComponentTest

* Update docs/configuration.asciidoc

Co-authored-by: Brandon Morelli <[email protected]>

* Updated documentation

* Refactored to disableTimingDependentFeatures

* Removed redundant import

* Fix issue found by static analysis

* Update docs/configuration.asciidoc

Co-authored-by: Brandon Morelli <[email protected]>

* Fixed wording in SPAN_STACK_TRACE_MIN_DURATION description

---------

Co-authored-by: Pawel Filipczak <[email protected]>
Co-authored-by: Brandon Morelli <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2023
1 parent d41a80f commit f8c1d58
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 25 deletions.
33 changes: 33 additions & 0 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,39 @@ This configuration option supports the duration suffixes: `ms`, `s` and `m`.
For example: `10ms`.
This option's default unit is `ms`, so `5` is interpreted as `5ms`.

[float]
[[config-span-stack-trace-min-duration]]
==== `span_stack_trace_min_duration`

[options="header"]
|============
| Environment variable name | Option name in `php.ini`
| `ELASTIC_APM_SPAN_STACK_TRACE_MIN_DURATION` | `elastic_apm.span_stack_trace_min_duration`
|============

[options="header"]
|============
| Default | Type
| `5ms` | Duration
|============

While it might be very helpful to have stack trace attached to a span,
collecting stack traces does have some overhead.
This configuration controls the minimum span duration at which stack traces are collected.
A higher value means lower overhead as stack trace collection is skipped for quick spans.

Set this config to:

- any positive value (e.g. `5ms`) - to limit stack trace collection to spans with duration
equal to or greater than the given value (e.g. 5 milliseconds)
- `0` (or `0` with any duration units e.g. `0ms`) - to collect stack traces
for spans with any duration
- any negative value (e.g. `-1ms`) - to disable stack trace collection for spans completely

This configuration option supports the duration suffixes: `ms`, `s` and `m`.
For example: `10ms`.
This option's default unit is `ms`, so `5` is interpreted as `5ms`.

[float]
[[config-stack-trace-limit]]
==== `stack_trace_limit`
Expand Down
6 changes: 6 additions & 0 deletions src/ElasticApm/Impl/Config/AllOptionsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ private static function buildDurationMetadataInMillisecondsWithMin(int $min, int
return new DurationOptionMetadata(floatval($min), /* max */ null, DurationUnits::MILLISECONDS, floatval($default));
}

private static function buildDurationMetadataInMillisecondsNoMin(int $default): DurationOptionMetadata
{
return new DurationOptionMetadata(/* min */ null, /* max */ null, DurationUnits::MILLISECONDS, floatval($default));
}

private static function buildDurationMetadataInMilliseconds(int $default): DurationOptionMetadata
{
return self::buildDurationMetadataInMillisecondsWithMin(/* min */ 0, $default);
Expand Down Expand Up @@ -107,6 +112,7 @@ public static function get(): array
OptionNames::SPAN_COMPRESSION_ENABLED => new BoolOptionMetadata(/* default */ true),
OptionNames::SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION => self::buildDurationMetadataInMilliseconds(/* default */ 50),
OptionNames::SPAN_COMPRESSION_SAME_KIND_MAX_DURATION => self::buildDurationMetadataInMilliseconds(/* default */ 0),
OptionNames::SPAN_STACK_TRACE_MIN_DURATION => self::buildDurationMetadataInMillisecondsNoMin(/* default */ OptionDefaultValues::SPAN_STACK_TRACE_MIN_DURATION),
OptionNames::STACK_TRACE_LIMIT => new IntOptionMetadata(/* min */ null, /* max */ null, /* default */ OptionDefaultValues::STACK_TRACE_LIMIT),
OptionNames::TRANSACTION_IGNORE_URLS => new NullableWildcardListOptionMetadata(),
OptionNames::TRANSACTION_MAX_SPANS => self::buildPositiveOrZeroIntMetadata(OptionDefaultValues::TRANSACTION_MAX_SPANS),
Expand Down
1 change: 1 addition & 0 deletions src/ElasticApm/Impl/Config/OptionDefaultValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class OptionDefaultValues
{
use StaticClassTrait;

public const SPAN_STACK_TRACE_MIN_DURATION = 5;
public const STACK_TRACE_LIMIT = 50;
public const TRANSACTION_MAX_SPANS = 500;
}
1 change: 1 addition & 0 deletions src/ElasticApm/Impl/Config/OptionNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class OptionNames
public const SPAN_COMPRESSION_ENABLED = 'span_compression_enabled';
public const SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION = 'span_compression_exact_match_max_duration';
public const SPAN_COMPRESSION_SAME_KIND_MAX_DURATION = 'span_compression_same_kind_max_duration';
public const SPAN_STACK_TRACE_MIN_DURATION = 'span_stack_trace_min_duration';
public const STACK_TRACE_LIMIT = 'stack_trace_limit';
public const TRANSACTION_IGNORE_URLS = 'transaction_ignore_urls';
public const TRANSACTION_MAX_SPANS = 'transaction_max_spans';
Expand Down
8 changes: 8 additions & 0 deletions src/ElasticApm/Impl/Config/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ final class Snapshot implements LoggableInterface
/** @var float */
private $spanCompressionSameKindMaxDuration;

/** @var float */
private $spanStackTraceMinDuration;

/** @var int */
private $stackTraceLimit;

Expand Down Expand Up @@ -371,6 +374,11 @@ public function spanCompressionSameKindMaxDuration(): float
return $this->spanCompressionSameKindMaxDuration;
}

public function spanStackTraceMinDuration(): float
{
return $this->spanStackTraceMinDuration;
}

public function stackTraceLimit(): int
{
return $this->stackTraceLimit;
Expand Down
12 changes: 9 additions & 3 deletions src/ElasticApm/Impl/InferredSpansBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ private function buildStackTrace(int $forFrameIndex, ?ClassicFormatStackTraceFra
private function sendFrameAsSpan(int $openFrameIndex, string $parentId, ?ClassicFormatStackTraceFrame $frameCopy, ?int $frameCopyIndex): void
{
$frame = $this->openFramesReverseOrder[$openFrameIndex];
$stackTrace = ($maxNumberOfFrames = StackTraceUtil::convertLimitConfigToMaxNumberOfFrames($this->transaction->getStackTraceLimitConfig())) === 0
? null
: $this->tracer->stackTraceUtil()->convertClassicToApmFormat($this->buildStackTrace($openFrameIndex, $frameCopy, $frameCopyIndex), $maxNumberOfFrames);
$stackTrace = null;
/** @var float $spanDurationInMilliseconds */
$spanDurationInMilliseconds = $frame->duration;
if (
$this->transaction->shouldCollectStackTraceForSpanDuration($spanDurationInMilliseconds)
&& (($maxNumberOfFrames = StackTraceUtil::convertLimitConfigToMaxNumberOfFrames($this->transaction->getStackTraceLimitConfig())) !== 0)
) {
$stackTrace = $this->tracer->stackTraceUtil()->convertClassicToApmFormat($this->buildStackTrace($openFrameIndex, $frameCopy, $frameCopyIndex), $maxNumberOfFrames);
}
$frame->prepareForSerialization($this->transaction, $parentId, $stackTrace);
$this->tracer->sendSpanToApmServer($frame);
}
Expand Down
4 changes: 3 additions & 1 deletion src/ElasticApm/Impl/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ public function endSpanEx(int $numberOfStackFramesToSkip, ?float $duration = nul
$this->onAboutToEnd->callCallbacks($this);

if ($this->shouldBeSentToApmServer()) {
$this->stackTrace = $this->containingTransaction->captureApmFormatStackTrace($numberOfStackFramesToSkip + 1);
if ($this->containingTransaction->shouldCollectStackTraceForSpanDuration($this->duration)) {
$this->stackTrace = $this->containingTransaction->captureApmFormatStackTrace($numberOfStackFramesToSkip + 1);
}
$this->prepareForSerialization();
$this->parentExecutionSegment->onChildSpanEnded($this);
}
Expand Down
37 changes: 37 additions & 0 deletions src/ElasticApm/Impl/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ final class Transaction extends ExecutionSegment implements TransactionInterface
/** @var ?int */
private $cachedStackTraceLimitConfig = null;

/** @var ?float */
private $cachedSpanStackTraceMinDurationConfig = null;

public function __construct(TransactionBuilder $builder)
{
$this->tracer = $builder->tracer;
Expand Down Expand Up @@ -594,6 +597,40 @@ public function getStackTraceLimitConfig(): int
return $this->cachedStackTraceLimitConfig;
}

private function getSpanStackTraceMinDurationConfig(): float
{
if ($this->cachedSpanStackTraceMinDurationConfig === null) {
$this->cachedSpanStackTraceMinDurationConfig = $this->getConfig()->spanStackTraceMinDuration();

/**
* span_stack_trace_min_duration
* 0 - collect stack traces for spans with any duration
* any positive value - it limits stack trace collection to spans with duration equal to or greater than
* any negative value - it disable stack trace collection for spans completely
*/
$msgPrefix = $this->cachedSpanStackTraceMinDurationConfig === 0.0
? 'Span stack trace collection is enabled for spans with any duration'
: ($this->cachedSpanStackTraceMinDurationConfig < 0
? 'Span stack trace collection is DISABLED for spans with any duration'
: 'Span stack trace collection is enabled for spans with duration >= ' . $this->cachedSpanStackTraceMinDurationConfig . ' ms');
($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log($msgPrefix . ' (set by configuration option `' . OptionNames::SPAN_STACK_TRACE_MIN_DURATION . '\')');
}

return $this->cachedSpanStackTraceMinDurationConfig;
}

public function shouldCollectStackTraceForSpanDuration(float $durationInMilliseconds): bool
{
/**
* span_stack_trace_min_duration
* 0 - collect stack traces for spans with any duration
* any positive value - it limits stack trace collection to spans with duration equal to or greater than
* any negative value - it disable stack trace collection for spans completely
*/
return (($stackTraceMinDuration = $this->getSpanStackTraceMinDurationConfig()) >= 0) && $durationInMilliseconds >= $stackTraceMinDuration;
}

/**
* @param int $numberOfStackFramesToSkip
*
Expand Down
7 changes: 7 additions & 0 deletions src/ext/ConfigManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, serviceVersion )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( boolValue, spanCompressionEnabled )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, spanCompressionExactMatchMaxDuration )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, spanCompressionSameKindMaxDuration )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, spanStackTraceMinDuration )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, stackTraceLimit )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, transactionIgnoreUrls )
ELASTIC_APM_DEFINE_FIELD_ACCESS_FUNCS( stringValue, transactionMaxSpans )
Expand Down Expand Up @@ -1146,6 +1147,12 @@ static void initOptionsMetadata( OptionMetadata* optsMeta )
ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION,
/* defaultValue: */ NULL );

ELASTIC_APM_INIT_METADATA(
buildStringOptionMetadata,
spanStackTraceMinDuration,
ELASTIC_APM_CFG_OPT_NAME_SPAN_STACK_TRACE_MIN_DURATION,
/* defaultValue: */ NULL );

ELASTIC_APM_INIT_METADATA(
buildStringOptionMetadata,
stackTraceLimit,
Expand Down
2 changes: 2 additions & 0 deletions src/ext/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ enum OptionId
optionId_spanCompressionEnabled,
optionId_spanCompressionExactMatchMaxDuration,
optionId_spanCompressionSameKindMaxDuration,
optionId_spanStackTraceMinDuration,
optionId_stackTraceLimit,
optionId_transactionIgnoreUrls,
optionId_transactionMaxSpans,
Expand Down Expand Up @@ -317,6 +318,7 @@ const ConfigSnapshot* getGlobalCurrentConfigSnapshot();
#define ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_ENABLED "span_compression_enabled"
#define ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION "span_compression_exact_match_max_duration"
#define ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION "span_compression_same_kind_max_duration"
#define ELASTIC_APM_CFG_OPT_NAME_SPAN_STACK_TRACE_MIN_DURATION "span_stack_trace_min_duration"
#define ELASTIC_APM_CFG_OPT_NAME_STACK_TRACE_LIMIT "stack_trace_limit"
#define ELASTIC_APM_CFG_OPT_NAME_TRANSACTION_IGNORE_URLS "transaction_ignore_urls"
#define ELASTIC_APM_CFG_OPT_NAME_TRANSACTION_MAX_SPANS "transaction_max_spans"
Expand Down
1 change: 1 addition & 0 deletions src/ext/ConfigSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct ConfigSnapshot
bool spanCompressionEnabled;
String spanCompressionExactMatchMaxDuration;
String spanCompressionSameKindMaxDuration;
String spanStackTraceMinDuration;
String stackTraceLimit;
String transactionIgnoreUrls;
String transactionMaxSpans;
Expand Down
1 change: 1 addition & 0 deletions src/ext/elastic_apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ PHP_INI_BEGIN()
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_ENABLED )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_SPAN_STACK_TRACE_MIN_DURATION )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_STACK_TRACE_LIMIT )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_TRANSACTION_IGNORE_URLS )
ELASTIC_APM_INI_ENTRY( ELASTIC_APM_CFG_OPT_NAME_TRANSACTION_MAX_SPANS )
Expand Down
1 change: 1 addition & 0 deletions tests/ElasticApmTests/ComponentTests/ConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private static function buildOptionNameToRawToValue(): array
=> $durationRawToParsedValues,
OptionNames::SPAN_COMPRESSION_SAME_KIND_MAX_DURATION
=> $durationRawToParsedValues,
OptionNames::SPAN_STACK_TRACE_MIN_DURATION => $durationRawToParsedValues,
OptionNames::STACK_TRACE_LIMIT => $intRawToParsedValues,
OptionNames::TRANSACTION_IGNORE_URLS => $wildcardListRawToParsedValues,
OptionNames::TRANSACTION_MAX_SPANS => $intRawToParsedValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ function (AppCodeHostParams $appCodeParams) use ($disableInstrumentationsOptVal)
if (!empty($disableInstrumentationsOptVal)) {
$appCodeParams->setAgentOption(OptionNames::DISABLE_INSTRUMENTATIONS, $disableInstrumentationsOptVal);
}
// Disable Span Compression feature to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
self::disableTimingDependentFeatures($appCodeParams);
}
);
$appCodeHost->sendRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ function (AppCodeHostParams $appCodeParams) use ($disableInstrumentationsOptVal)
if (!empty($disableInstrumentationsOptVal)) {
$appCodeParams->setAgentOption(OptionNames::DISABLE_INSTRUMENTATIONS, $disableInstrumentationsOptVal);
}
// Disable Span Compression feature to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
self::disableTimingDependentFeatures($appCodeParams);
}
);
$appCodeHost->sendRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace ElasticApmTests\ComponentTests;

use Elastic\Apm\Impl\Config\OptionNames;
use Elastic\Apm\Impl\Log\LoggableToString;
use Elastic\Apm\Impl\Util\TextUtil;
use ElasticApmTests\ComponentTests\Util\AppCodeHostParams;
Expand Down Expand Up @@ -55,7 +54,7 @@ protected function isSpanCompressionCompatible(): bool
*/
private static function sharedCodeForTestAllSpanCreatingApis(): array
{
/** @var array<string, mixed> */
/** @var array<string, mixed> $expectedData */
$expectedData = [];
$createSpanApis = SpanStackTraceTestSharedCode::allSpanCreatingApis(/* ref */ $expectedData);

Expand All @@ -74,19 +73,15 @@ public static function appCodeForTestAllSpanCreatingApis(): void
public function testAllSpanCreatingApis(): void
{
$sharedCodeResult = self::sharedCodeForTestAllSpanCreatingApis();
/** @var array<string, mixed> */
/** @var array<string, mixed> $expectedData */
$expectedData = $sharedCodeResult['expectedData'];
/**
* @var array<callable>
* @phpstan-var array<callable(): void>
*/
/** @var array<callable(): void> $createSpanApis */
$createSpanApis = $sharedCodeResult['createSpanApis'];

$testCaseHandle = $this->getTestCaseHandle();
$appCodeHost = $testCaseHandle->ensureMainAppCodeHost(
function (AppCodeHostParams $appCodeParams): void {
// Disable Span Compression feature to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
self::disableTimingDependentFeatures($appCodeParams);
}
);
$appCodeHost->sendRequest(AppCodeTarget::asRouted([__CLASS__, 'appCodeForTestAllSpanCreatingApis']));
Expand All @@ -102,8 +97,7 @@ public function testTopLevelTransactionBeginCurrentSpanApi(): void
$testCaseHandle = $this->getTestCaseHandle();
$appCodeHost = $testCaseHandle->ensureMainAppCodeHost(
function (AppCodeHostParams $appCodeParams): void {
// Disable Span Compression feature to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
self::disableTimingDependentFeatures($appCodeParams);
}
);
$appCodeHost->sendRequest(AppCodeTarget::asTopLevel(TopLevelCodeId::SPAN_BEGIN_END));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function testVariousConfigValues(MixedMap $testArgs): void

$appCodeHost = $testCaseHandle->ensureMainAppCodeHost(
function (AppCodeHostParams $appCodeParams) use ($testArgs): void {
// Enable span stack trace collection for span with any duration
$appCodeParams->setAgentOption(OptionNames::SPAN_STACK_TRACE_MIN_DURATION, 0);
if (($optVal = $testArgs->getNullableString(OptionNames::STACK_TRACE_LIMIT)) !== null) {
$appCodeParams->setAgentOption(OptionNames::STACK_TRACE_LIMIT, $optVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,12 @@ public static function getContextCustom(TransactionContextDto $ctx, string $key)
self::assertSame($receivedCrc, $calculatedCrc);
return unserialize(base64_decode($valueSerialized));
}

protected static function disableTimingDependentFeatures(AppCodeHostParams $appCodeParams): void
{
// Disable Span Compression feature to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
// Enable span stack trace collection for span with any duration
$appCodeParams->setAgentOption(OptionNames::SPAN_STACK_TRACE_MIN_DURATION, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ private function implTestOnMockSource(MixedMap $testArgs): void
function (AppCodeHostParams $appCodeParams) use ($testArgs): void {
$appCodeParams->setAgentOptionIfNotDefaultValue(OptionNames::AST_PROCESS_ENABLED, $testArgs->getBool(self::IS_AST_PROCESS_ENABLED_KEY));
$appCodeParams->setAgentOption(OptionNames::DISABLE_INSTRUMENTATIONS, $testArgs->getString(AutoInstrumentationUtilForTests::DISABLE_INSTRUMENTATIONS_KEY));
// Disable span compression to have all the expected spans individually
$appCodeParams->setAgentOption(OptionNames::SPAN_COMPRESSION_ENABLED, false);
self::disableTimingDependentFeatures($appCodeParams);
$appCodeParams->setAgentOption(OptionNames::NON_KEYWORD_STRING_MAX_LENGTH, self::NON_KEYWORD_STRING_MAX_LENGTH);
}
);
Expand Down
Loading

0 comments on commit f8c1d58

Please sign in to comment.