Skip to content

Commit

Permalink
move TextMapPropagatorFactoryInterface to SDK
Browse files Browse the repository at this point in the history
reorganise extension propagator factories into SDK, and add a deptrac rule to allow
SDK->Extension dependency. Add PackageDependency attribute to the SDK-housed
extension propagator factories.
  • Loading branch information
brettmc committed Jan 17, 2025
1 parent ae70eeb commit 0571d3b
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 95 deletions.
10 changes: 3 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"open-telemetry/exporter-otlp": "1.0.x-dev",
"open-telemetry/exporter-zipkin": "1.0.x-dev",
"open-telemetry/extension-propagator-b3": "1.0.x-dev",
"open-telemetry/extension-propagator-jaeger": "0.0.2",
"open-telemetry/extension-propagator-cloudtrace": "0.0.4",
"open-telemetry/extension-propagator-jaeger": "0.0.3",
"open-telemetry/gen-otlp-protobuf": "1.0.x-dev",
"open-telemetry/sdk": "1.0.x-dev",
"open-telemetry/sdk-configuration": "0.1.x-dev",
Expand All @@ -65,9 +66,6 @@
"src/Contrib/Otlp/_register.php",
"src/Contrib/Grpc/_register.php",
"src/Contrib/Zipkin/_register.php",
"src/Extension/Propagator/B3/_register.php",
"src/Extension/Propagator/CloudTrace/_register.php",
"src/Extension/Propagator/Jaeger/_register.php",
"src/SDK/_register.php",
"src/SDK/Common/Dev/Compatibility/_load.php",
"src/SDK/Common/Util/functions.php",
Expand Down Expand Up @@ -130,12 +128,10 @@
"autoload-files": [
"examples/src/_register.php",
"src/API/_register.php",
"src/Config/SDK/_register.php",
"src/Contrib/Otlp/_register.php",
"src/Contrib/Grpc/_register.php",
"src/Contrib/Zipkin/_register.php",
"src/Extension/Propagator/B3/_register.php",
"src/Extension/Propagator/CloudTrace/_register.php",
"src/Extension/Propagator/Jaeger/_register.php",
"src/SDK/_register.php",
"tests/_register.php"
],
Expand Down
1 change: 1 addition & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ deptrac:
SDK:
- +API
- ConfigSDK
- Extension
- SemConv
- PsrHttp
- HttpPlug
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Propagator;

use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* @implements ComponentProvider<TextMapPropagatorInterface>
*/
#[PackageDependency('open-telemetry/extension-propagator-cloudtrace', '^0.0.4')]
final class TextMapPropagatorCloudTrace implements ComponentProvider
{
/**
* @param array{} $properties
*/
public function createPlugin(array $properties, Context $context): TextMapPropagatorInterface
{
return CloudTracePropagator::getInstance();
}

public function getConfig(ComponentProviderRegistry $registry, NodeBuilder $builder): ArrayNodeDefinition
{
return $builder->arrayNode('cloudtrace');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @implements ComponentProvider<TextMapPropagatorInterface>
*/
#[PackageDependency('open-telemetry/extension-propagator-jaeger', '^0.0.2')]
#[PackageDependency('open-telemetry/extension-propagator-jaeger', '^0.0.3')]
final class TextMapPropagatorJaeger implements ComponentProvider
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Config/SDK/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorB3;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorB3Multi;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorBaggage;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorCloudTrace;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorComposite;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorJaeger;
use OpenTelemetry\Config\SDK\ComponentProvider\Propagator\TextMapPropagatorTraceContext;
Expand All @@ -34,6 +35,7 @@
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorB3Multi::class);
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorBaggage::class);
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorComposite::class);
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorCloudTrace::class);
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorJaeger::class);
ServiceLoader::register(ComponentProvider::class, TextMapPropagatorTraceContext::class);

Expand Down
12 changes: 0 additions & 12 deletions src/Context/Propagation/TextMapPropagatorFactoryInterface.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Extension/Propagator/B3/_register.php

This file was deleted.

9 changes: 1 addition & 8 deletions src/Extension/Propagator/B3/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
"autoload": {
"psr-4": {
"OpenTelemetry\\Extension\\Propagator\\B3\\": "."
},
"files": [
"_register.php"
]
}
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev",
"dev-2.x": "2.x-dev"
},
"spi-config": {
"autoload-files": true,
"prune-autoload-files": true
}
}
}
11 changes: 0 additions & 11 deletions src/Extension/Propagator/CloudTrace/_register.php

This file was deleted.

9 changes: 1 addition & 8 deletions src/Extension/Propagator/CloudTrace/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
"autoload": {
"psr-4": {
"OpenTelemetry\\Extension\\Propagator\\CloudTrace\\": "."
},
"files": [
"_register.php"
]
}
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev",
"dev-2.x": "2.x-dev"
},
"spi-config": {
"autoload-files": true,
"prune-autoload-files": true
}
}
}
11 changes: 0 additions & 11 deletions src/Extension/Propagator/Jaeger/_register.php

This file was deleted.

9 changes: 1 addition & 8 deletions src/Extension/Propagator/Jaeger/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
"autoload": {
"psr-4": {
"OpenTelemetry\\Extension\\Propagator\\Jaeger\\": "."
},
"files": [
"_register.php"
]
}
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev",
"dev-2.x": "2.x-dev"
},
"spi-config": {
"autoload-files": true,
"prune-autoload-files": true
}
}
}
4 changes: 2 additions & 2 deletions src/SDK/Common/Services/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace OpenTelemetry\SDK\Common\Services;

use Nevay\SPI\ServiceLoader;
use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface;
use OpenTelemetry\SDK\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\SDK\Resource\ResourceDetectorFactoryInterface;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface;
Expand All @@ -21,7 +21,7 @@
class Loader
{
/**
* @param class-string $class
* @param class-string<SpiLoadableInterface> $class
* @phan-suppress PhanTypeNonVarPassByRef
*/
private static function getFactory(string $class, string $type): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\B3;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\B3\B3Propagator;

#[PackageDependency('open-telemetry/extension-propagator-b3', '^1')]
class B3MultiPropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\B3;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\B3\B3Propagator;

#[PackageDependency('open-telemetry/extension-propagator-b3', '^1')]
class B3PropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
1 change: 0 additions & 1 deletion src/SDK/Propagation/BaggagePropagatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
;

use OpenTelemetry\API\Baggage\Propagation\BaggagePropagator;
use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Configuration\KnownValues;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\CloudTrace;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator;

#[PackageDependency('open-telemetry/extension-propagator-cloudtrace', '^0')]
class CloudTraceOneWayPropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\CloudTrace;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator;

#[PackageDependency('open-telemetry/extension-propagator-cloudtrace', '^0')]
class CloudTracePropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\Jaeger;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\Jaeger\JaegerBaggagePropagator;

#[PackageDependency('open-telemetry/extension-propagator-jaeger', '^0')]
class JaegerBaggagePropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\Jaeger;
namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use Nevay\SPI\ServiceProviderDependency\PackageDependency;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\Extension\Propagator\Jaeger\JaegerPropagator;

#[PackageDependency('open-telemetry/extension-propagator-jaeger', '^0')]
class JaegerPropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
Expand Down
13 changes: 13 additions & 0 deletions src/SDK/Propagation/TextMapPropagatorFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Services\SpiLoadableInterface;

interface TextMapPropagatorFactoryInterface extends SpiLoadableInterface
{
public function create(): TextMapPropagatorInterface;
}
1 change: 0 additions & 1 deletion src/SDK/Propagation/TraceContextPropagatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
;

use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator;
use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Configuration\KnownValues;

Expand Down
15 changes: 13 additions & 2 deletions src/SDK/_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
declare(strict_types=1);

use Nevay\SPI\ServiceLoader;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Common\Export\Stream\StreamTransportFactory;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Logs\Exporter as LogsExporter;
use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
use OpenTelemetry\SDK\Metrics\MetricExporter;
use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface;
use OpenTelemetry\SDK\Propagation\B3MultiPropagatorFactory;
use OpenTelemetry\SDK\Propagation\B3PropagatorFactory;
use OpenTelemetry\SDK\Propagation\BaggagePropagatorFactory;
use OpenTelemetry\SDK\Propagation\CloudTraceOneWayPropagatorFactory;
use OpenTelemetry\SDK\Propagation\CloudTracePropagatorFactory;
use OpenTelemetry\SDK\Propagation\JaegerBaggagePropagatorFactory;
use OpenTelemetry\SDK\Propagation\JaegerPropagatorFactory;
use OpenTelemetry\SDK\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\SDK\Propagation\TraceContextPropagatorFactory;
use OpenTelemetry\SDK\Trace\SpanExporter;
use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface;

ServiceLoader::register(TextMapPropagatorFactoryInterface::class, BaggagePropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, TraceContextPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3PropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, B3MultiPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTracePropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, CloudTraceOneWayPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerPropagatorFactory::class);
ServiceLoader::register(TextMapPropagatorFactoryInterface::class, JaegerBaggagePropagatorFactory::class);

ServiceLoader::register(LogRecordExporterFactoryInterface::class, LogsExporter\ConsoleExporterFactory::class);
ServiceLoader::register(LogRecordExporterFactoryInterface::class, LogsExporter\InMemoryExporterFactory::class);
Expand Down

0 comments on commit 0571d3b

Please sign in to comment.