Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: open-telemetry/opentelemetry-php-contrib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a0dfbe3604955111feb80db0127846873ccd65ee
Choose a base ref
..
head repository: open-telemetry/opentelemetry-php-contrib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8cd17478f0d2659e6c0ea735a0cb638fd8b3098e
Choose a head ref
Showing with 48 additions and 0 deletions.
  1. +24 −0 src/Instrumentation/Symfony/src/SymfonyInstrumentation.php
  2. +24 −0 src/Instrumentation/Symfony/tests/Integration/SymfonyInstrumentationTest.php
24 changes: 24 additions & 0 deletions src/Instrumentation/Symfony/src/SymfonyInstrumentation.php
Original file line number Diff line number Diff line change
@@ -144,6 +144,30 @@ public static function register(): void
}
);

hook(
HttpKernel::class,
'handleThrowable',
pre: static function (
HttpKernel $kernel,
array $params,
string $class,
string $function,
?string $filename,
?int $lineno,
): array {
/** @var \Throwable $throwable */
$throwable = $params[0];

Span::getCurrent()
->recordException($throwable, [
TraceAttributes::EXCEPTION_ESCAPED => true,
])
->setStatus(StatusCode::STATUS_ERROR, $throwable->getMessage());

return $params;
},
);

/**
* Extract symfony event dispatcher known events and trace the controller
*
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
namespace OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration;

use OpenTelemetry\API\Trace\SpanKind;
use OpenTelemetry\API\Trace\StatusCode;
use OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator;
use OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator;
use OpenTelemetry\SDK\Trace\ImmutableSpan;
@@ -18,6 +19,7 @@
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;

@@ -40,6 +42,28 @@ public function test_http_kernel_handle_exception(): void
);
}

public function test_http_kernel_marks_root_as_erroneous(): void
{
$this->expectException(HttpException::class);
$kernel = $this->getHttpKernel(new EventDispatcher(), function () {
throw new HttpException(500, 'foo');
});
$this->assertCount(0, $this->storage);

$response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);

$this->assertCount(1, $this->storage);
$this->assertSame(500, $this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));

$this->assertSame(StatusCode::STATUS_ERROR, $this->storage[0]->getStatus()->getCode());

$this->assertArrayHasKey(
TraceResponsePropagator::TRACERESPONSE,
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);
}

public function test_http_kernel_handle_attributes(): void
{
$kernel = $this->getHttpKernel(new EventDispatcher());