Skip to content

Commit

Permalink
Fixes after rewiew and test of big hook file
Browse files Browse the repository at this point in the history
  • Loading branch information
gechetspr committed Dec 5, 2024
1 parent dffb37e commit 3480f4a
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
fail-fast: false
matrix:
php-version: [
'8.1',
'8.2'
'8.2',
'8.3'
]

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OpenTelemetry\SDK\Common\Attribute\AttributeValidatorInterface;
use OpenTelemetry\SemConv\TraceAttributes;
use Spryker\Service\Opentelemetry\Instrumentation\Sampler\CriticalSpanRatioSampler;
use Spryker\Service\Opentelemetry\Instrumentation\SprykerInstrumentationBootstrap;

class AttributesBuilder implements AttributesBuilderInterface
{
Expand Down Expand Up @@ -140,6 +141,9 @@ protected function getSafeAttributes(): array
'root.url',
TraceAttributes::URL_DOMAIN,
CriticalSpanRatioSampler::IS_CRITICAL_ATTRIBUTE,
CriticalSpanRatioSampler::NO_CRITICAL_ATTRIBUTE,
SprykerInstrumentationBootstrap::ATTRIBUTE_HTTP_METHOD,
SprykerInstrumentationBootstrap::ATTRIBUTE_IS_DETAILED_TRACE,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function __construct(
* @param \OpenTelemetry\SDK\Trace\SpanProcessorInterface $spanProcessor
* @param \OpenTelemetry\SDK\Resource\ResourceInfo $resource
* @param \OpenTelemetry\SDK\Common\Attribute\AttributesBuilderInterface $attributesBuilder
* @param array $links
* @param list<\OpenTelemetry\SDK\Trace\LinkInterface> $links
* @param int $totalRecordedLinks
* @param int $startEpochNanos
*
Expand Down Expand Up @@ -485,15 +485,15 @@ public function getAttributes(): AttributesInterface
}

/**
* @return \OpenTelemetry\SDK\Trace\EventInterface[]
* @return array<\OpenTelemetry\SDK\Trace\EventInterface>
*/
public function getEvents(): array
{
return $this->events;
}

/**
* @return \OpenTelemetry\SDK\Trace\LinkInterface[]
* @return array<\OpenTelemetry\SDK\Trace\LinkInterface>
*/
public function getLinks(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class SpanContext implements SpanContextInterface, SpanIdUpdateAwareSpanContextInterface
{
/**
* @var \OpenTelemetry\API\Trace\SpanContextInterface|null
*/
protected static ?SpanContextInterface $invalidContext = null;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function convert(iterable $spans): ExportTraceServiceRequest
return $pExportTraceServiceRequest;
}

/**
* @param \OpenTelemetry\SDK\Resource\ResourceInfo $resource
*
* @return \Opentelemetry\Proto\Trace\V1\ResourceSpans
*/
protected function convertResourceSpans(ResourceInfo $resource): ResourceSpans
{
$pResourceSpans = new ResourceSpans();
Expand All @@ -96,6 +101,11 @@ protected function convertResourceSpans(ResourceInfo $resource): ResourceSpans
return $pResourceSpans;
}

/**
* @param \OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface $instrumentationScope
*
* @return \Opentelemetry\Proto\Trace\V1\ScopeSpans
*/
protected function convertScopeSpans(InstrumentationScopeInterface $instrumentationScope): ScopeSpans
{
$pScopeSpans = new ScopeSpans();
Expand All @@ -111,6 +121,9 @@ protected function convertScopeSpans(InstrumentationScopeInterface $instrumentat

/**
* @param Resource_|Span|Event|Link|InstrumentationScope $pElement
* @param \OpenTelemetry\SDK\Common\Attribute\AttributesInterface $attributes
*
* @return void
*/
protected function setAttributes($pElement, AttributesInterface $attributes): void
{
Expand All @@ -123,6 +136,11 @@ protected function setAttributes($pElement, AttributesInterface $attributes): vo
$pElement->setDroppedAttributesCount($attributes->getDroppedAttributesCount());
}

/**
* @param int $kind
*
* @return int
*/
protected function convertSpanKind(int $kind): int
{
return match ($kind) {
Expand All @@ -135,6 +153,11 @@ protected function convertSpanKind(int $kind): int
};
}

/**
* @param string $status
*
* @return int
*/
protected function convertStatusCode(string $status): int
{
switch ($status) {
Expand All @@ -146,6 +169,11 @@ protected function convertStatusCode(string $status): int
return StatusCode::STATUS_CODE_UNSET;
}

/**
* @param \OpenTelemetry\SDK\Trace\SpanDataInterface $span
*
* @return \Opentelemetry\Proto\Trace\V1\Span
*/
protected function convertSpan(SpanDataInterface $span): Span
{
$pSpan = new Span();
Expand Down Expand Up @@ -190,6 +218,11 @@ protected function convertSpan(SpanDataInterface $span): Span
return $pSpan;
}

/**
* @param \OpenTelemetry\API\Trace\SpanContextInterface $spanContext
*
* @return int
*/
protected static function traceFlags(SpanContextInterface $spanContext): int
{
$flags = $spanContext->getTraceFlags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface SpanIdUpdateAwareSpanContextInterface
{
/**
* @param string $spanId
*
* @return void
*/
public function updateSpanId(string $spanId): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ protected function setScheduledDelayTime(int $scheduledDelayMillis): void
$this->scheduledDelayNanos = $scheduledDelayMillis * 1_000_000;
}

/**
* @param int $maxExportBatchSize
* @param int $maxQueueSize
*
* @return void
*/
protected function setMaxExportBatchSize(int $maxExportBatchSize, int $maxQueueSize): void
{
if ($maxExportBatchSize <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class SprykerInstrumentationBootstrap
*/
public const NAME = 'spryker';

/**
* @var string
*/
public const ATTRIBUTE_IS_DETAILED_TRACE = 'is_full_trace';

/**
* @var string
*/
public const ATTRIBUTE_HTTP_METHOD = 'method';

/**
* @var string
*/
Expand Down Expand Up @@ -97,6 +107,7 @@ public static function register(): void

ShutdownHandler::register($tracerProvider->shutdown(...));
ShutdownHandler::register([static::class, 'shutdownHandler']);
include_once APPLICATION_ROOT_DIR . '/src/Generated/OpenTelemetry/Hooks/BigHookHook.php';
}

/**
Expand Down Expand Up @@ -216,8 +227,8 @@ protected static function registerRootSpan(string $servicedName, Request $reques
->setParent($parent)
->setSpanKind(SpanKind::KIND_SERVER)
->setAttribute(TraceAttributes::URL_QUERY, $request->getQueryString())
->setAttribute('is_full_trace', !TraceSampleResult::shouldSkipTraceBody())
->setAttribute('method', $request->getMethod())
->setAttribute(static::ATTRIBUTE_IS_DETAILED_TRACE, TraceSampleResult::shouldSkipTraceBody() ? null : false)
->setAttribute(static::ATTRIBUTE_HTTP_METHOD, $request->getMethod())
->startSpan();

Context::storage()->attach($span->storeInContext($parent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static function getSamplerProbability(): float
{
$probability = getenv(static::OTEL_TRACES_SAMPLER_ARG) ?: 0.4;

return (float)0.4;
return (float)$probability;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OpentelemetryMonitoringExtensionPlugin extends AbstractPlugin implements M
{
/**
* Specification:
* - Adds error in to the current active span
* - Adds error to the current active span
*
* @api
*
Expand Down Expand Up @@ -58,7 +58,7 @@ public function setApplicationName(?string $application = null, ?string $store =

/**
* Specification:
* - Sets name for the root span. If no name provided, default name will be generated.
* - Sets name for the root span. If no name was provided, default name will be generated.
* - This will affect only root span as it will not update the current possible span name.
*
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function getOutputFilepathByModule(array $class): string
return sprintf(
static::OUTPUT_FILE_PATH_PLACEHOLDER_BY_MODULE,
$this->config->getOutputDir(),
$moduleNamePattern,
'BigHook',
);
}
}
14 changes: 7 additions & 7 deletions src/Spryker/Zed/Opentelemetry/OpentelemetryConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ public function getExcludedSpans(): array
'Discount-DecisionRuleOrSpecification::isSatisfiedBy',
'Discount-DiscountableItemFilter::filter',
'Discount-DiscountableItemTransformer::transformSplittableDiscountableItem',
// 'Discount-DiscountFacade::calculatePercentageDiscount',
// 'Discount-DiscountFacade::checkDiscountChanges',
// 'Discount-DiscountFacade::collectBySku',
// 'Discount-DiscountFacade::isCurrencyDecisionRuleSatisfiedBy',
// 'Discount-DiscountFacade::isDayOfTheWeekSatisfiedBy',
// 'Discount-DiscountFacade::isSubTotalSatisfiedBy',
// 'Discount-DiscountFacade::queryStringCompare',
'Discount-DiscountFacade::calculatePercentageDiscount',
'Discount-DiscountFacade::checkDiscountChanges',
'Discount-DiscountFacade::collectBySku',
'Discount-DiscountFacade::isCurrencyDecisionRuleSatisfiedBy',
'Discount-DiscountFacade::isDayOfTheWeekSatisfiedBy',
'Discount-DiscountFacade::isSubTotalSatisfiedBy',
'Discount-DiscountFacade::queryStringCompare',
'Discount-Distributor::distributeDiscountAmountToDiscountableItems',
'Discount-Equal::compare',
'Discount-Equal::getAcceptedTypes',
Expand Down

0 comments on commit 3480f4a

Please sign in to comment.