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.
Choose how to ingest data into Dynatrace
OneAgent currently only ingests traces automatically. If you are recording metrics or logs, choose the OTLP export route.
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.1php pickle.phar install --source https://github.com/open-telemetry/opentelemetry-php-instrumentation.git#1.0.0beta5
Add the newly compiled library as extension to your
Restart PHP and verify that the extension was loaded.
- From the command line, with
- As part of a web server, by calling
- 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.
Depending on your ingestion type (OneAgent or export), configure the following environment variables.
Add telemetry signals manually optional
As automatic instrumentation on PHP does not provide pre-configured tracer and meter providers, you'd need to follow the initialization and instrumentation steps at Manually instrument your PHP application with OpenTelemetry, if you wish to manually add custom signals (such as traces and metrics) on top of automatic instrumentation.
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 & Events (latest Dynatrace) or Logs (previous Dynatrace).
- Enrich ingested data with Dynatrace-specific dimensions
Learn how to automatically enrich your telemetry data with Dynatrace-specific dimensions.