APM tracing

← All configuration scenarios

Mini4Work can trace each call to your PHP handler over HTTP/1.1, HTTP/2 or HTTP/3. Tracing defaults to off. Choose one provider and run its example from the directory containing the example server.php. That handler returns HTTP 200 for GET /hello.

Jump to Datadog, New Relic, Elastic APM or OpenTelemetry.

Datadog

Install the PHP tracer for your CLI and enable APM on your Datadog Agent. This example sends spans to an Agent listening on the same host at port 8126. Save this profile as datadog.json. Datadog PHP setup

JSON
{
  "listen": { "port": 9000 },
  "observability": { "apm": "datadog" }
}

Check that the CLI loads the tracer, then start the server. Disabling the automatic CLI root span and enabling auto-flush lets the worker send a trace as each request finishes.

Shell
php --ri ddtrace
DD_SERVICE=mini4work-app \
DD_TRACE_AGENT_URL=http://127.0.0.1:8126 \
DD_TRACE_CLI_ENABLED=1 \
DD_TRACE_GENERATE_ROOT_SPAN=0 \
DD_TRACE_AUTO_FLUSH_ENABLED=1 \
php server.php datadog.json

Send a request from a second terminal.

Shell
curl -i http://127.0.0.1:9000/hello

In Datadog Trace Explorer, filter by service:mini4work-app. Open a recent http.request span and check that http.status_code is 200.

New Relic

Install the New Relic PHP agent and its reporting daemon for your PHP version. Save this Mini4Work profile as newrelic.json. New Relic PHP installation

JSON
{
  "listen": { "port": 9000 },
  "observability": { "apm": "newrelic" }
}

Run php --ini to locate the agent’s CLI INI file. Set the application name there and supply your ingest license key in the server process’s NEW_RELIC_LICENSE_KEY environment variable. PHP expands the variable when it reads the file.

INI
newrelic.appname = "mini4work-app"
newrelic.license = "${NEW_RELIC_LICENSE_KEY}"

Check that the extension loads, then start the server.

Shell
php --ri newrelic
php server.php newrelic.json

Send a request from a second terminal.

Shell
curl -i http://127.0.0.1:9000/hello

In New Relic APM, open mini4work-app and its Transactions view. Include non-web transactions when filtering because the worker runs under PHP CLI. Look for the name Mini4Work/http.request. The agent adds http.response.status_code to the transaction when the handler returns.

Elastic APM

Install the native Elastic PHP agent on a supported PHP version and operating system. Save this profile as elastic.json. Elastic PHP agent setup

JSON
{
  "listen": { "port": 9000 },
  "observability": { "apm": "elastic" }
}

Export your deployment’s secret token as APM_SECRET_TOKEN in the launch shell. Replace the example URL with its HTTPS APM intake URL, then start the server. If your deployment uses API keys, replace the secret-token line with ELASTIC_APM_API_KEY="$APM_API_KEY" and export your key as APM_API_KEY. Elastic agent settings

Shell
php --ri elastic_apm
ELASTIC_APM_SERVICE_NAME=mini4work-app \
ELASTIC_APM_SECRET_TOKEN="${APM_SECRET_TOKEN:?Export the APM secret token first}" \
ELASTIC_APM_SERVER_URL=https://apm.example.com:8200 \
php server.php elastic.json

Send a request from a second terminal.

Shell
curl -i http://127.0.0.1:9000/hello

In Kibana APM, open mini4work-app and select the http.request transaction of type request. For this handler, the transaction result is HTTP 2xx and its outcome is success.

OpenTelemetry

Use a collector with an OTLP/HTTP receiver and a traces pipeline that exports to your tracing backend. This example assumes the receiver is reachable from the worker at 127.0.0.1:4318. Save this profile as otel.json.

JSON
{
  "listen": { "port": 9000 },
  "observability": { "apm": "opentelemetry" }
}

Install the SDK, OTLP exporter and HTTP client in the application.

Shell
composer require open-telemetry/sdk open-telemetry/exporter-otlp php-http/guzzle7-adapter

Start the server with SDK autoloading enabled. The simple processor exports each completed span immediately, which makes a single test request easy to find. Omit the processor setting to use the SDK’s default batching. PHP SDK configuration

Shell
OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME=mini4work-app \
OTEL_TRACES_EXPORTER=otlp \
OTEL_PHP_TRACES_PROCESSOR=simple \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 \
php server.php otel.json

In a second terminal, generate a trace ID and send it in the W3C traceparent header. The final command prints the ID to look up.

Shell
trace_id=$(php -r 'echo bin2hex(random_bytes(16));')
curl -i -H "traceparent: 00-${trace_id}-00f067aa0ba902b7-01" \
  http://127.0.0.1:9000/hello
echo "$trace_id"

Search your backend for that trace ID. Under mini4work-app, look for the http.request server span with http.response.status_code equal to 200. The instrumentation scope is mini4work/webserver.

Troubleshooting

The server rejects the provider at startup
Check the extension or Composer SDK in the same PHP CLI that runs server.php. For New Relic, also check that newrelic.appname is set.
The handler returns 200 but the backend shows no trace
Check the service name, time range and sampling settings. Inspect the Agent, daemon or collector logs for delivery errors. Inside a container, a loopback address reaches the container itself. Use the receiver’s service hostname if it runs elsewhere.
The trace ends before the response finishes
Tracing measures handler execution. A streamed response can continue sending bytes after the handler returns. Datadog, New Relic and Elastic finish the active span or transaction when a managed request suspends. OpenTelemetry can keep its span open across that suspension.