Skip to content

The only tool you need to know what is happening and how to fix it.

progress

ddux40e665d01c10
diff --git a/backend/app/controllers/otelcontrollers/trace_converter.go b/backend/app/controllers/otelcontrollers/trace_converter.go
index fe9bb3b0..5f6b6838 100644
--- a/backend/app/controllers/otelcontrollers/trace_converter.go
+++ b/backend/app/controllers/otelcontrollers/trace_converter.go
@@ -169,6 +169,9 @@ func getHTTPEndpoint(attrs []*commonpb.KeyValue, fallback string) string {
method = getStringAttribute(attrs, "http.method")
}
route := getStringAttribute(attrs, "http.route")
+ if route != "" && !strings.HasPrefix(route, "/") {
+ route = ""
+ }
if route == "" {
route = getStringAttribute(attrs, "url.path")
}
diff --git a/docs/pages/client/symfony/index.mdx b/docs/pages/client/symfony/index.mdx
index de8f7485..87ec69da 100644
--- a/docs/pages/client/symfony/index.mdx
+++ b/docs/pages/client/symfony/index.mdx
@@ -43,13 +43,85 @@ OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME=my-symfony-app
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
-OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
+OTEL_EXPORTER_OTLP_PROTOCOL=http/json
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-traceway-instance.com/api/otel
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-project-token"
```
Your Traceway dashboard includes a **Connection** page with a ready-made config snippet and your project token. Go to **Connection** in the sidebar to grab it.
+> **Note:** Use `http/json` instead of `http/protobuf`. The protobuf encoder has known deprecation warnings on PHP 8.4+ that can cause noisy logs.
+
+## Step 4: Update Your Front Controller
+
+The `opentelemetry-auto-symfony` package has two issues that need a workaround in your `public/index.php`:
+
+1. **Endpoint names** — `http.route` is set to the internal Symfony route name (e.g., `app_user_show`) instead of the URL path template (`/users/{id}`)
+2. **500 errors not exported** — when Symfony renders an error page via a sub-request, the sub-request's OTel scope shadows the main request's scope, causing the main span to never be ended or exported
+
+Register this hook **after** the OTel autoloader to fix both issues:
+
+```php
+<?php
+// public/index.php
+
+use App\Kernel;
+
+require_once dirname(__DIR__) . '/vendor/autoload.php';
+
+\OpenTelemetry\SDK\SdkAutoloader::autoload();
+
+// Fixes for Symfony's OTel auto-instrumentation:
+// 1. Corrects http.route from internal route name to URL path template
+// 2. Cleans up sub-request scopes so 500 error spans are exported
+\OpenTelemetry\Instrumentation\hook(
+ \Symfony\Component\HttpKernel\HttpKernel::class,
+ 'handle',
+ post: static function (
+ \Symfony\Component\HttpKernel\HttpKernel $kernel,
+ array $params,
+ mixed $returnValue,
+ ?\Throwable $exception
+ ): void {
+ $request = ($params[0] instanceof \Symfony\Component\HttpFoundation\Request) ? $params[0] : null;
+ if (null === $request) return;
+
+ $type = $params[1] ?? \Symfony\Component\HttpKernel\HttpKernelInterface::MAIN_REQUEST;
+
+ // Sub-requests (e.g., error page rendering) push an extra OTel scope
+ // that shadows the main request. Clean up immediately.
+ if ($type === \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST) {
+ $scope = \OpenTelemetry\Context\Context::storage()->scope();
+ if (null !== $scope) {
+ $span = \OpenTelemetry\API\Trace\Span::fromContext($scope->context());
+ $scope->detach();
+ $span->end();
+ }
+ return;
+ }
+
+ // For main requests: fix route name to path template
+ $routeParams = $request->attributes->get('_route_params', []);
+ $path = $request->getPathInfo();
+ if (\is_array($routeParams)) {
+ foreach ($routeParams as $name => $value) {
+ if (\is_string($value) && '' !== $value) {
+ $path = str_replace($value, '{' . $name . '}', $path);
+ }
+ }
+ }
+
+ $request->attributes->set('_route', $path);
+ }
+);
+
+$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', (bool) ($_SERVER['APP_DEBUG'] ?? true));
+$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
+$response = $kernel->handle($request);
+$response->send();
+$kernel->terminate($request, $response);
+```
+
## What Gets Captured
Once configured, the OTel auto-instrumentation captures:
diff --git a/frontend/src/lib/utils/framework-code.ts b/frontend/src/lib/utils/framework-code.ts
index 127008c4..4c5bc0de 100644
--- a/frontend/src/lib/utils/framework-code.ts
+++ b/frontend/src/lib/utils/framework-code.ts
@@ -29,7 +29,7 @@ export function getInstallCommand(framework: Framework): string {
case 'remix':
return 'npm install @tracewayapp/remix';
case 'symfony':
- return 'composer require open-telemetry/sdk open-telemetry/exporter-otlp';
+ return 'composer require open-telemetry/sdk open-telemetry/exporter-otlp open-telemetry/opentelemetry-auto-symfony';
case 'cloudflare':
return '';
case 'opentelemetry':
@@ -207,14 +207,61 @@ export default withTraceway({
});`;
case 'symfony':
- return `# Add to your .env file
-OTEL_PHP_AUTOLOAD_ENABLED=true
-OTEL_SERVICE_NAME=my-symfony-app
-OTEL_TRACES_EXPORTER=otlp
-OTEL_METRICS_EXPORTER=otlp
-OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
-OTEL_EXPORTER_OTLP_ENDPOINT=${backendUrl}/api/otel
-OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ${token || 'YOUR_TOKEN'}"`;
+ return `<?php
+// public/index.php
+
+use App\\Kernel;
+
+require_once dirname(__DIR__) . '/vendor/autoload.php';
+
+\\OpenTelemetry\\SDK\\SdkAutoloader::autoload();
+
+// Fixes for Symfony's OTel auto-instrumentation:
+// 1. Corrects http.route from internal route name to URL path template
+// 2. Cleans up sub-request scopes so 500 error spans are exported
+\\OpenTelemetry\\Instrumentation\\hook(
+ \\Symfony\\Component\\HttpKernel\\HttpKernel::class,
+ 'handle',
+ post: static function (
+ \\Symfony\\Component\\HttpKernel\\HttpKernel $kernel,
+ array $params,
+ mixed $returnValue,
+ ?\\Throwable $exception
+ ): void {
+ $request = ($params[0] instanceof \\Symfony\\Component\\HttpFoundation\\Request) ? $params[0] : null;
+ if (null === $request) return;
+
+ $type = $params[1] ?? \\Symfony\\Component\\HttpKernel\\HttpKernelInterface::MAIN_REQUEST;
+
+ if ($type === \\Symfony\\Component\\HttpKernel\\HttpKernelInterface::SUB_REQUEST) {
+ $scope = \\OpenTelemetry\\Context\\Context::storage()->scope();
+ if (null !== $scope) {
+ $span = \\OpenTelemetry\\API\\Trace\\Span::fromContext($scope->context());
+ $scope->detach();
+ $span->end();
+ }
+ return;
+ }
+
+ $routeParams = $request->attributes->get('_route_params', []);
+ $path = $request->getPathInfo();
+ if (\\is_array($routeParams)) {
+ foreach ($routeParams as $name => $value) {
+ if (\\is_string($value) && '' !== $value) {
+ $path = str_replace($value, '{' . $name . '}', $path);
+ }
+ }
+ }
+
+ $request->attributes->set('_route', $path);
+ }
+);
+
+$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', (bool) ($_SERVER['APP_DEBUG'] ?? true));
+$request = \\Symfony\\Component\\HttpFoundation\\Request::createFromGlobals();
+$response = $kernel->handle($request);
+$response->send();
+$kernel->terminate($request, $response);`;
case 'cloudflare':
return '';
@@ -242,8 +289,21 @@ func main() {
export function getTestingRouteCode(framework?: Framework): string {
if (framework === 'symfony') {
- return `// In any controller action
-throw new \\RuntimeException("Test error from Traceway integration");`;
+ return `<?php
+// src/Controller/TestController.php
+namespace App\\Controller;
+
+use Symfony\\Component\\HttpFoundation\\Response;
+use Symfony\\Component\\Routing\\Attribute\\Route;
+
+class TestController
+{
+ #[Route('/testing', name: 'testing')]
+ public function index(): Response
+ {
+ throw new \\RuntimeException("Test error from Traceway integration");
+ }
+}`;
}
if (framework && isJsFramework(framework)) {
return `// Trigger a test error
@@ -256,8 +316,7 @@ throw new Error("Test error from Traceway integration");`;
export function getTestingRouteCode2(framework?: Framework): string {
if (framework === 'symfony') {
- return `// In any controller action
-throw new \\RuntimeException("Test error from Traceway integration");`;
+ return '';
}
if (framework && isJsFramework(framework)) {
switch (framework) {
@@ -323,8 +382,8 @@ export function getFrameworkLabel(framework: Framework): string {
return labels[framework] || framework;
}
-export function getCodeLanguage(framework: Framework): 'go' | 'javascript' | 'bash' {
- if (framework === 'symfony') return 'bash';
+export function getCodeLanguage(framework: Framework): 'go' | 'javascript' | 'bash' | 'php' {
+ if (framework === 'symfony') return 'php';
if (framework === 'opentelemetry') return 'go';
if (framework === 'cloudflare') return 'javascript';
return isJsFramework(framework) ? 'javascript' : 'go';
diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte
index 347e3117..f9ec09a3 100644
--- a/frontend/src/routes/+page.svelte
+++ b/frontend/src/routes/+page.svelte
@@ -36,6 +36,7 @@
import go from 'svelte-highlight/languages/go';
import javascript from 'svelte-highlight/languages/javascript';
import bash from 'svelte-highlight/languages/bash';
+ import php from 'svelte-highlight/languages/php';
import { themeState } from '$lib/state/theme.svelte';
import yaml from 'svelte-highlight/languages/yaml';
import 'svelte-highlight/styles/github-dark.css';
@@ -124,7 +125,7 @@
projectWithToken ? getCodeLanguage(projectWithToken.framework) : ('go' as const)
);
- const highlightLanguage = $derived(codeLanguage === 'javascript' ? javascript : codeLanguage === 'bash' ? bash : go);
+ const highlightLanguage = $derived(codeLanguage === 'javascript' ? javascript : codeLanguage === 'php' ? php : codeLanguage === 'bash' ? bash : go);
const testingRouteCode = $derived(getTestingRouteCode(projectWithToken?.framework));
const testingRouteCode2 = $derived(getTestingRouteCode2(projectWithToken?.framework));
@@ -742,6 +743,7 @@ service:
</div>
</div>
+ {#if testingRouteCode2}
<div class="flex justify-center p-2 italic">or</div>
<div class="relative">
@@ -764,6 +766,7 @@ service:
<Highlight language={highlightLanguage} code={testingRouteCode2} />
</div>
</div>
+ {/if}
</div>
</div>
{/if}
@@ -1025,6 +1028,12 @@ service:
:global(.light-code .hljs-built_in) {
color: #005cc5;
}
+ :global(.light-code .hljs-meta) {
+ color: #d73a49;
+ }
+ :global(.light-code .hljs-variable) {
+ color: #24292e;
+ }
/* Dark theme - ensure dark styles apply */
:global(.dark-code .hljs) {
@@ -1049,4 +1058,7 @@ service:
:global(.dark-code .hljs-built_in) {
color: #79c0ff;
}
+ :global(.dark-code .hljs-meta) {
+ color: #ff7b72;
+ }
</style>
diff --git a/frontend/src/routes/connection/+page.svelte b/frontend/src/routes/connection/+page.svelte
index cd236a9a..7e32b3c1 100644
--- a/frontend/src/routes/connection/+page.svelte
+++ b/frontend/src/routes/connection/+page.svelte
@@ -22,6 +22,7 @@
import go from 'svelte-highlight/languages/go';
import javascript from 'svelte-highlight/languages/javascript';
import bash from 'svelte-highlight/languages/bash';
+ import php from 'svelte-highlight/languages/php';
import yaml from 'svelte-highlight/languages/yaml';
import { themeState } from '$lib/state/theme.svelte';
import 'svelte-highlight/styles/github-dark.css';
@@ -106,7 +107,7 @@ service:
const highlightLanguage = $derived.by(() => {
if (!projectWithToken) return go;
- if (projectWithToken.framework === 'symfony') return bash;
+ if (projectWithToken.framework === 'symfony') return php;
if (isJsFramework(projectWithToken.framework)) return javascript;
return go;
});
@@ -550,6 +551,12 @@ service:
:global(.light-code .hljs-built_in) {
color: #005cc5;
}
+ :global(.light-code .hljs-meta) {
+ color: #d73a49;
+ }
+ :global(.light-code .hljs-variable) {
+ color: #24292e;
+ }
/* Dark theme - ensure dark styles apply */
:global(.dark-code .hljs) {
@@ -574,4 +581,7 @@ service:
:global(.dark-code .hljs-built_in) {
color: #79c0ff;
}
+ :global(.dark-code .hljs-meta) {
+ color: #ff7b72;
+ }
</style>
diff --git a/testing/devtesting-symfony/public/index.php b/testing/devtesting-symfony/public/index.php
index a172281b..b001a996 100644
--- a/testing/devtesting-symfony/public/index.php
+++ b/testing/devtesting-symfony/public/index.php
@@ -6,11 +6,62 @@ use Symfony\Component\Dotenv\Dotenv;
require_once dirname(__DIR__) . '/vendor/autoload.php';
(new Dotenv())->loadEnv(dirname(__DIR__) . '/.env');
-
\OpenTelemetry\SDK\SdkAutoloader::autoload();
+// Fix 1: Symfony's OTel auto-instrumentation sets http.route to the
+// internal route name (e.g., "app_test_testparam") instead of the
+// path template. This hook modifies _route on the request so Symfony's
+// own terminate hook reads the corrected path.
+//
+// Fix 2: When a 500 occurs, Symfony renders the error page via a
+// sub-request, which creates an extra OTel scope. The terminate hook
+// then picks up the sub-request scope instead of the main request's,
+// leaving the main span orphaned (never ended, never exported).
+// We clean up sub-request scopes immediately to prevent this.
+\OpenTelemetry\Instrumentation\hook(
+ \Symfony\Component\HttpKernel\HttpKernel::class,
+ 'handle',
+ post: static function (
+ \Symfony\Component\HttpKernel\HttpKernel $kernel,
+ array $params,
+ mixed $returnValue,
+ ?\Throwable $exception
+ ): void {
+ $request = ($params[0] instanceof \Symfony\Component\HttpFoundation\Request) ? $params[0] : null;
+ if (null === $request) return;
+
+ $type = $params[1] ?? \Symfony\Component\HttpKernel\HttpKernelInterface::MAIN_REQUEST;
+
+ // Sub-requests (e.g., error page rendering) push an extra scope
+ // that prevents the main request's span from being exported.
+ // Clean up sub-request scopes immediately.
+ if ($type === \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST) {
+ $scope = \OpenTelemetry\Context\Context::storage()->scope();
+ if (null !== $scope) {
+ $span = \OpenTelemetry\API\Trace\Span::fromContext($scope->context());
+ $scope->detach();
+ $span->end();
+ }
+ return;
+ }
+
+ // For main requests: fix route name from internal name to path template
+ $routeParams = $request->attributes->get('_route_params', []);
+ $path = $request->getPathInfo();
+ if (\is_array($routeParams)) {
+ foreach ($routeParams as $name => $value) {
+ if (\is_string($value) && '' !== $value) {
+ $path = str_replace($value, '{' . $name . '}', $path);
+ }
+ }
+ }
+
+ $request->attributes->set('_route', $path);
+ }
+);
+
$kernel = new Kernel('dev', true);
-$request = Symfony\Component\HttpFoundation\Request::createFromGlobals();
+$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);