Add first-party OpenTelemetry support (opentelemetry extension + PHP_OPENTELEMETRY_* env vars) #695
aagjalpankaj
started this conversation in
Ideas & Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
👉 Describe the problem
There is currently no first-party way to instrument an application running on
serversideup/phpwith OpenTelemetry, and the workarounds that people reach for fight the image's architecture.The common approach — running a vendor APM agent as a sidecar process inside the container — collides directly with S6 Overlay. This is not hypothetical: #292 (Datadog APM on Google Cloud Run) shows a user hitting
s6-overlay-suexec: fatal: can only run as pid 1while trying to instrument8.1-fpm-nginx, and a second user reporting the same failure and having to install the agent through a custom S6 oneshot service with a runtime-only API key.OpenTelemetry avoids that entire problem class, because the PHP implementation is in-process: a PHP extension plus Composer packages. There is no second process, no PID 1 conflict, and nothing for S6 Overlay to argue with. But today the extension is not present in any image, so every user who wants it has to discover
install-php-extensions, write a customDockerfile, and work out the correct configuration themselves.👥 Problem evidence & reach
Concrete evidence in this repository:
I want to be straight about in-repo demand: OpenTelemetry specifically has not been requested here before, and this is the first discussion about it. The reach argument is mostly external.
Evidence of reach in the wider PHP/Laravel ecosystem (Packagist download counts, at time of writing):
open-telemetry/exporter-otlpopen-telemetry/opentelemetry-auto-laravelopen-telemetry/opentelemetryThe Laravel auto-instrumentation package alone is pulled ~340k times a month. Given this project describes itself as optimized for Laravel, that is the population most likely to want this.
OpenTelemetry is also the vendor-neutral CNCF standard, so supporting it serves Datadog, New Relic, Grafana, Honeycomb, Signoz, Jaeger and self-hosted collector users with one implementation, rather than the project ever needing to take a position on a specific APM vendor.
🏆 How to solve this problem
Ship the
opentelemetryextension in the images, expose its INI directives through the existingPHP_*environment variable convention, and document the setup. Defaults stay exactly as they are today, so nothing changes for existing users until someone opts in by installing the Composer SDK.Detail 1 — Install the extension, guarded to PHP 8.x
The extension requires PHP 8.0+. I verified that
install-php-extensions opentelemetryfails on PHP 7.4 (pecl/opentelemetry requires PHP (version >= 8.0.0), installed version is 7.4.33→install failed), so it cannot simply be appended to the sharedDEPENDENCY_PHP_EXTENSIONSlist — that would break every 7.4 build.DEPENDENCY_PHP_EXTENSIONS_PHP8='opentelemetry'build ARGcase "${PHP_VERSION}" in 8.*)guard, so 7.4 images are untouchedARG PHP_VERSIONis currently declared only before the firstFROMin all five variation Dockerfiles. Because Docker global ARGs do not carry into build stages, it must be re-declared inside the stage or the guard would silently skip on every versionDetail 2 — Expose configuration via the existing
PHP_*conventionThe extension exposes a small set of INI directives. Four are worth surfacing, each defaulting to the upstream value:
PHP_OPENTELEMETRY_ATTR_HOOKS_ENABLED0#[WithSpan]attribute instrumentationPHP_OPENTELEMETRY_ALLOW_STACK_EXTENSION0PHP_OPENTELEMETRY_VALIDATE_HOOK_FUNCTIONS1PHP_OPENTELEMETRY_DISPLAY_WARNINGS0These would live in
serversideup-docker-php.inialongside the other module sections. There is precedent for this: that file already carries an[intl]section even thoughintlis not installed by default, and PHP silently ignores INI directives belonging to an unloaded extension — so the block is harmless on 7.4.Detail 3 — What this deliberately does not include
Keeping the image lean is the point, so the scope stops well short of "bundle observability":
grpc— not included. OTLP export over HTTP+protobuf does not need it, and it is by far the largest cost (see measurements below)protobuf— not included. It is an application-level performance choiceopen-telemetry/*Composer packages — these belong in the application, not the imageOTEL_*variables (OTEL_SERVICE_NAME,OTEL_EXPORTER_OTLP_ENDPOINT, …) — deliberately not set. The SDK reads these from the environment itself; baking in defaults would silently override user intent and break spec compliance. They should be documented, not setMeasured image size impact
Given that
intlis excluded from these images specifically because it costs ~40 MB, I measured the actual cost before proposing this. Built locally from the published8.4-cliimages onlinux/arm64:serversideup/php:8.4-cli(baseline)+ opentelemetry+ opentelemetry protobuf+ opentelemetry protobuf grpcserversideup/php:8.4-cli-alpine(baseline)+ opentelemetry+ opentelemetry protobuf+ opentelemetry protobuf grpcThe extension on its own costs ~200–270 KB, roughly 1/150th of what excluded
intl.The
grpcrows are the reason it is explicitly out of scope. On Alpine it would inflate the image by 15.32% — 64× the cost of the OpenTelemetry extension itself — for a transport that OTLP over HTTP+protobuf does not require. Users who genuinely need OTLP/gRPC can still add it in their ownDockerfile; everyone else should not pay for it.🥰 Describe the "impact" on users?
OTEL_*variables, done — no customDockerfileand no rebuild💯 How do we validate the problem is solved?
scripts/dev.sh. Assert 7.4 still builds and does not contain the extension; assert 8.x doesphp --ri opentelemetryon a stock 8.x image reports the extension present with upstream defaults, and an app with no OTel Composer packages behaves identically to todayPHP_OPENTELEMETRY_ATTR_HOOKS_ENABLED=1is reflected inphp --ri opentelemetryopen-telemetry/opentelemetry-auto-laravelagainst a local OTel Collector and confirm spans arrive — with no customDockerfileand no sidecarI have measured the size impact and verified the PHP 7.4 and
ARGscoping constraints described above, and I am happy to do the implementation work and open the PR if there is appetite for it. Wanted to follow the process in #66 and check for interest first.All reactions