Skip to content
Merged
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
80 changes: 41 additions & 39 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Flow\ETL\Row\Entry\XMLElementEntry;
use Flow\ETL\Row\Entry\XMLEntry;

use function array_keys;
use function is_array;
use function is_bool;
use function is_float;
Expand Down Expand Up @@ -60,8 +61,8 @@ private function normalizeArray(mixed $value): ?array

$normalized = [];

foreach ($value as $key => $nested) {
$normalized[$key] = $this->normalizeValue($nested);
foreach (array_keys($value) as $key) {
$normalized[$key] = $this->normalizeValue($value[$key]);
}

return $normalized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\Telemetry\Telemetry;
use Flow\Telemetry\Tracer\Span;
use Flow\Telemetry\Tracer\SpanKind;
use Flow\Telemetry\Tracer\SpanStatus;
use Flow\Telemetry\Tracer\Tracer;
use Override;
use SplObjectStorage;
Expand Down Expand Up @@ -94,12 +95,29 @@ public function leave(Profile $profile): void

// @mago-expect analysis:no-value(2),redundant-type-comparison(2),redundant-logical-operation(2)
if (is_array($spanData) && $spanData['tracer'] instanceof Tracer && $spanData['span'] instanceof Span) {
$spanData['span']->setStatus(SpanStatus::ok());
$spanData['tracer']->complete($spanData['span']);
}

unset($this->activeSpans[$profile]);
}

public function reset(): void
{
foreach ($this->activeSpans as $profile) {
// @mago-expect analysis:mixed-assignment
$spanData = $this->activeSpans[$profile];

if (is_array($spanData) && $spanData['tracer'] instanceof Tracer && $spanData['span'] instanceof Span) {
$spanData['span']->setStatus(SpanStatus::error('Twig rendering did not complete'));
$spanData['tracer']->complete($spanData['span']);
}
}

$this->activeSpans = new SplObjectStorage();
$this->excludedDepth = 0;
}

private function getSpanName(Profile $profile): string
{
if ($profile->isRoot()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Twig;

use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* Completes Twig spans left open by a render exception and resets the extension state.
*/
final readonly class TwigSpanCleanupSubscriber implements EventSubscriberInterface
{
public function __construct(
private TracingTwigExtension $extension,
) {}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::TERMINATE => ['onTerminate', -15000],
ConsoleEvents::TERMINATE => ['onConsoleTerminate', -15000],
];
}

public function onConsoleTerminate(ConsoleTerminateEvent $event): void
{
$this->extension->reset();
}

public function onTerminate(TerminateEvent $event): void
{
$this->extension->reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Twig\TracingTwigExtension;
use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Twig\TwigSpanCleanupSubscriber;
use Flow\Telemetry\Telemetry;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -20,5 +21,12 @@
'%flow.telemetry.twig.trace_macros%',
'%flow.telemetry.twig.exclude_templates%',
])
->tag('twig.extension');
->tag('twig.extension')->tag('kernel.reset', ['method' => 'reset']);

$services
->set('flow.telemetry.twig.span_cleanup_subscriber', TwigSpanCleanupSubscriber::class)
->args([
service('flow.telemetry.twig.extension'),
])
->tag('kernel.event_subscriber');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Flow\Bridge\Symfony\TelemetryBundle\Tests\Mother;

use Flow\Telemetry\Context\MemoryContextStorage;
use Flow\Telemetry\Logger\LoggerProvider;
use Flow\Telemetry\Meter\MeterProvider;
use Flow\Telemetry\Provider\Clock\SystemClock;
use Flow\Telemetry\Provider\Void\VoidLogProcessor;
use Flow\Telemetry\Provider\Void\VoidMetricProcessor;
use Flow\Telemetry\Resource;
use Flow\Telemetry\Telemetry;
use Flow\Telemetry\Tracer\SpanProcessor;
use Flow\Telemetry\Tracer\TracerProvider;

final class TelemetryMother
{
public static function withSpanProcessor(SpanProcessor $spanProcessor): Telemetry
{
$clock = new SystemClock();
$contextStorage = new MemoryContextStorage();

return new Telemetry(
Resource::create(['service.name' => 'test']),
new TracerProvider($spanProcessor, $clock, $contextStorage),
new MeterProvider(new VoidMetricProcessor(), $clock),
new LoggerProvider(new VoidLogProcessor(), $clock, $contextStorage),
);
}
}
Loading
Loading