On Tracing Symfony, Twig and API Platform

Post

According to their Website, “Symfony is a set of PHP Components, a Web Application framework, a Philosophy, and a Community — all working together in harmony.”

The Symfony project provides a set of solid components for building applications in PHP and has shaped the landscape as many other projects either adapt their components or switch to using the framework directly.

A Symfony Web Framework application consists of a set of routes, which translate to controllers and / or actions. The view layer is usually facilitated by Twig, a Jinja2 inspired template language that is well supported by IDEs and code editors.

Completing the picture, bit by bit

At Instana, we’re committed to providing visibility into the full stack of your application and its logic. For a Symfony Web application, this means highlighting the routes, controllers and actions that are involved in processing a request.

The Instana PHP Tracer will automatically detect invocations of routes with the standard Symfony http-kernel and router components and then trace the execution of your controller action or invokable.

A list of Symfony controller spans in Instana Unbounded Analytics Symfony trace filtering in Instana

We collect data points like the current route, the controller, the action and the parameters that make up your URL.

This way, we can group route patterns to logical groups and infer that /news/article/123-french-fries-are-not-french-what and /news/article/124-one-bulletproof-method-to-catch-kangaroos actually belong to the framework route news_article_show with the pattern /news/article/{id}-{slug}.

A Symfony route invocation in Instana A Symfony route invocation in Instana

Twig

Twig is the canonical template language in Symfony projects. Twig will compile its templates and has rules for overriding templates. Sometimes it’s tricky to determine which templates were executed. With Instana, you can now see which templates your application executed (by name) and which file was resolved. This provides immediate visibility for your developers to see where the app spends its time.

Twig Spans in Instana Trace detail view containing twig spans enriched with valuable information

API Platform support

Instana now supports segmenting trace data by API Platform operations. API Platform provides a standards-based REST API for Symfony projects with low overhead and great flexibility.

The Instana PHP trace extension now sends information about the collection or item action your users are performing as well as which subject class (i.e. Doctrine entity) is involved. This enables you as a developer to find the hotspots on your API surface without overhead.

Call segmenting by API Platform resource Filtering Calls by API Platform resources and grouping provides great insights into the ratio of invocations

Bonus: End-User Monitoring

Adding the Instana End-User Monitoring JavaScript snippet to your twig templates and thus associating your backend and frontend activity with a user is easy.

<script>
  {# This will set the current route as page name in EUM #}
  {% set current_path = app.request.get('_route') %}

  ineum('page', '{{ current_path }}');

{% if is_granted('IS_AUTHENTICATED_FULLY') %}
  ineum('user', '{{ app.user.id }}');
{% endif %}
</script>

That’s it!

For more information on our End-User Monitoring JavaScript API, please visit Instana’s documentation.

Play with Instana’s APM Observability Sandbox

Start your FREE TRIAL today!

As the leading provider of Automatic Application Performance Monitoring (APM) solutions for microservices, Instana has developed the automatic monitoring and AI-based analysis DevOps needs to manage the performance of modern applications. Instana is the only APM solution that automatically discovers, maps and visualizes microservice applications without continuous additional engineering. Customers using Instana achieve operational excellence and deliver better software faster. Visit https://www.instana.com to learn more.