Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
- conditionally use SPI in extensions _register.php
- deprecate OtlpHttpTransportFactory in favour of PsrTransportFactory
  • Loading branch information
brettmc committed Oct 28, 2024
1 parent 9f7d95b commit 5ffe83b
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 51 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
},
"spi": {
"OpenTelemetry\\SDK\\Common\\Export\\TransportFactoryInterface": [
"OpenTelemetry\\Contrib\\Otlp\\OtlpHttpTransportFactory",
"OpenTelemetry\\Contrib\\Grpc\\GrpcTransportFactory",
"OpenTelemetry\\SDK\\Common\\Export\\Http\\PsrTransportFactory",
"OpenTelemetry\\SDK\\Common\\Export\\Stream\\StreamTransportFactory"
Expand Down
4 changes: 2 additions & 2 deletions examples/logs/exporters/otlp_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use OpenTelemetry\API\Logs\LogRecord;
use OpenTelemetry\API\Logs\Severity;
use OpenTelemetry\Contrib\Otlp\LogsExporter;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory;
use OpenTelemetry\SDK\Logs\EventLoggerProvider;
use OpenTelemetry\SDK\Logs\LoggerProvider;
Expand All @@ -16,7 +16,7 @@

require __DIR__ . '/../../../vendor/autoload.php';

$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/logs', 'application/json');
$transport = (new PsrTransportFactory())->create('http://collector:4318/v1/logs', 'application/json');
$exporter = new LogsExporter($transport);

$loggerProvider = new LoggerProvider(
Expand Down
4 changes: 2 additions & 2 deletions examples/traces/exporters/otlp_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

require __DIR__ . '/../../../vendor/autoload.php';

use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', 'application/x-protobuf');
$transport = (new PsrTransportFactory())->create('http://collector:4318/v1/traces', 'application/x-protobuf');
$exporter = new SpanExporter($transport);

echo 'Starting OTLP example';
Expand Down
4 changes: 2 additions & 2 deletions examples/traces/exporters/otlp_http_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
require __DIR__ . '/../../../vendor/autoload.php';

use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', ContentTypes::JSON);
$transport = (new PsrTransportFactory())->create('http://collector:4318/v1/traces', ContentTypes::JSON);
$exporter = new SpanExporter($transport);

echo 'Starting OTLP+json example';
Expand Down
4 changes: 2 additions & 2 deletions examples/traces/features/auto_root_span.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use OpenTelemetry\API\Logs\LogRecord;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=otlp');
putenv('OTEL_TRACES_EXPORTER=console');
putenv('OTEL_METRICS_EXPORTER=none');
putenv('OTEL_LOGS_EXPORTER=otlp');
putenv('OTEL_LOGS_EXPORTER=console');
putenv('OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318');
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf');
putenv('OTEL_PROPAGATORS=tracecontext');
Expand Down
3 changes: 3 additions & 0 deletions src/Contrib/Otlp/OtlpHttpTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;

/**
* @deprecated Use PsrTransportFactory
*/
class OtlpHttpTransportFactory implements TransportFactoryInterface
{
private const DEFAULT_COMPRESSION = 'none';
Expand Down
4 changes: 0 additions & 4 deletions src/Contrib/Otlp/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
use Nevay\SPI\ServiceLoader;
use OpenTelemetry\Contrib\Otlp\LogsExporterFactory;
use OpenTelemetry\Contrib\Otlp\MetricExporterFactory;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporterFactory;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface;
use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface;

ServiceLoader::register(SpanExporterFactoryInterface::class, SpanExporterFactory::class);
ServiceLoader::register(MetricExporterFactoryInterface::class, MetricExporterFactory::class);
ServiceLoader::register(LogRecordExporterFactoryInterface::class, LogsExporterFactory::class);

ServiceLoader::register(TransportFactoryInterface::class, OtlpHttpTransportFactory::class);
1 change: 0 additions & 1 deletion src/Extension/Propagator/B3/B3MultiPropagatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class B3MultiPropagatorFactory implements TextMapPropagatorFactoryInterface
{

public function create(): TextMapPropagatorInterface
{
return B3Propagator::getB3MultiHeaderInstance();
Expand Down
6 changes: 4 additions & 2 deletions src/Extension/Propagator/B3/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
use OpenTelemetry\Extension\Propagator\B3\B3MultiPropagatorFactory;
use OpenTelemetry\Extension\Propagator\B3\B3PropagatorFactory;

ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3PropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3MultiPropagatorFactory::class);
if (class_exists(ServiceLoader::class)) {
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3PropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3MultiPropagatorFactory::class);
}
6 changes: 4 additions & 2 deletions src/Extension/Propagator/CloudTrace/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTraceOneWayPropagatorFactory;
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagatorFactory;

ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTracePropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTraceOneWayPropagatorFactory::class);
if (class_exists(ServiceLoader::class)) {
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTracePropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTraceOneWayPropagatorFactory::class);
}
6 changes: 4 additions & 2 deletions src/Extension/Propagator/Jaeger/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
use OpenTelemetry\Extension\Propagator\Jaeger\JaegerBaggagePropagatorFactory;
use OpenTelemetry\Extension\Propagator\Jaeger\JaegerPropagatorFactory;

ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerBaggagePropagatorFactory::class);
if (class_exists(ServiceLoader::class)) {
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerBaggagePropagatorFactory::class);
}
3 changes: 0 additions & 3 deletions src/SDK/Common/Export/Http/PsrTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public function create(
throw new InvalidArgumentException(sprintf('Invalid endpoint url "%s"', $endpoint));
}
assert(!empty($endpoint));
if ($compression === 'none') {
$compression = null;
}

$this->client ??= Discovery::find([
'timeout' => $timeout,
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Common/Export/Http/PsrUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function compression($compression): array
if (is_array($compression)) {
return $compression;
}
if (!$compression) {
if ($compression === 'none' || !$compression) {
return [];
}
if (!str_contains((string) $compression, ',')) {
Expand Down
27 changes: 0 additions & 27 deletions tests/Unit/Contrib/Otlp/OtlpHttpTransportFactoryTest.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static function compressionProvider(): array
return [
['gzip', ['gzip']],
['', []],
['none', []],
['gzip,br', ['gzip','br']],
['gzip , brotli', ['gzip','brotli']],
[['gzip'], ['gzip']],
Expand Down

0 comments on commit 5ffe83b

Please sign in to comment.