Skip to content

Commit

Permalink
use SPI to configure registry
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Oct 22, 2024
1 parent abd9944 commit 43ebe82
Show file tree
Hide file tree
Showing 43 changed files with 599 additions and 143 deletions.
108 changes: 37 additions & 71 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,84 +117,50 @@
"ext-yaml": "Allows loading config from yaml files",
"symfony/yaml": "Allows loading config from yaml files"
},
"scripts": {
"pre-autoload-dump": "OpenTelemetry\\SDK\\ComposerRegistry::generate"
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"target-directory": "vendor-bin",
"forward-command": true
},
"opentelemetry": {
"registry": {
"OpenTelemetry\\SDK\\Common\\Export\\TransportFactoryInterface": {
"http": "OpenTelemetry\\Contrib\\Otlp\\OtlpHttpTransportFactory",
"grpc": "OpenTelemetry\\Contrib\\Grpc\\GrpcTransportFactory",
"stream": "OpenTelemetry\\SDK\\Common\\Export\\Stream\\StreamTransportFactory"
},
"OpenTelemetry\\SDK\\Trace\\SpanExporter\\SpanExporterFactoryInterface": {
"console": "OpenTelemetry\\SDK\\Trace\\SpanExporter\\ConsoleSpanExporterFactory",
"memory": "OpenTelemetry\\SDK\\Trace\\SpanExporter\\InMemorySpanExporterFactory",
"stream": "OpenTelemetry\\SDK\\Common\\Export\\Stream\\StreamTransportFactory",
"otlp": "OpenTelemetry\\Contrib\\Otlp\\SpanExporterFactory",
"zipkin": "OpenTelemetry\\Contrib\\Zipkin\\SpanExporterFactory"
},
"OpenTelemetry\\SDK\\Metrics\\MetricExporterFactoryInterface": {
"memory": "OpenTelemetry\\SDK\\Metrics\\MetricExporter\\InMemoryExporterFactory",
"console": "OpenTelemetry\\SDK\\Metrics\\MetricExporter\\ConsoleMetricExporterFactory",
"none": "OpenTelemetry\\SDK\\Metrics\\MetricExporter\\NoopMetricExporterFactory",
"otlp": "OpenTelemetry\\Contrib\\Otlp\\MetricExporterFactory"
},
"OpenTelemetry\\Context\\Propagation\\TextMapPropagatorInterface": {
"baggage": [
"OpenTelemetry\\API\\Baggage\\Propagation\\BaggagePropagator",
"getInstance"
],
"tracecontext": [
"OpenTelemetry\\API\\Trace\\Propagation\\TraceContextPropagator",
"getInstance"
],
"none": [
"OpenTelemetry\\Context\\Propagation\\NoopTextMapPropagator",
"getInstance"
],
"b3": [
"OpenTelemetry\\Extension\\Propagator\\B3\\B3Propagator",
"getB3SingleHeaderInstance"
],
"b3multi": [
"OpenTelemetry\\Extension\\Propagator\\B3\\B3Propagator",
"getB3MultiHeaderInstance"
],
"cloudtrace": [
"OpenTelemetry\\Extension\\Propagator\\CloudTrace\\CloudTracePropagator",
"getInstance"
],
"cloudtrace-oneway": [
"OpenTelemetry\\Extension\\Propagator\\CloudTrace\\CloudTracePropagator",
"getOneWayInstance"
],
"jaeger": [
"OpenTelemetry\\Extension\\Propagator\\Jaeger\\JaegerPropagator",
"getInstance"
],
"jaeger-baggage": [
"OpenTelemetry\\Extension\\Propagator\\Jaeger\\JaegerBaggagePropagator",
"getInstance"
]
},
"OpenTelemetry\\SDK\\Logs\\LogRecordExporterFactoryInterface": {
"console": "OpenTelemetry\\SDK\\Logs\\Exporter\\ConsoleExporterFactory",
"memory": "OpenTelemetry\\SDK\\Logs\\Exporter\\InMemoryExporterFactory",
"otlp": "OpenTelemetry\\Contrib\\Otlp\\LogsExporterFactory"
},
"OpenTelemetry\\SDK\\Resource\\ResourceDetectorInterface": {
"test": "OpenTelemetry\\Example\\TestResourceDetector"
}
}
},
"spi": {
"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
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;
}
}
5 changes: 3 additions & 2 deletions examples/traces/features/auto_root_span.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf');
putenv('OTEL_PROPAGATORS=tracecontext');
putenv('OTEL_PHP_EXPERIMENTAL_AUTO_ROOT_SPAN=true');
putenv('OTEL_PHP_EXPERIMENTAL_JSON_REGISTRY=true');
putenv('OTEL_PHP_DETECTORS=all');
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;
}
}
Loading

0 comments on commit 43ebe82

Please sign in to comment.