This walkthrough shows how to add observability to your PHP application using the OpenTelemetry PHP libraries and tools.
It is currently not possible to enrich automatically instrumented services with host-relevant information. To achieve this, you'd need to switch to manual instrumentation.
For details on how to assemble the base OTLP endpoint URL, see Export with OTLP. The URL should end in /api/v2/otlp
.
The access token for ingesting traces, logs, and metrics can be generated under Access Tokens.
Export with OTLP has more details on the format and the necessary access scopes.
Ensure you have an adequate build environment for your system set up, consisting of GCC, Make, and Autoconfig.
Build and install the instrumentation library, using pickle.
php pickle.phar install opentelemetry
Add the newly compiled library as extension to your php.ini
.
extension=opentelemetry.so
Restart PHP and verify that the extension was loaded.
php -m
phpinfo()
Install the SDK and other dependencies.
Configure the following environment variables.
OTEL_PHP_AUTOLOAD_ENABLED=trueOTEL_SERVICE_NAME=php-quickstartOTEL_PROPAGATORS=baggage,tracecontextOTEL_EXPORTER=otlpOTEL_EXPORTER_OTLP_PROTOCOL=http/protobufOTEL_EXPORTER_OTLP_ENDPOINT=[URL]OTEL_EXPORTER_OTLP_HEADERS="Authorization=Api-Token [TOKEN]"OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta
Substitute [URL]
and [TOKEN]
with the respective values.
Context propagation is particularly important when network calls (for example, REST) are involved.
With automatic instrumentation, this should be automatically taken care of by the instrumentation libraries. If the used network libraries are not be covered by that, you would need to switch to manual instrumentation instead and handle propagation manually.
While Dynatrace automatically captures all OpenTelemetry attributes, only attribute values specified in the allowlist are stored and displayed in the Dynatrace web UI. This prevents accidental storage of personal data, so you can meet your privacy requirements and control the amount of monitoring data stored.
To view your custom attributes, you need to allow them in the Dynatrace web UI first. To learn how to configure attribute storage and masking, see Attribute redaction.
Once you have finished the instrumentation of your application, perform a couple of test actions to create and send demo traces, metrics, and logs and verify that they were correctly ingested into Dynatrace.
To do that for traces, go to Distributed Traces or Distributed Traces Classic (latest Dynatrace) and select the Ingested traces tab. If you use OneAgent, select PurePaths instead.
For metrics and logs, go to Metrics or Logs or Logs & Events (latest Dynatrace).