On Tracing Symfony, Twig and API Platform

On Tracing Symfony, Twig and API Platform

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 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.

  {# 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 %}

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!

Instana, an IBM company, provides an Enterprise Observability Platform with automated application monitoring capabilities to businesses operating complex, modern, cloud-native applications no matter where they reside – on-premises or in public and private clouds, including mobile devices or IBM Z.

Control hybrid modern applications with Instana’s AI-powered discovery of deep contextual dependencies inside hybrid applications. Instana also gives visibility into development pipelines to help enable closed-loop DevOps automation.

This provides actionable feedback needed for clients as they to optimize application performance, enable innovation and mitigate risk, helping Dev+Ops add value and efficiency to software delivery pipelines while meeting their service and business level objectives.

For further information, please visit instana.com.