-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[opentelemetry-php-contrib] Symfony OtelSdkBundle integration error #1116
Comments
Can you please try changing the type-hint in the readme example to: public function __construct( \OpenTelemetry\SDK\Trace\TracerProviderInterface $provider) |
Thank you for your suggestion. I have forgot to mention that have Symfony 5.4.22
and saw next Traces in Jaeger UI:
but no Traces for my endpoints |
No problem. I can take a pretty good guess at what's wrong next. Change the <?php
namespace App\EventSubscriber;
use OpenTelemetry\API\Trace\SpanInterface;
use OpenTelemetry\Context\ScopeInterface;
use OpenTelemetry\SDK\Trace\TracerProvider;
use OpenTelemetry\SDK\Trace\TracerProviderInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class TracingKernelSubscriber implements EventSubscriberInterface
{
private TracerProvider $provider;
private ?SpanInterface $mainSpan = null;
private ?ScopeInterface $scope = null;
public function __construct(TracerProviderInterface $provider)
{
// store a reference to the TracerProvider in case we want to create
// more spans on different events (not covered in this example)
$this->provider = $provider;
}
public function onRequestEvent(RequestEvent $event)
{
// Create our main span and activate it
$this->mainSpan = $this->provider
->getTracer('io.opentelemetry.contrib.php')
->spanBuilder('main')
->startSpan();
$this->scope = $this->mainSpan->activate();
}
public function onTerminateEvent(TerminateEvent $event): void
{
// end our main span once the request has been processed and the kernel terminates.
$this->mainSpan->end();
$this->scope->detach();
}
public static function getSubscribedEvents(): array
{
// return the subscribed events, their methods and priorities
// use a very high integer for the Request priority and a
// very low negative integer for the Terminate priority, so the listener
// will be the first and last one to be called respectively.
return [
KernelEvents::REQUEST => [['onRequestEvent', 10000]],
KernelEvents::TERMINATE => [['onTerminateEvent', -10000]],
];
}
} Note that we keep track of the scope when activating the root span, and detach it when finished. |
Thanks a lot!. The error disappear, but still no traces for my endpoints (I have expected they should be added automatically when I request any endpoint). |
I'm not very familiar with either Symfony or the sdk bundle, but here's what I'd try. It looks like You might also like to try to use a console logger to simplify your setup, it's a good way to tell if spans are actually being generated. It's sounding like we need somebody who understands Symfony to test out this documentation. |
I did setup based on this documention:
https://github.com/open-telemetry/opentelemetry-php-contrib/blob/main/src/Symfony/src/OtelSdkBundle/README.md
and got an error:
App\EventListener\TracingKernelSubscriber::__construct(): Argument #1 ($provider) must be of type OpenTelemetry\SDK\Trace\TracerProvider, OpenTelemetry\Contrib\Symfony\OtelSdkBundle\Debug\TraceableTracerProvider given
The text was updated successfully, but these errors were encountered: