in agent/php/ElasticApm/Impl/Span.php [354:407]
private function canCompressFirstPair(Span $sibling): ?string
{
if (($loggerProxyTrace = $this->logger->ifTraceLevelEnabledNoLine(__FUNCTION__)) !== null) {
$localLogger = $this->logger->inherit()->addAllContext(
[
'this' => ['name' => $this->name, 'type' => $this->type, 'duration' => $this->duration],
'sibling' => ['name' => $sibling->name, 'type' => $sibling->type, 'duration' => $sibling->duration],
]
);
$loggerProxyTrace = $localLogger->ifTraceLevelEnabledNoLine(__FUNCTION__);
}
if (!$this->isSameKind($sibling)) {
$loggerProxyTrace && $loggerProxyTrace->log(__LINE__, 'Cannot compress because not even same kind');
return null;
}
$config = $this->containingTransaction->tracer()->getConfig();
$exactMatchMaxDuration = $config->spanCompressionExactMatchMaxDuration();
if ($this->name === $sibling->name) {
if ($this->duration <= $exactMatchMaxDuration && $sibling->duration <= $exactMatchMaxDuration) {
$loggerProxyTrace && $loggerProxyTrace->log(__LINE__, 'Can compress as ' . Constants::COMPRESSION_STRATEGY_EXACT_MATCH);
return Constants::COMPRESSION_STRATEGY_EXACT_MATCH;
} else {
/**
* Note that if the spans are exact match but duration threshold requirement is not satisfied we just stop compression sequence.
* In particular it means that the implementation should not proceed to try same kind strategy.
* Otherwise user would have to lower both span_compression_exact_match_max_duration and span_compression_same_kind_max_duration
* to prevent longer exact match spans from being compressed.
*
* @link https://github.com/elastic/apm/blob/e528576a5b0f3e95fe3c1da493466882fa7d8329/specs/agents/handling-huge-traces/tracing-spans-compress.md?plain=1#L200
*/
$loggerProxyTrace && $loggerProxyTrace->log(
__LINE__,
'Cannot compress as ' . Constants::COMPRESSION_STRATEGY_EXACT_MATCH . ' because one of the durations is above configured threshold',
['exactMatchMaxDuration (ms)' => $exactMatchMaxDuration]
);
return null;
}
}
$sameKindMaxDuration = $config->spanCompressionSameKindMaxDuration();
if ($this->duration <= $sameKindMaxDuration && $sibling->duration <= $sameKindMaxDuration) {
$loggerProxyTrace && $loggerProxyTrace->log(__LINE__, 'Can compress as ' . Constants::COMPRESSION_STRATEGY_SAME_KIND);
return Constants::COMPRESSION_STRATEGY_SAME_KIND;
} else {
$loggerProxyTrace && $loggerProxyTrace->log(
__LINE__,
'Cannot compress as ' . Constants::COMPRESSION_STRATEGY_SAME_KIND . ' because one of the durations is above configured threshold',
['sameKindMaxDuration (ms)' => $sameKindMaxDuration]
);
return null;
}
}