-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-instrumentation registration (#1304)
* [WIP] Add instrumentation configuration * add autoloading for auto-instrumentations using SPI * allow autoloading and non-autoloading to work * fix attribute * experimental config file * fixing invalid dependencies - deptrac was rightly complaining that API (indirectly) depended on SDK through config/sdk. For now, remove usage of Config\SDK\Configuration\Context - update deptrac config to allow some new dependencies * dont register hook manager globally or in sdk * remove unused function, psalm ignore missing extension function * possibly fixing type-hint psalm doesn't complain now, so that should be good * load config files relative to cwd * fixing hook manager enable/disable + psalm complaints * fixing 8.1 psalm error * use context to pass providers to instrumentations - make "register global" a function of Sdk, but keep the sdk builder's interface intact - invent an API instrumentation context, similar to the one in config/sdk, to pass providers to instrumentations - add an initial test of autoloading from a config file * adding tests for sdk::registerGlobal in passing, remove some dead code for handling invalid booleans - config already handles this correctly * linting * test coverage for globals * add opentelemetry extension to developer image and actions * always register instrumentations via SPI * register globals initializer for file-config sdk allow SDK created from config file to coexist with components using globals initializer * linting * remove globals init function * fix phan warning * simplify hook manager - drop storage from hook manager: can't guarantee that something else, eg swoole, won't modify storage - drop context from hook manager: we must lazy-load globals via initializers, because not all instrumentations use SPI (although that may change in future) - default hook manager to enabled * add todo to deprecate Registry in future * autoload instrumentations without config if no config provided, still try to load them. wrap registration in a try/catch/log * fixing phan ref, update doc * remove phan suppress * fix example * bump SPI to 0.2.1 * adding late-binding tracer+provider per review from Nevay, this will allow instrumentations to get things from Globals as late as possible * adding late binding logger and meter providers * more late binding test coverage * tidy * dont use CoversMethod yet not available in phpunit 10, so comment out and leave a todo * kitchen sink, remove unused var * instrumentation config as a map, per config file spec * adding general config * move general config into sdk * test config caching * move general instrumentation config to api * avoid bad version of sebastian/exporter * bump config yaml files to 0.3 * fix tests * disable hook manager during file-based init * cleanup * support multiple config files in autoloader * move hook manager enable/disable out of extension hook manager The most obvious place to do this is in a class named HookManager, which _was_ an interface for hook managers. Rename existing HookManager to HookManagerInterface, then re-purpose HookManager for globally enabling/disabling hook managers as well as determining the disabled status. * update spi config --------- Co-authored-by: Tobias Bachert <[email protected]>
- Loading branch information
Showing
10 changed files
with
294 additions
and
25 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
ComponentProvider/Instrumentation/General/HttpConfigProvider.php
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,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Instrumentation\General; | ||
|
||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\GeneralInstrumentationConfiguration; | ||
use OpenTelemetry\API\Instrumentation\Configuration\General\HttpConfig; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry; | ||
use OpenTelemetry\Config\SDK\Configuration\Context; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @implements ComponentProvider<GeneralInstrumentationConfiguration> | ||
*/ | ||
class HttpConfigProvider implements ComponentProvider | ||
{ | ||
|
||
public function createPlugin(array $properties, Context $context): GeneralInstrumentationConfiguration | ||
{ | ||
return new HttpConfig($properties); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition | ||
{ | ||
$node = new ArrayNodeDefinition('http'); | ||
$node | ||
->children() | ||
->append($this->capturedHeaders('client')) | ||
->append($this->capturedHeaders('server')) | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
|
||
private function capturedHeaders(string $name): ArrayNodeDefinition | ||
{ | ||
$node = new ArrayNodeDefinition($name); | ||
$node | ||
->children() | ||
->arrayNode('request_captured_headers') | ||
->scalarPrototype()->end() | ||
->end() | ||
->arrayNode('response_captured_headers') | ||
->scalarPrototype()->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ComponentProvider/Instrumentation/General/PeerConfigProvider.php
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider\Instrumentation\General; | ||
|
||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\GeneralInstrumentationConfiguration; | ||
use OpenTelemetry\API\Instrumentation\Configuration\General\PeerConfig; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry; | ||
use OpenTelemetry\Config\SDK\Configuration\Context; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @implements ComponentProvider<GeneralInstrumentationConfiguration> | ||
*/ | ||
class PeerConfigProvider implements ComponentProvider | ||
{ | ||
public function createPlugin(array $properties, Context $context): GeneralInstrumentationConfiguration | ||
{ | ||
return new PeerConfig($properties); | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition | ||
{ | ||
$node = new ArrayNodeDefinition('peer'); | ||
$node | ||
->children() | ||
->arrayNode('service_mapping') | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('peer')->end() | ||
->scalarNode('service')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
ComponentProvider/InstrumentationConfigurationRegistry.php
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Config\SDK\ComponentProvider; | ||
|
||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\ConfigurationRegistry; | ||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\GeneralInstrumentationConfiguration; | ||
use OpenTelemetry\API\Instrumentation\AutoInstrumentation\InstrumentationConfiguration; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentPlugin; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider; | ||
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry; | ||
use OpenTelemetry\Config\SDK\Configuration\Context; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @internal | ||
* @todo In a future release, when all instrumentations use SPI (and not autoload.files), this could be moved into {@see OpenTelemetrySdk}> | ||
* @implements ComponentProvider<ConfigurationRegistry> | ||
*/ | ||
class InstrumentationConfigurationRegistry implements ComponentProvider | ||
{ | ||
/** | ||
* @param array{ | ||
* instrumentation: array{ | ||
* php: list<ComponentPlugin<InstrumentationConfiguration>>, | ||
* general: list<ComponentPlugin<InstrumentationConfiguration>> | ||
* } | ||
* } $properties | ||
*/ | ||
public function createPlugin(array $properties, Context $context): ConfigurationRegistry | ||
{ | ||
$configurationRegistry = new ConfigurationRegistry(); | ||
/** @phpstan-ignore-next-line */ | ||
foreach ($properties['instrumentation']['php'] ?? [] as $configuration) { | ||
$configurationRegistry->add($configuration->create($context)); | ||
} | ||
/** @phpstan-ignore-next-line */ | ||
foreach ($properties['instrumentation']['general'] ?? [] as $configuration) { | ||
$configurationRegistry->add($configuration->create($context)); | ||
} | ||
|
||
return $configurationRegistry; | ||
} | ||
|
||
public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition | ||
{ | ||
$root = new ArrayNodeDefinition('open_telemetry'); | ||
$root | ||
->ignoreExtraKeys() | ||
->children() | ||
->arrayNode('instrumentation') | ||
->ignoreExtraKeys() | ||
->children() | ||
->append($registry->componentList('php', InstrumentationConfiguration::class)) | ||
->append($registry->componentList('general', GeneralInstrumentationConfiguration::class)) | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
return $root; | ||
} | ||
} |
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
Oops, something went wrong.