Blog Post

Apps on Azure Blog
3 MIN READ

Part I: OTEL sidecar extension on Azure App Service for Linux - Intro + PHP walkthrough

TulikaC's avatar
TulikaC
Icon for Microsoft rankMicrosoft
Nov 13, 2025

Sidecar extensions let you attach a companion container to your App Service for Linux app to add capabilities—without changing your core app or container. If you’re new to sidecars on App Service, start here: Sidecars in Azure App Service

OpenTelemetry (OTEL) is the vendor-neutral standard for collecting traces, metrics, and logs, with auto/manual instrumentation across popular languages and backends. See the official docs for concepts and quick starts. (OpenTelemetry)

In this post, we’ll use the new sidecar extension—OpenTelemetry - Azure Monitor and show end-to-end setup for a PHP code-based apps (the same extension will also work for other language stacks and container-based apps).

Walkthrough: add the OpenTelemetry – Azure Monitor sidecar to a PHP (code-based) app

This section shows the exact portal steps plus the code/config you need. Your PHP code is in sidecar-samples/otel-sidecar/php/php-blessed-app at main · Azure-Samples/sidecar-samples.

1) Create Application Insights and copy the Connection string

Create (or reuse) an Application Insights resource and copy the Connection string from the Overview blade.

2) Create the PHP Web App (Linux)

Create an Azure App Service (Linux) app and choose any supported PHP version (e.g., PHP 8.4).

 

3) Set environment variables on the main app

In Environment variables → Application settings, add:

OTEL_PHP_AUTOLOAD_ENABLED = true # (optional) SCM_DO_BUILD_DURING_DEPLOYMENT = true

When you add the sidecar extension, these environment variables would be set by default

APPLICATIONINSIGHTS_CONNECTION_STRING = <your-connection-string> OTEL_EXPORTER = azuremonitor OTEL_EXPORTER_OTLP_ENDPOINT = http://127.0.0.1:4318 OTEL_SERVICE_NAME = php-blessed-otel # pick a meaningful name

 

4) Get the app code

git clone <repo> cd php-blessed-app

 

5) PHP dependencies (already in composer.json)

The repo already includes the OpenTelemetry libraries and auto-instrumentation plugins:

{ "require": { "open-telemetry/sdk": "^1.7", "open-telemetry/exporter-otlp": "^1.3", "open-telemetry/opentelemetry-auto-slim": "^1.2", "open-telemetry/opentelemetry-auto-psr18": "^1.1", "monolog/monolog": "^3.0", "open-telemetry/opentelemetry-logger-monolog": "^1.0", "...": "..." }, "config": { "allow-plugins": { "open-telemetry/opentelemetry-auto-slim": true, "open-telemetry/opentelemetry-auto-psr18": true } } }

 

6) Minimal bootstrap in index.php

use OpenTelemetry\API\Globals; require __DIR__ . '/vendor/autoload.php';

 

7) Startup script (installs PECL extension if missing)

startup.sh included in the repo:

#!/bin/bash # Install OpenTelemetry extension if needed if ! php -m | grep -q opentelemetry; then echo "Installing OpenTelemetry extension..." pecl install opentelemetry echo "extension=opentelemetry.so" > /usr/local/etc/php/conf.d/99-opentelemetry.ini echo "OpenTelemetry extension installed successfully" fi # Start PHP-FPM echo "Starting PHP-FPM..." php-fpm

 

8) Deploy the app

Use your preferred method (GitHub Actions, ZIP deploy, local Git, etc.).

 

9) Add the sidecar extension on the Web App

Go to Deployment Center → Containers (new) → Add → Sidecar Extension, pick
Observability: OpenTelemetry – Azure Monitor, and paste your Connection string.

 

10) Map the autoload flag into the sidecar

Open the created sidecar container (Edit container) and map the autoload flag from the main app:

  • Name: OTEL_PHP_AUTOLOAD_ENABLED
  • Value: OTEL_PHP_AUTOLOAD_ENABLED (select from the drop-down to reference the app setting)

 

11) Set the Startup command for PHP

In Configuration (preview) → Stack settings, set:

cp /home/site/wwwroot/default /etc/nginx/sites-enabled/default && nginx -s reload && bash /home/site/wwwroot/startup.sh

 

12) Verify telemetry in Application Insights

After the app restarts, open your Application Insights resource and check Application map, Live metrics, or Search for spans with service.name = php-blessed-otel (or the value you set).

 

Part I — Conclusion

Sidecar extensions turn observability into an additive step - with just a few settings and a lightweight startup script. With OTEL wired for PHP, you now have portable traces, metrics, and logs you can query and dashboard.

Next: In Part II, we’ll connect the same app to Elastic APM using the OpenTelemetry – Elastic APM sidecar, with the few settings changes you need.

Updated Nov 13, 2025
Version 2.0
No CommentsBe the first to comment