Automatically instrument your PHP application with OpenTelemetry
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 and use available DDU quotas. To achieve this, you'd need to switch to manual instrumentation.
Get the Dynatrace access details
Determine the API base URL
For details on how to assemble the base OTLP endpoint URL, see Export with OTLP. The URL should end in /api/v2/otlp
.
Get API access token
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.
Instrument your application
-
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.
- From the command line, with
php -m
- As part of a web server, by calling
phpinfo()
- From the command line, with
-
Install the SDK and other dependencies.
- required Install the SDK for OpenTelemetry PHP.
- optional Depending on the libraries your application is using, you might want to add other instrumentation libraries to the dependencies. You'll find the list of supported libraries in the OpenTelemetry Registry.
- required You must use composer autoloading, as this is the mechanism that all auto-instrumentation packages use to register themselves.
-
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]"Substitute
[URL]
and[TOKEN]
with the respective values.
Ensure context propagation
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.
Configure data capture to meet privacy requirements optional
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.
Verify data ingestion into Dynatrace
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 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).