-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use SPI to manage components (#1412)
To resolve our long-standing race conditions stemming from using composer's autoload->files to registry SDK components at runtime, this changes things so that: - components are registerd in various _register.php files, and SPI is used to remove those files from autoload->files - the SDK Registry is removed, replaced by an internal service loader which interacts with SPI similarly to how the Registry did
- Loading branch information
Showing
106 changed files
with
1,192 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
deptrac: | ||
skip_violations: | ||
/src/Extension/Propagator/B3/_register.php: | ||
- OpenTelemetry\SDK\Registry | ||
/src/Extension/Propagator/CloudTrace/_register.php: | ||
- OpenTelemetry\SDK\Registry | ||
/src/Extension/Propagator/Jaeger/_register.php: | ||
- OpenTelemetry\SDK\Registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ deptrac: | |
SDK: | ||
- +API | ||
- ConfigSDK | ||
- Extension | ||
- SemConv | ||
- PsrHttp | ||
- HttpPlug | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Upgrading notes for major versions | ||
|
||
## 1.x -> 2.x | ||
|
||
### SDK | ||
|
||
#### SDK\Registry removed | ||
`SDK\Registry` has been removed, and the technique of registering components (eg propagators, transports, | ||
auto-instrumentations) has been replaced with [Nevay/SPI](https://github.com/Nevay/spi/) ServiceLoader. | ||
|
||
The ServiceLoader should be configured through existing `_register.php` files, which should *only* contain calls to | ||
SPI's `ServiceLoader::register()` method. | ||
|
||
SPI has a composer plugin which will scan for `ServiceLoader::register()` calls in `autoload.files` and generate a | ||
`GeneratedServiceProviderData.php` file in `vendor/composer/`. The plugin will then remove those `autoload.files` entries | ||
from composer's generated output to avoid double-loading. | ||
Pre-generating the services in this way avoids a race-condition in 1.x where composer's `autoload.files` are executed in an | ||
undefined order, and services may not be registered in time for the SDK to use them. | ||
|
||
For SPI to work correctly, the composer plugin _should_ be allowed to run. If the plugin is not allowed to run, then | ||
services will still register at runtime, however this might still suffer from the same race-condition as `1.x`. | ||
|
||
#### FactoryInterfaces updated | ||
Various component factory interfaces (eg `TextMapPropagatorFactoryInterface`, `TransportFactoryInterface`) have been | ||
updated to include `priority()` and `type()` methods. These are used in conjunction with SPI ServiceLoader to associate | ||
a type (eg `otlp`) with a factory, and to allow SDK-provided factories to be replaced by user-provided factories (by | ||
providing a higher priority for the same type). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nevay\SPI\ServiceLoader; | ||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\Instrumentation; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider; | ||
use OpenTelemetry\Example\ExampleConfigProvider; | ||
use OpenTelemetry\Example\ExampleInstrumentation; | ||
use OpenTelemetry\Example\TestResourceDetectorFactory; | ||
use OpenTelemetry\SDK\Resource\ResourceDetectorFactoryInterface; | ||
|
||
ServiceLoader::register(Instrumentation::class, ExampleInstrumentation::class); | ||
ServiceLoader::register(ResourceDetectorFactoryInterface::class, TestResourceDetectorFactory::class); | ||
ServiceLoader::register(ComponentProvider::class, ExampleConfigProvider::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nevay\SPI\ServiceLoader; | ||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\ExtensionHookManager; | ||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\HookManagerInterface; | ||
|
||
ServiceLoader::register(HookManagerInterface::class, ExtensionHookManager::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.