Skip to content

Commit

Permalink
require google/protobuf (native) (#1067)
Browse files Browse the repository at this point in the history
We made protobuf implementation optional back in #949 however it seems to be tripping up
a number of developers. Since native + extension can be installed at the same time (with
extension taking priority), I think that users will be less surprised when starting out
if there is a working implementation by default.
  • Loading branch information
brettmc authored Jul 4, 2023
1 parent 5e827ab commit 6387992
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
21 changes: 10 additions & 11 deletions proto/otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@

## Protobuf Runtime library

OTLP exporting requires a [protobuf runtime library](https://github.com/protocolbuffers/protobuf/tree/main/php).

There exist two protobuf runtime libraries that offer the same set of APIs, allowing developers to choose the one that
best suits their needs.

The first and easiest option is to install the Protobuf PHP Runtime Library through composer. This can be the easiest
way to get started quickly. Either run `composer require google/protobuf`, or update your `composer.json` as follows:

```json
"require": {
"google/protobuf": "^v3.3.0"
}
```
This package requires `google/protobuf`, which is the native implementation. It is easy to install and a good way to get
started quickly.

Alternatively, and the recommended option for production is to install the Protobuf C extension for PHP. The extension
makes both exporters _significantly_ more performant. This can be easily installed with the following command:
```sh
$ sudo pecl install protobuf
makes OTLP exporting _significantly_ more performant. The extension can be installed with the following command:

```shell
pecl install protobuf
```

The extension can be installed alongside the native library, and it will be used instead if available.
6 changes: 3 additions & 3 deletions proto/otel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
],
"require": {
"php": "^7.4 || ^8.0"
"php": "^7.4 || ^8.0",
"google/protobuf": "^3.3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -26,8 +27,7 @@
}
},
"suggest": {
"ext-protobuf": "For better performance, when dealing with the protobuf format",
"google/protobuf": "To get started quickly, install the native protobuf library."
"ext-protobuf": "For better performance, when dealing with the protobuf format"
},
"extra": {
"branch-alias": {
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
\Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class,
\Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
\Rector\RemovingStatic\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class,
\Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class,
]);
};
26 changes: 8 additions & 18 deletions src/Contrib/Otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,25 @@ See https://github.com/open-telemetry/opentelemetry-php/blob/main/examples/trace

## Http transport

To export over HTTP, you will need to provide implementations for [http factory implementation](https://packagist.org/providers/psr/http-factory-implementation) and [async-client-implementation](https://packagist.org/providers/php-http/async-client-implementation).

You will also need to install [php-http/discovery](https://packagist.org/packages/php-http/discovery).

```php
$transport = (new \OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory())->create('http://collector:4318');
$exporter = new \OpenTelemetry\Contrib\Otlp\SpanExporter($transport);
```

## gRPC transport

To export over gRPC, you will need to additionally install the `open-telemetry/exporter-grpc` package.
To export over gRPC, you will need to additionally install the `open-telemetry/transport-grpc` package.

## Protobuf Runtime library

There exist two protobuf runtime libraries that offer the same set of APIs, allowing developers to choose the one that
best suits their needs. You must install one of them, in order to use the OTLP exporter.
OTLP exporting requires a [protobuf implementation](https://github.com/protocolbuffers/protobuf/tree/main/php).

The first and easiest option is to install the Protobuf PHP Runtime Library through composer. This can be the easiest
way to get started quickly. Either run `composer require google/protobuf`, or update your `composer.json` as follows:
The `open-telemetry/gen-otlp-protobuf` requires the `google/protobuf` native implementation. It's fine for development, but
not recommended for production usage.

```json
"require": {
"google/protobuf": "^v3.3.0"
}
```
The recommended option for production is to install the Protobuf C extension for PHP. The extension
makes exporting _significantly_ more performant. This can be easily installed with the following command:

Alternatively, and the recommended option for production is to install the Protobuf C extension for PHP. The extension
makes both exporters _significantly_ more performant. This can be easily installed with the following command:
```sh
$ sudo pecl install protobuf
```shell
pecl install protobuf
```
3 changes: 0 additions & 3 deletions src/Contrib/Otlp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"open-telemetry/sdk": "^1.0"
},
"suggest": {
"php-http/async-client-implementation": "For otlp/http exporting",
"php-http/discovery": "For otlp/http exporting",
"psr/http-factory-implementation": "For otlp/http exporting"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 6387992

Please sign in to comment.