OpenTelemetry middleware is a unified standard for the tracing, logging and metrics information. At the moment, only tracing information is stable and safe to use in production.
PHP library in the alpha stage at the moment: link.
Thanks to Brett McBride, he created a rr-otel PHP demo.
OT is a middleware plugin which currently working with gRPC and HTTP plugins.
Example configuration for HTTP:
version: "2.7"
rpc:
listen: tcp://127.0.0.1:6001
server:
command: "php otel_worker.php"
env:
- OTEL_SERVICE_NAME: php
- OTEL_TRACES_EXPORTER: otlp
- OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
- OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:4318
- OTEL_PHP_TRACES_PROCESSOR: simple
relay: pipes
http:
address: 127.0.0.1:15389
middleware: [gzip, otel]
otel:
insecure: true
compress: false
exporter: otlp
service_name: rr_test
service_version: 1.0.0
endpoint: 127.0.0.1:4318
pool:
num_workers: 10
logs:
encoding: console
level: debug
mode: production
otel
contains the following keys:
insecure
: boolean, default false
. Use insecure endpoints (http/https) or insecure gRPC.compress
: boolean, default false
. Use gzip to compress the spans.exporter
: string, default otlp
. Provides functionality to emit telemetry to consumers. Possible values: otlp
(used for new_relic
, datadog
), zipkin
, stdout
, jaeger
or jaeger_agent
to use a Jaeger agent UDP endpoint.custom_url
: string, default empty. Used for the http
client to override the default URL.client
: string, default http
. Client to send the spans. Possible values: http
, grpc
.endpoint
: string, default localhost:4318
. Consumer's endpoint.service_name
: string, default: RoadRunner
. User's service name.service_version
: string, default 1.0.0
. User's service version.headers
: key-values map, default empty. User defined headers. new_relic api-key
should be here.Env variables are used for the PHP process and can be passed via the server
env variables.
server:
command: "php otel_worker.php"
env:
- OTEL_SERVICE_NAME: php
- OTEL_TRACES_EXPORTER: otlp
- OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
- OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:4318
- OTEL_PHP_TRACES_PROCESSOR: simple
relay: pipes
#docker-composer.yml
version: "3.6"
services:
collector:
image: otel/opentelemetry-collector-contrib
command: ["--config=/etc/otel-collector-config.yml"]
volumes:
- ./otel-collector-config.yml:/etc/otel-collector-config.yml
ports:
- "4318:4318"
Below, you will find an example of a collector configuration that sends data to Zipkin, Datadog, or New Relic:
#otel-collector-config.yml
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
timeout: 1s
exporters:
logging:
loglevel: debug
zipkin:
endpoint: "http://zipkin:9411/api/v2/spans"
datadog:
api:
site: datadoghq.eu
key: ...
otlp:
endpoint: https://otlp.eu01.nr-data.net:443
headers:
api-key: ...
service:
pipelines:
traces:
receivers: [ otlp ]
processors: [ batch ]
exporters: [ zipkin, datadog, otlp, logging ]
Then configure your php application:
# OpenTelemetry
OTEL_SERVICE_NAME=php-blog
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 # Collector address
OTEL_PHP_TRACES_PROCESSOR=simple