OpenObserve PHP Tracing Guide
Send distributed traces from PHP applications on Red Hat Enterprise Linux and Windows Server to OpenObserve through the OpenTelemetry Collector. No code changes are needed.
How to use this guide. Read Before you begin and fill in the table of values. Then follow Part A on Red Hat Enterprise Linux servers or Part B on Windows servers, one step at a time. Every value you must replace is shown in angle brackets, like
<SERVICE_NAME>, and the steps that contain one are marked with ✏️. Everything else can be copied as it is. Each part ends with a check that your traces arrived in OpenObserve.
Contents
- Before you begin
- Part A: Red Hat Enterprise Linux
- Part B: Windows Server
- Troubleshooting
- Tested versions
Before you begin
This guide sends distributed traces from a PHP application to OpenObserve. There are two parts to install: the opentelemetry PHP extension, and a few Composer packages. You don't need to change your code.
The application sends traces to an OpenTelemetry Collector on the same server. The Collector batches them, retries on network errors, and forwards them to OpenObserve. Only the Collector holds your OpenObserve credentials. PHP sends its traces at the end of every request, so a local Collector also keeps tracing from slowing down your users' requests.
Which part to follow
| Your server | Follow | Steps |
|---|---|---|
| Red Hat Enterprise Linux 8 or 9 (Apache or nginx with php-fpm) | Part A | A1 Install the Collector → A2 Instrument the app → A3 Verify |
| Windows Server 2016 or later (IIS with FastCGI) | Part B | B1 Install the Collector → B2 Instrument the app → B3 Verify |
Do all steps in order on each application server. Allow about 30 minutes per server.
Which instrumentation packages your app needs
Pick every row that matches your application. You will install the packages in A2.3 / B2.5. List them as <INSTRUMENTATION_PACKAGES>, separated by spaces.
| Your application uses | Package |
|---|---|
| Laravel | open-telemetry/opentelemetry-auto-laravel |
| Symfony | open-telemetry/opentelemetry-auto-symfony |
| Slim | open-telemetry/opentelemetry-auto-slim |
| WordPress | open-telemetry/opentelemetry-auto-wordpress |
| Any PSR-15 framework (Mezzio, etc.) | open-telemetry/opentelemetry-auto-psr15 |
| Guzzle HTTP client | open-telemetry/opentelemetry-auto-guzzle |
| Any PSR-18 HTTP client | open-telemetry/opentelemetry-auto-psr18 |
| PDO database access | open-telemetry/opentelemetry-auto-pdo |
| cURL extension | open-telemetry/opentelemetry-auto-curl |
Example for a Laravel app that uses Guzzle and PDO: open-telemetry/opentelemetry-auto-laravel open-telemetry/opentelemetry-auto-guzzle open-telemetry/opentelemetry-auto-pdo.
Values you need to provide
Throughout this guide, every value in angle brackets, like <SERVICE_NAME>, is a value you must replace with your own. Replace the angle brackets too. Copy everything else exactly as shown. Fill in this table before you start:
| Placeholder | What to enter | Where to find it | Example |
|---|---|---|---|
<OPENOBSERVE_URL> | Base URL of your OpenObserve, with no trailing / | OpenObserve Cloud: https://api.openobserve.ai. Self-hosted: the URL you use to open OpenObserve | https://o2.example.com |
<ORG_ID> | Your OpenObserve organization ID | OpenObserve → Data sources. It's part of the endpoint shown there | default |
<BASE64_CREDENTIALS> | Base64 of email:password-or-token for the ingestion user | OpenObserve → Data sources shows a ready-made Authorization: Basic ... value; use the part after Basic . To build it yourself, see the note below | dXNlcjpwYXNz |
<TRACE_STREAM> | Traces stream to write to | Your choice. It is created on first use | default |
<SERVICE_NAME> | Name this application will have in OpenObserve | Your choice. Lowercase, unique per application | shop-web |
<ENVIRONMENT> | Environment label | Your choice | production |
<SERVICE_VERSION> | Application version label | Your release version | 2.3.1 |
<APP_DIR> | The application folder that contains composer.json | Your server | RHEL: /var/www/shop · Windows: C:\inetpub\shop |
<INSTRUMENTATION_PACKAGES> | Packages from the table above | The table above | open-telemetry/opentelemetry-auto-laravel |
<FPM_POOL_FILE> | php-fpm pool file that serves the app (RHEL) | Usually /etc/php-fpm.d/www.conf | /etc/php-fpm.d/www.conf |
<PHP_DIR> | PHP install folder that contains php-cgi.exe (Windows) | IIS Manager → FastCGI Settings | C:\php |
<APP_URL> | A URL of the application for a test request | Your application | http://localhost/ |
<O2_USER_EMAIL> / <O2_PASSWORD_OR_TOKEN> | An OpenObserve login, used only for the optional API check in step A3/B3 | OpenObserve | ingest@example.com |
To build <BASE64_CREDENTIALS> yourself:
- RHEL:
echo -n '<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>' | base64 - Windows PowerShell:
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>'))
Use a dedicated OpenObserve user or service account for ingestion, not a personal administrator login.
Prerequisites
- Administrator rights on the server:
sudoon RHEL, an elevated PowerShell on Windows. - PHP 8.0 or later, and Composer. The application must use Composer's autoloader (
vendor/autoload.php). - Outbound HTTPS (port 443) from the server to
<OPENOBSERVE_URL>. Self-hosted OpenObserve may use port 5080 instead. - Internet access to
github.com,pecl.php.net/downloads.php.netandpackagist.org. Without it, use your internal mirrors. - A short restart window for php-fpm or IIS.
Extension and SDK, or eBPF?
On Red Hat Enterprise Linux, you can also trace PHP applications with eBPF instead of the extension and Composer packages in this guide. One OBI service per server traces Apache httpd or nginx and the php-fpm workers from the kernel, with no change to the application. See the companion OpenObserve eBPF Tracing Guide.
| Use | When |
|---|---|
| Extension and SDK (this guide) | You need complete traces, framework detail (Laravel/Symfony routes, PDO statements, exceptions, custom spans), the server runs Windows or IIS, or you can't run a root-level service |
| eBPF | You want broad coverage quickly, can't add Composer packages or a PHP extension, or also run services with no agent |
In testing, eBPF traced the PHP sample application on httpd + php-fpm, but linked it only partially. The outgoing call and the downstream request were linked; the incoming request was a separate trace, because the request is handed from httpd to a php-fpm worker. php-fpm spans were named php-fpm. For complete PHP traces, use this guide.
Part A: Red Hat Enterprise Linux
Run every command as a user with sudo rights on the application server. Commands without placeholders can be copied as they are.
Step A1. Install and configure the OpenTelemetry Collector
A1.1 Download the Collector package and verify its checksum. On ARM servers, set ARCH=arm64.
OTEL_VERSION=0.166.0
ARCH=amd64
BASE=https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}
cd /tmp
curl -LO ${BASE}/otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm
curl -LO ${BASE}/otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm.sha256
echo "$(cat otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm.sha256) otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm" | sha256sum -c -Expected output: otelcol-contrib_0.166.0_linux_amd64.rpm: OK
A1.2 Install the package. This creates the otelcol-contrib systemd service and the /etc/otelcol-contrib/ folder.
sudo dnf install -y ./otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpmA1.3 Write the Collector configuration. This file contains no values of yours; they come from the next step. Copy the whole block as it is.
sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.orig
sudo tee /etc/otelcol-contrib/config.yaml >/dev/null <<'EOF'
extensions:
health_check:
endpoint: 127.0.0.1:13133
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:4317
http:
endpoint: 127.0.0.1:4318
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 80
spike_limit_percentage: 25
resource_detection:
detectors: [env, system]
system:
hostname_sources: [os]
batch:
send_batch_size: 1024
timeout: 5s
exporters:
otlp_http/openobserve:
endpoint: ${env:O2_OTLP_ENDPOINT}
headers:
Authorization: "Basic ${env:O2_AUTH_TOKEN}"
stream-name: ${env:O2_TRACE_STREAM}
compression: gzip
retry_on_failure:
enabled: true
sending_queue:
enabled: true
queue_size: 5000
service:
extensions: [health_check]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, resource_detection, batch]
exporters: [otlp_http/openobserve]
EOFThe Collector listens only on 127.0.0.1, so only applications on this server can send to it. To accept traces from other servers too, change the two receiver endpoints to 0.0.0.0:4317 and 0.0.0.0:4318, and open those ports in the firewall (A1.6).
A1.4 Enter your OpenObserve values. ✏️ Replace the three placeholders, then run:
sudo tee -a /etc/otelcol-contrib/otelcol-contrib.conf >/dev/null <<'EOF'
O2_OTLP_ENDPOINT=<OPENOBSERVE_URL>/api/<ORG_ID>
O2_AUTH_TOKEN=<BASE64_CREDENTIALS>
O2_TRACE_STREAM=<TRACE_STREAM>
EOF
sudo chown root:otelcol-contrib /etc/otelcol-contrib/otelcol-contrib.conf
sudo chmod 640 /etc/otelcol-contrib/otelcol-contrib.confFilled in, the three lines look like this:
O2_OTLP_ENDPOINT=https://o2.example.com/api/default
O2_AUTH_TOKEN=dXNlcjpwYXNz
O2_TRACE_STREAM=defaultDon't add /v1/traces to the endpoint; the Collector adds it. Don't add Basic to the token; the configuration adds it.
A1.5 Check the configuration, then start the Collector:
sudo bash -c 'set -a; . /etc/otelcol-contrib/otelcol-contrib.conf; otelcol-contrib validate --config=/etc/otelcol-contrib/config.yaml' && echo CONFIG OK
sudo systemctl enable otelcol-contrib
sudo systemctl restart otelcol-contrib
sudo systemctl status otelcol-contrib --no-pager
curl -s http://127.0.0.1:13133Expected: CONFIG OK, status active (running), and {"status":"Server available",...}.
A1.6 (Only if other servers send to this Collector) Open the firewall:
sudo firewall-cmd --permanent --add-port=4317/tcp --add-port=4318/tcp
sudo firewall-cmd --reloadA1.7 Send a test trace from the Collector to OpenObserve. This confirms the connection and credentials before you touch the application.
NOW=$(date +%s); TID=$(openssl rand -hex 16); SID=$(openssl rand -hex 8)
curl -s -w ' HTTP %{http_code}\n' -X POST http://127.0.0.1:4318/v1/traces -H 'Content-Type: application/json' -d '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"collector-smoke-test"}}]},"scopeSpans":[{"spans":[{"traceId":"'$TID'","spanId":"'$SID'","name":"smoke-test","kind":1,"startTimeUnixNano":"'${NOW}000000000'","endTimeUnixNano":"'${NOW}500000000'"}]}]}]}'Expected: {"partialSuccess":{}} HTTP 200. Within about 10 seconds, a service named collector-smoke-test appears under Traces in OpenObserve. If it doesn't, check sudo journalctl -u otelcol-contrib -n 50 --no-pager and see Troubleshooting.
Step A2. Instrument the PHP application
A2.1 Install the build tools for the PHP extension:
sudo dnf install -y php-devel php-pear gcc makeIf PHP comes from another repository (Remi, Software Collections), install that repository's -devel and -pear packages for the same PHP version instead.
A2.2 Build and enable the opentelemetry extension:
sudo pecl install opentelemetry-1.5.0
echo 'extension=opentelemetry.so' | sudo tee /etc/php.d/40-opentelemetry.ini
php --ri opentelemetry | head -5Expected output includes opentelemetry hooks => enabled and extension version => 1.5.0.
A2.3 Add the OpenTelemetry Composer packages to the application. ✏️ Replace <APP_DIR> and <INSTRUMENTATION_PACKAGES>. Run this as the user who owns the application files, not as root.
cd <APP_DIR>
composer config allow-plugins.php-http/discovery true
composer config allow-plugins.tbachert/spi true
composer require open-telemetry/sdk open-telemetry/exporter-otlp <INSTRUMENTATION_PACKAGES>If Composer reports that no PSR-18 HTTP client is installed, also run composer require php-http/guzzle7-adapter. Commit the updated composer.json and composer.lock, so that your normal deployment installs the same packages.
A2.4 Add the tracing settings to php-fpm. php-fpm doesn't pass environment variables from systemd or the shell to PHP, so the settings go in the pool file. ✏️ Replace <FPM_POOL_FILE>, <SERVICE_NAME>, <ENVIRONMENT> and <SERVICE_VERSION>:
sudo cp <FPM_POOL_FILE> <FPM_POOL_FILE>.orig
sudo tee -a <FPM_POOL_FILE> >/dev/null <<'EOF'
; ---- OpenTelemetry tracing ----
env[OTEL_PHP_AUTOLOAD_ENABLED] = "true"
env[OTEL_SERVICE_NAME] = "<SERVICE_NAME>"
env[OTEL_RESOURCE_ATTRIBUTES] = "deployment.environment.name=<ENVIRONMENT>,service.version=<SERVICE_VERSION>"
env[OTEL_TRACES_EXPORTER] = "otlp"
env[OTEL_METRICS_EXPORTER] = "none"
env[OTEL_LOGS_EXPORTER] = "none"
env[OTEL_EXPORTER_OTLP_PROTOCOL] = "http/protobuf"
env[OTEL_EXPORTER_OTLP_ENDPOINT] = "http://127.0.0.1:4318"
env[OTEL_PROPAGATORS] = "tracecontext,baggage"
EOFKeep the double quotes around every value. Without them, php-fpm fails to start, because OTEL_RESOURCE_ATTRIBUTES contains =.
A2.5 Check the php-fpm configuration and restart:
sudo php-fpm -t
sudo systemctl restart php-fpmExpected: configuration file /etc/php-fpm.conf test is successful. If the test fails, restore the backup with sudo cp <FPM_POOL_FILE>.orig <FPM_POOL_FILE> and check the quotes.
A2.6 Send a request. ✏️ Replace <APP_URL>: curl -s <APP_URL> > /dev/null
CLI scripts, cron jobs and queue workers don't run through php-fpm. To trace them too, export the same OTEL_* values (without env[...]) in their own environment, for example in the systemd unit of a queue worker.
Step A3. Verify traces in OpenObserve
- Send a few requests to the application, or wait for normal traffic.
- In OpenObserve, open Traces, select the
<TRACE_STREAM>stream and the Last 15 minutes time range. - Filter on
service_name = '<SERVICE_NAME>'. Your requests appear within about 10 seconds. - Open a trace. It shows the incoming request (for example
GET /checkout) with child spans for the framework's controller, database queries and outgoing HTTP calls. Calls to other instrumented services appear in the same trace.
Optional check from the command line. ✏️ Replace the placeholders:
END=$(($(date +%s)*1000000)); START=$((END-3600*1000000))
cat > /tmp/q.json <<EOF
{"query":{"sql":"SELECT service_name, count(*) AS spans FROM \"<TRACE_STREAM>\" GROUP BY service_name","start_time":$START,"end_time":$END}}
EOF
curl -s -u '<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>' -H 'Content-Type: application/json' \
"<OPENOBSERVE_URL>/api/<ORG_ID>/_search?type=traces" -d @/tmp/q.jsonExpected: a hits list that includes <SERVICE_NAME> with a span count above 0.
Repeat Part A on every RHEL application server. Use a different <SERVICE_NAME> for each application, but the same name for every server that runs the same application.
Part B: Windows Server
Run every command in PowerShell as Administrator on the application server. Commands without placeholders can be copied as they are.
Step B1. Install and configure the OpenTelemetry Collector
B1.1 Download the Collector installer and verify its checksum:
$v = '0.166.0'
$base = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v$v"
$msi = "otelcol-contrib_${v}_windows_x64.msi"
New-Item -ItemType Directory -Force C:\temp | Out-Null; Set-Location C:\temp
Invoke-WebRequest "$base/$msi" -OutFile $msi
Invoke-WebRequest "$base/$msi.sha256" -OutFile "$msi.sha256"
$expected = (Get-Content "$msi.sha256" -Raw).Trim().Split(' ')[0]
if ((Get-FileHash $msi -Algorithm SHA256).Hash -ne $expected.ToUpper()) { throw 'Checksum mismatch - do not install' } else { 'Checksum OK' }B1.2 Install the Collector. This creates the Windows service otelcol-contrib (automatic start) and the folder C:\Program Files\OpenTelemetry Collector\.
Start-Process msiexec.exe -Wait -ArgumentList "/i `"C:\temp\$msi`" /qn /l*v C:\temp\otelcol-install.log"
Get-Service otelcol-contribB1.3 Write the Collector configuration. This file contains no values of yours; they come from the next step. Copy the whole block as it is.
$dir = 'C:\Program Files\OpenTelemetry Collector'
Copy-Item "$dir\config.yaml" "$dir\config.yaml.orig" -Force
@'
extensions:
health_check:
endpoint: 127.0.0.1:13133
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:4317
http:
endpoint: 127.0.0.1:4318
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 80
spike_limit_percentage: 25
resource_detection:
detectors: [env, system]
system:
hostname_sources: [os]
batch:
send_batch_size: 1024
timeout: 5s
exporters:
otlp_http/openobserve:
endpoint: ${env:O2_OTLP_ENDPOINT}
headers:
Authorization: "Basic ${env:O2_AUTH_TOKEN}"
stream-name: ${env:O2_TRACE_STREAM}
compression: gzip
retry_on_failure:
enabled: true
sending_queue:
enabled: true
queue_size: 5000
service:
extensions: [health_check]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, resource_detection, batch]
exporters: [otlp_http/openobserve]
'@ | Set-Content -Path "$dir\config.yaml" -Encoding asciiTo accept traces from other servers too, change the two receiver endpoints to 0.0.0.0:4317 and 0.0.0.0:4318, and open the firewall (B1.6).
B1.4 Enter your OpenObserve values. ✏️ Replace the three placeholders, then run. The values are stored on the Collector service only; other programs can't see them.
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\otelcol-contrib' -Name Environment -Type MultiString -Value @(
'O2_OTLP_ENDPOINT=<OPENOBSERVE_URL>/api/<ORG_ID>',
'O2_AUTH_TOKEN=<BASE64_CREDENTIALS>',
'O2_TRACE_STREAM=<TRACE_STREAM>'
)Filled in, the first line looks like 'O2_OTLP_ENDPOINT=https://o2.example.com/api/default',. Don't add /v1/traces or Basic .
B1.5 Check the configuration, then restart the Collector. ✏️ Use the same three values as in B1.4:
$env:O2_OTLP_ENDPOINT = '<OPENOBSERVE_URL>/api/<ORG_ID>'; $env:O2_AUTH_TOKEN = '<BASE64_CREDENTIALS>'; $env:O2_TRACE_STREAM = '<TRACE_STREAM>'
& 'C:\Program Files\OpenTelemetry Collector\otelcol-contrib.exe' validate --config 'C:\Program Files\OpenTelemetry Collector\config.yaml'; if ($LASTEXITCODE -eq 0) { 'CONFIG OK' }
Restart-Service otelcol-contrib
Get-Service otelcol-contrib
(Invoke-WebRequest http://127.0.0.1:13133 -UseBasicParsing).ContentExpected: CONFIG OK, status Running, and {"status":"Server available",...}.
B1.6 (Only if other servers send to this Collector) Open the firewall:
New-NetFirewallRule -DisplayName 'OpenTelemetry Collector OTLP' -Direction Inbound -Protocol TCP -LocalPort 4317,4318 -Action AllowB1.7 Send a test trace from the Collector to OpenObserve:
$now = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
$tid = -join ((1..32) | % { '{0:x}' -f (Get-Random -Max 16) }); $sid = -join ((1..16) | % { '{0:x}' -f (Get-Random -Max 16) })
$body = '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"collector-smoke-test"}}]},"scopeSpans":[{"spans":[{"traceId":"' + $tid + '","spanId":"' + $sid + '","name":"smoke-test","kind":1,"startTimeUnixNano":"' + ($now*1000000) + '","endTimeUnixNano":"' + (($now+500)*1000000) + '"}]}]}]}'
$r = Invoke-WebRequest -Uri http://127.0.0.1:4318/v1/traces -Method Post -ContentType 'application/json' -Body $body -UseBasicParsing
"HTTP $($r.StatusCode) $($r.Content)"Expected: HTTP 200 {"partialSuccess":{}}. Within about 10 seconds, the service collector-smoke-test appears under Traces in OpenObserve. Collector messages are in Event Viewer → Windows Logs → Application; filter on source otelcol-contrib.
Step B2. Instrument the PHP application
B2.1 Make sure the Visual C++ runtime is installed. PHP for Windows needs it. Running the installer again is harmless.
Invoke-WebRequest 'https://aka.ms/vs/17/release/vc_redist.x64.exe' -OutFile C:\temp\vc_redist.x64.exe
Start-Process C:\temp\vc_redist.x64.exe -Wait -ArgumentList '/install','/quiet','/norestart'B2.2 Download the opentelemetry extension that matches your PHP build. ✏️ Replace <PHP_DIR>. The commands read your PHP version and build type, then pick the matching file.
$php = '<PHP_DIR>'
$full = & "$php\php.exe" -r 'echo PHP_VERSION;'
$phpv = ($full -split '\.')[0..1] -join '.'
$ts = if ((& "$php\php.exe" -r 'echo PHP_ZTS;') -eq '1') { 'ts' } else { 'nts' }
$vs = if ([version]$phpv -ge [version]'8.4') { 'vs17' } else { 'vs16' }
$zip = "php_opentelemetry-1.5.0-$phpv-$ts-$vs-x64.zip"
"PHP $full $ts -> $zip"
Invoke-WebRequest "https://downloads.php.net/~windows/pecl/releases/opentelemetry/1.5.0/$zip" -OutFile "C:\temp\$zip"
Expand-Archive "C:\temp\$zip" C:\temp\php_otel -Force
Copy-Item C:\temp\php_otel\php_opentelemetry.dll "$php\ext\" -ForceIIS with FastCGI uses the NTS build of PHP; the output line should show nts.
B2.3 Enable the extension in php.ini. Run this in the same window as B2.2:
$ini = (& "$php\php.exe" --ini | Select-String 'Loaded Configuration File').ToString().Split(':',2)[1].Trim()
$ini
Copy-Item $ini "$ini.orig" -Force
Add-Content $ini "`r`n; ---- OpenTelemetry tracing ----`r`nextension=opentelemetry"
& "$php\php.exe" --ri opentelemetry | Select-Object -First 5
& "$php\php.exe" -m | Select-String -Pattern '^(curl|mbstring|openssl|fileinfo|zip)$'Expected: opentelemetry hooks => enabled, extension version => 1.5.0, and the five extensions curl, mbstring, openssl, fileinfo, zip. If any of those five is missing, remove the ; in front of its extension= line in php.ini.
B2.4 Add the OpenTelemetry Composer packages to the application. ✏️ Replace <APP_DIR> and <INSTRUMENTATION_PACKAGES>:
Set-Location '<APP_DIR>'
composer config allow-plugins.php-http/discovery true
composer config allow-plugins.tbachert/spi true
composer require open-telemetry/sdk open-telemetry/exporter-otlp <INSTRUMENTATION_PACKAGES>If Composer reports that no PSR-18 HTTP client is installed, also run composer require php-http/guzzle7-adapter. Commit the updated composer.json and composer.lock.
B2.5 Add the tracing settings to IIS FastCGI. IIS passes environment variables to PHP only through the FastCGI settings. ✏️ Replace <PHP_DIR>, <SERVICE_NAME>, <ENVIRONMENT> and <SERVICE_VERSION>:
$appcmd = "$env:windir\System32\inetsrv\appcmd.exe"
$cgi = '<PHP_DIR>\php-cgi.exe'
$vars = [ordered]@{
OTEL_PHP_AUTOLOAD_ENABLED = 'true'
OTEL_SERVICE_NAME = '<SERVICE_NAME>'
OTEL_RESOURCE_ATTRIBUTES = 'deployment.environment.name=<ENVIRONMENT>,service.version=<SERVICE_VERSION>'
OTEL_TRACES_EXPORTER = 'otlp'
OTEL_METRICS_EXPORTER = 'none'
OTEL_LOGS_EXPORTER = 'none'
OTEL_EXPORTER_OTLP_PROTOCOL = 'http/protobuf'
OTEL_EXPORTER_OTLP_ENDPOINT = 'http://127.0.0.1:4318'
OTEL_PROPAGATORS = 'tracecontext,baggage'
}
foreach ($k in $vars.Keys) {
& $appcmd set config -section:system.webServer/fastCgi "/-[fullPath='$cgi'].environmentVariables.[name='$k']" 2>$null | Out-Null
& $appcmd set config -section:system.webServer/fastCgi "/+[fullPath='$cgi'].environmentVariables.[name='$k',value='$($vars[$k])']"
}
& $appcmd list config -section:system.webServer/fastCgiThe last command shows the FastCGI settings, with the nine OTEL_* variables under php-cgi.exe. The command first removes any earlier value, so you can safely run it again. These settings apply to every IIS site that uses this php-cgi.exe.
B2.6 Restart IIS and send a request. ✏️ Replace <APP_URL>:
iisreset
Invoke-WebRequest '<APP_URL>' -UseBasicParsing | Out-NullRestarting IIS briefly interrupts all sites on the server; do it in a maintenance window. Recycling only the site's application pool is not enough, because PHP extensions and FastCGI settings are loaded when IIS starts the FastCGI process.
Step B3. Verify traces in OpenObserve
- Send a few requests to the application, or wait for normal traffic.
- In OpenObserve, open Traces, select the
<TRACE_STREAM>stream and the Last 15 minutes time range. - Filter on
service_name = '<SERVICE_NAME>'. Your requests appear within about 10 seconds. - Open a trace. It shows the incoming request with child spans for the framework's controller, database queries and outgoing HTTP calls.
Optional check from PowerShell. ✏️ Replace the placeholders:
$end = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() * 1000; $start = $end - 3600000000
$body = @{ query = @{ sql = 'SELECT service_name, count(*) AS spans FROM "<TRACE_STREAM>" GROUP BY service_name'; start_time = $start; end_time = $end } } | ConvertTo-Json
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>'))
(Invoke-RestMethod -Method Post -Uri '<OPENOBSERVE_URL>/api/<ORG_ID>/_search?type=traces' -Headers @{ Authorization = "Basic $auth" } -ContentType 'application/json' -Body $body).hitsExpected: a row for <SERVICE_NAME> with a span count above 0.
Repeat Part B on every Windows application server.
Troubleshooting
Start with the Collector test trace (A1.7 / B1.7). If collector-smoke-test reaches OpenObserve, the connection to OpenObserve is fine, and the problem is between PHP and the Collector. If it doesn't arrive, fix the Collector first.
Where to look:
- Collector log. RHEL:
sudo journalctl -u otelcol-contrib -n 100 --no-pager. Windows: Event Viewer → Windows Logs → Application, sourceotelcol-contrib. - PHP error log. RHEL:
/var/log/php-fpm/www-error.log. Windows: theerror_logpath inphp.ini. OpenTelemetry messages start withOpenTelemetry.
| Symptom | Cause | Fix |
|---|---|---|
php-fpm doesn't start: syntax error, unexpected '=' or Unable to include ... www.conf | A value in the pool file isn't in double quotes | Put double quotes around every value in the A2.4 lines, then run sudo php-fpm -t |
Web requests produce no traces, but the extension shows in php --ri opentelemetry | The settings aren't reaching PHP | RHEL: check the env[...] lines are in the pool that serves the site. Windows: run the last command of B2.5 and check the variables are listed |
| No traces at all, and no errors | OTEL_PHP_AUTOLOAD_ENABLED isn't true, or the app doesn't load vendor/autoload.php | Check the setting; the application must use Composer's autoloader |
| Incoming requests traced, but no framework, database or HTTP spans | The matching instrumentation package isn't installed | Add it with composer require (see "Which instrumentation packages your app needs") |
composer require fails: plugin not allowed | Composer blocks plugins by default | Run the two composer config allow-plugins... commands first |
Windows: the extension doesn't load (Unable to load dynamic library) | The DLL doesn't match the PHP version, NTS/TS build or compiler, or the Visual C++ runtime is missing | Repeat B2.1–B2.2; the script picks the matching file |
Collector log shows 401 or 403 | Wrong <BASE64_CREDENTIALS>, or the user has no access to <ORG_ID> | Rebuild the Base64 value from email:password-or-token and check the org ID. Restart the Collector |
Collector log shows 404 | Wrong endpoint path | O2_OTLP_ENDPOINT must be <OPENOBSERVE_URL>/api/<ORG_ID>, without /v1/traces |
Collector log shows connection refused, a timeout, or a TLS error | No network route or a proxy in between | Test with curl -I <OPENOBSERVE_URL>. If you need a proxy, add HTTPS_PROXY=http://<proxy-host>:<port> next to the other O2_* values |
| Calls between services show as separate traces | A proxy or API gateway removes the traceparent header | Configure it to forward the traceparent and tracestate headers |
| Too much trace volume | Every request is traced | Add OTEL_TRACES_SAMPLER = parentbased_traceidratio and OTEL_TRACES_SAMPLER_ARG = 0.1 (10%) next to the other settings |
To remove tracing:
- RHEL: restore the pool file (
sudo cp <FPM_POOL_FILE>.orig <FPM_POOL_FILE>) and restart php-fpm. - Windows: remove the
OTEL_*FastCGI variables in IIS Manager → FastCGI Settings →php-cgi.exe→ Environment Variables, then runiisreset.
Without these settings, the extension and packages stay inactive.
Tested versions
This procedure was tested end to end on Red Hat Enterprise Linux 9.9 (Apache httpd with php-fpm) and Windows Server 2022 (IIS 10 with FastCGI), with the versions below. Other versions usually work. Before upgrading a component, check its release notes for removed settings.
| Component | Version |
|---|---|
| OpenTelemetry Collector Contrib | 0.166.0 |
opentelemetry PHP extension | 1.5.0 |
open-telemetry/sdk / open-telemetry/exporter-otlp | 1.18.0 / 1.6.0 |
| PHP | 8.2.36 (RHEL), 8.3.37 NTS x64 (Windows) |
| Framework | Slim 4 with Guzzle 7 (opentelemetry-auto-slim 1.5.1, opentelemetry-auto-guzzle 1.5.0) |
| OpenObserve | v1.2.0 |
For all available instrumentation packages, see OpenTelemetry PHP contrib.