Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use SPI to manage components #1412

Open
wants to merge 49 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
abd9944
generate registry from composer autoload-dump
brettmc Oct 18, 2024
43ebe82
use SPI to configure registry
brettmc Oct 22, 2024
8e17eaa
fix b3
brettmc Oct 22, 2024
d252d31
don't static init registry from SPI. add tests
brettmc Oct 23, 2024
d0fb06c
always use SPI
brettmc Oct 28, 2024
b157de2
tidy registry
brettmc Oct 28, 2024
98c1ce0
remove phan suppressions
brettmc Oct 28, 2024
663998d
dont define built-in propagators in SPI
brettmc Oct 28, 2024
77b5d7c
update examples
brettmc Oct 28, 2024
9f7d95b
formatting, remove unused factories
brettmc Oct 28, 2024
5ffe83b
tidy
brettmc Oct 28, 2024
95edf15
generate registry from composer autoload-dump
brettmc Oct 18, 2024
8f26132
use SPI to configure registry
brettmc Oct 22, 2024
b07b16a
fix b3
brettmc Oct 22, 2024
3481905
don't static init registry from SPI. add tests
brettmc Oct 23, 2024
9475249
always use SPI
brettmc Oct 28, 2024
93829f3
tidy registry
brettmc Oct 28, 2024
0d8662d
remove phan suppressions
brettmc Oct 28, 2024
1744c84
dont define built-in propagators in SPI
brettmc Oct 28, 2024
fa1b678
update examples
brettmc Oct 28, 2024
af53feb
formatting, remove unused factories
brettmc Oct 28, 2024
0af0b54
tidy
brettmc Oct 28, 2024
37f8176
remove blank lines after class opening (#1468)
brettmc Jan 7, 2025
b90344e
adding otlp/file exporter (#1465)
brettmc Jan 8, 2025
b4484c4
deprecate event logger (#1466)
brettmc Jan 8, 2025
5a0dc98
use SPI for stdout otlp exporters
brettmc Jan 9, 2025
eb256a2
Merge branch '2.x' into composer-extra-registry
brettmc Jan 9, 2025
4cdc497
Merge branch 'composer-extra-registry' of github.com:brettmc/opentele…
brettmc Jan 9, 2025
4e3a60c
fix merge conflict
brettmc Jan 9, 2025
b3cd9f3
remove otlphttp transport factory, in favour of psr transport factory
brettmc Jan 9, 2025
0df5bcf
remove registerXXX methods from Registry
brettmc Jan 9, 2025
0708e47
move Registry to common/service/loader
brettmc Jan 9, 2025
4159f2e
Merge branch '2.x' into composer-extra-registry
brettmc Jan 10, 2025
01e7c70
add stdout exporters to SPI, remove otlphttp transport factory from SPI
brettmc Jan 10, 2025
24b72bd
use spi.prune_autoload_files=true where possible
brettmc Jan 10, 2025
e33845b
fix composer.json, add upgrading guide
brettmc Jan 10, 2025
7dbe592
simplify resource detector loading
brettmc Jan 13, 2025
b506de9
use _register.php to register SPI classes
brettmc Jan 13, 2025
9b96b79
use _register.php to register SPI classes
brettmc Jan 13, 2025
ed836e9
tidy up service loader
brettmc Jan 13, 2025
63264fd
simplify services loader code
brettmc Jan 13, 2025
4f24708
register and use API propagators through SPI
brettmc Jan 13, 2025
540243e
Merge branch 'composer-extra-registry' of github.com:brettmc/opentele…
brettmc Jan 13, 2025
b7b9ca1
filter out 'none' compression
brettmc Jan 13, 2025
ff3299c
update upgrading docs
brettmc Jan 13, 2025
b7af73d
move type() and priority() into a shared interface
brettmc Jan 13, 2025
a8fc516
factory test coverage
brettmc Jan 13, 2025
3e80235
tests, configure bypass-finals
brettmc Jan 13, 2025
93f25f8
coverage
brettmc Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,43 @@
"forward-command": true
},
"spi": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use extra.spi-config.autoload-files and remove the extra.spi entries to load the service providers from _register.phps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved most of these to an appropriate _register.php, excepting some test instances and the API's ExtensionHookManager...

"OpenTelemetry\\SDK\\Common\\Export\\TransportFactoryInterface": [
"OpenTelemetry\\SDK\\Common\\Export\\Http\\PsrTransportFactory",
"OpenTelemetry\\Contrib\\Otlp\\OtlpHttpTransportFactory",
"OpenTelemetry\\Contrib\\Grpc\\GrpcTransportFactory",
"OpenTelemetry\\SDK\\Common\\Export\\Stream\\StreamTransportFactory"
],
"OpenTelemetry\\SDK\\Trace\\SpanExporter\\SpanExporterFactoryInterface": [
"OpenTelemetry\\SDK\\Trace\\SpanExporter\\ConsoleSpanExporterFactory",
"OpenTelemetry\\SDK\\Trace\\SpanExporter\\InMemorySpanExporterFactory",
"OpenTelemetry\\Contrib\\Otlp\\SpanExporterFactory",
"OpenTelemetry\\Contrib\\Zipkin\\SpanExporterFactory"
],
"OpenTelemetry\\SDK\\Metrics\\MetricExporterFactoryInterface": [
"OpenTelemetry\\SDK\\Metrics\\MetricExporter\\InMemoryExporterFactory",
"OpenTelemetry\\SDK\\Metrics\\MetricExporter\\ConsoleMetricExporterFactory",
"OpenTelemetry\\SDK\\Metrics\\MetricExporter\\NoopMetricExporterFactory",
"OpenTelemetry\\Contrib\\Otlp\\MetricExporterFactory"
],
"OpenTelemetry\\SDK\\Logs\\LogRecordExporterFactoryInterface": [
"OpenTelemetry\\SDK\\Logs\\Exporter\\ConsoleExporterFactory",
"OpenTelemetry\\SDK\\Logs\\Exporter\\InMemoryExporterFactory",
"OpenTelemetry\\Contrib\\Otlp\\LogsExporterFactory"
],
"OpenTelemetry\\Context\\Propagation\\TextMapPropagatorFactoryInterface": [
"OpenTelemetry\\API\\Baggage\\Propagation\\BaggagePropagatorFactory",
"OpenTelemetry\\API\\Trace\\Propagation\\TraceContextPropagatorFactory",
"OpenTelemetry\\Context\\Propagation\\NoopTextMapPropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\B3\\B3PropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\B3\\B3MultiPropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\CloudTrace\\CloudTracePropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\CloudTrace\\CloudTraceOneWayPropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\Jaeger\\JaegerPropagatorFactory",
"OpenTelemetry\\Extension\\Propagator\\Jaeger\\JaegerBaggagePropagatorFactory"
],
"OpenTelemetry\\SDK\\Resource\\ResourceDetectorFactoryInterface": [
"OpenTelemetry\\Example\\TestResourceDetectorFactory"
],
"OpenTelemetry\\Config\\SDK\\Configuration\\ComponentProvider": [
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorB3",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Propagator\\TextMapPropagatorB3Multi",
Expand Down
10 changes: 10 additions & 0 deletions examples/autoload_sdk_with_custom_transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function forceFlush(?\OpenTelemetry\SDK\Common\Future\CancellationInterfa
}
};
}

public function type(): string
{
return 'grpc';
}

public function priority(): int
{
return 100;
}
};

\OpenTelemetry\SDK\Registry::registerTransportFactory('grpc', $factory, true);
Expand Down
3 changes: 1 addition & 2 deletions examples/src/ExampleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace OpenTelemetry\Example;

use Exception;
use OpenTelemetry\API\Configuration\ConfigProperties;
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Context as InstrumentationContext;
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\HookManagerInterface;
Expand All @@ -17,7 +16,7 @@ final class ExampleInstrumentation implements Instrumentation

public function register(HookManagerInterface $hookManager, ConfigProperties $configuration, InstrumentationContext $context): void
{
$config = $configuration->get(ExampleConfig::class) ?? throw new Exception('example instrumentation must be configured');
$config = $configuration->get(ExampleConfig::class) ?? new ExampleConfig('example');
if (!$config->enabled) {
return;
}
Expand Down
22 changes: 22 additions & 0 deletions examples/src/TestResourceDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Example;

use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;
use OpenTelemetry\SDK\Resource\ResourceInfo;
use OpenTelemetry\SemConv\ResourceAttributes;

class TestResourceDetector implements ResourceDetectorInterface
{
public function getResource(): ResourceInfo
{
$attributes = [
'test-resource' => 'test-value',
];

return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL);
}
}
27 changes: 27 additions & 0 deletions examples/src/TestResourceDetectorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Example;

use OpenTelemetry\SDK\Resource\ResourceDetectorFactoryInterface;
use OpenTelemetry\SDK\Resource\ResourceDetectorInterface;

class TestResourceDetectorFactory implements ResourceDetectorFactoryInterface
{

public function create(): ResourceDetectorInterface
{
return new TestResourceDetector();
}

public function type(): string
{
return 'test';
}

public function priority(): int
{
return 0;
}
}
9 changes: 7 additions & 2 deletions examples/traces/features/auto_root_span.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
use OpenTelemetry\API\Logs\LogRecord;

putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=console');
putenv('OTEL_TRACES_EXPORTER=otlp');
putenv('OTEL_METRICS_EXPORTER=none');
putenv('OTEL_LOGS_EXPORTER=console');
putenv('OTEL_LOGS_EXPORTER=otlp');
putenv('OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318');
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf');
putenv('OTEL_PROPAGATORS=tracecontext');
putenv('OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN=true');
putenv('OTEL_PHP_EXPERIMENTAL_SPI_REGISTRY=true');
putenv('OTEL_PHP_DETECTORS=sdk,test');
$_SERVER['REQUEST_METHOD'] = 'GET';

//Usage: php -S localhost:8080 examples/traces/features/auto_root_span.php

Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ parameters:
-
message: "#.*return with type T is not subtype.*#"
paths:
- src/SDK/Common/InstrumentationScope
- src/SDK/Common/InstrumentationScope
-
message: "#.*array_multisort.*#"
paths:
- src/SDK/Registry
6 changes: 6 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="GMP"/>
<file name="src/SDK/Registry.php"/>
</errorLevel>
</UndefinedClass>
<UndefinedFunction>
Expand Down Expand Up @@ -57,5 +58,10 @@
<directory name="src/Config/SDK/ComponentProvider"/>
</errorLevel>
</InvalidDocblock>
<InvalidPropertyAssignmentValue>
<errorLevel type="suppress">
<file name="src/SDK/Registry.php"/>
</errorLevel>
</InvalidPropertyAssignmentValue>
</issueHandlers>
</psalm>
26 changes: 26 additions & 0 deletions src/API/Baggage/Propagation/BaggagePropagatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\API\Baggage\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;

class BaggagePropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
{
return BaggagePropagator::getInstance();
}

public function type(): string
{
return 'baggage';
}

public function priority(): int
{
return 0;
}
}
26 changes: 26 additions & 0 deletions src/API/Trace/Propagation/TraceContextPropagatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\API\Trace\Propagation;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;

class TraceContextPropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
{
return TraceContextPropagator::getInstance();
}

public function type(): string
{
return 'tracecontext';
}

public function priority(): int
{
return 0;
}
}
23 changes: 23 additions & 0 deletions src/Context/Propagation/NoopTextMapPropagatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Context\Propagation;

class NoopTextMapPropagatorFactory implements TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface
{
return NoopTextMapPropagator::getInstance();
}

public function type(): string
{
return 'none';
}

public function priority(): int
{
return 0;
}
}
12 changes: 12 additions & 0 deletions src/Context/Propagation/TextMapPropagatorFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Context\Propagation;

interface TextMapPropagatorFactoryInterface
{
public function create(): TextMapPropagatorInterface;
public function type(): string;
public function priority(): int;
}
10 changes: 10 additions & 0 deletions src/Contrib/Grpc/GrpcTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@ private static function fileGetContents(?string $file): ?string

return $content;
}

public function type(): string
{
return 'grpc';
}

public function priority(): int
{
return 0;
}
}
10 changes: 10 additions & 0 deletions src/Contrib/Otlp/LogsExporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function create(): LogRecordExporterInterface
return new LogsExporter($this->buildTransport($protocol));
}

public function type(): string
{
return 'otlp';
}

public function priority(): int
{
return 0;
}

/**
* @psalm-suppress UndefinedClass
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Contrib/Otlp/MetricExporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public function create(): MetricExporterInterface
return new MetricExporter($this->buildTransport($protocol), $temporality);
}

public function type(): string
{
return 'otlp';
}

public function priority(): int
{
return 0;
}

/**
* @psalm-suppress UndefinedClass
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Contrib/Otlp/OtlpHttpTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ public function create(
return (new PsrTransportFactory())
->create($endpoint, $contentType, $headers, $compression, $timeout, $retryDelay, $maxRetries, $cacert, $cert, $key);
}

public function type(): string
{
return 'http';
}

public function priority(): int
{
return 0;
}
}
9 changes: 9 additions & 0 deletions src/Contrib/Otlp/SpanExporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ private function getTimeout(): float

return $value/1000;
}

public function type(): string
{
return 'otlp';
}
public function priority(): int
{
return 0;
}
}
9 changes: 9 additions & 0 deletions src/Contrib/Zipkin/SpanExporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ public function create(): SpanExporterInterface

return new Exporter($transport);
}

public function type(): string
{
return 'zipkin';
}
public function priority(): int
brettmc marked this conversation as resolved.
Show resolved Hide resolved
{
return 0;
}
}
27 changes: 27 additions & 0 deletions src/Extension/Propagator/B3/B3MultiPropagatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Extension\Propagator\B3;

use OpenTelemetry\Context\Propagation\TextMapPropagatorFactoryInterface;
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;

class B3MultiPropagatorFactory implements TextMapPropagatorFactoryInterface
{

brettmc marked this conversation as resolved.
Show resolved Hide resolved
public function create(): TextMapPropagatorInterface
{
return B3Propagator::getB3MultiHeaderInstance();
}

public function type(): string
{
return 'b3multi';
}

public function priority(): int
{
return 0;
}
}
Loading