A gRPC transport for opentelemetry-php built on
thesis/grpc-client: a drop-in replacement for
open-telemetry/transport-grpc that needs no ext-grpc, because the whole gRPC stack — HTTP/2 framing,
compression, TLS, load balancing — is plain PHP running on amphp.
composer require thesis/opentelemetry-grpc-transportTransportFactory implements TransportFactoryInterface, so it plugs into any OTLP exporter in place
of the one shipped by the contrib package. The endpoint is a URL whose path is the fully qualified
gRPC method of the signal:
use OpenTelemetry\API\Signals;
use OpenTelemetry\Contrib\Otlp\OtlpUtil;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use Thesis\OpenTelemetry\Grpc\TransportFactory;
$transport = new TransportFactory()->create(
'http://collector:4317' . OtlpUtil::method(Signals::TRACE),
);
$exporter = new SpanExporter($transport);The factory only applies what OTLP knows about. Load balancing, endpoint resolvers, connection limits
and your own interceptors belong on a Client\Builder, which the factory takes as a constructor
argument, leaves untouched and reuses for every transport it creates:
use Thesis\Grpc\Client;
use Thesis\OpenTelemetry\Grpc\TransportFactory;
$factory = new TransportFactory(
new Client\Builder()
->withLoadBalancer(new Client\LoadBalancer\RoundRobinFactory())
->withConnectionLimit(4),
);The host, the encoder, the retry interceptor, compression and TLS are set by the factory on top of it and override whatever the builder had for those.
examples/otlp_grpc.php exports a handful of spans to a collector. A Jaeger
all-in-one is defined in compose.yaml behind the example profile, so one target brings it up and
runs the example against it:
make exampleThe spans then show up at http://localhost:16686 under the unknown_service:php service.
Against a collector you are running yourself:
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 php examples/otlp_grpc.phpIt needs open-telemetry/exporter-otlp for the exporter itself.