-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate registry from composer autoload-dump
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 registed in various composer.json files, under the extra.opentelemetry.registry key - a composer script is registered to write this config out to a JSON file - the SDK Registry is modified to make manually registering components a no-op (currently behind a flag, OTEL_PHP_EXPERIMENTAL_JSON_REGISTRY), and instead configure itself from the generated JSON file If we move ahead with this approach, a follow-up PR could tidy up the Registry and remove our various late-binding providers.
- Loading branch information
Showing
8 changed files
with
198 additions
and
2 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
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
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK; | ||
|
||
use Composer\Script\Event; | ||
use Composer\Util\Filesystem; | ||
|
||
class ComposerRegistry | ||
{ | ||
public const FILENAME = 'opentelemetry_registry.json'; | ||
|
||
/** | ||
* Generate a JSON file for the SDK registry from `composer.extra.opentelemetry.registry`, so that | ||
* all required factories etc can be registered immediately. | ||
*/ | ||
public static function generate(Event $event): void | ||
{ | ||
$composer = $event->getComposer(); | ||
$extra = $composer->getPackage()->getExtra(); | ||
$json = json_encode($extra['opentelemetry']['registry'], JSON_PRETTY_PRINT); | ||
$filesystem = new Filesystem(); | ||
$vendorDir = $filesystem->normalizePath($composer->getConfig()->get('vendor-dir')); | ||
$filesystem->ensureDirectoryExists($vendorDir . '/composer'); | ||
$filesystem->filePutContentsIfModified($vendorDir . '/composer/' . self::FILENAME, $json); | ||
} | ||
} |
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