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

PoC: Configuration\CompositeResolver and SPI discovery #1523

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ChrisLightfootWild
Copy link
Contributor

@ChrisLightfootWild ChrisLightfootWild commented Mar 5, 2025

Proof of concept, to cover the use-case where multi-application installs operate on shared-infra and wish to provide their own configuration.

See #1436.


Any suggestions on the best way to approach adding tests for these optional dependencies?

use OpenTelemetry\SDK\Common\Configuration\Resolver\ResolverInterface;
use function str_starts_with;

#[PackageDependency('vlucas/phpdotenv', '^5.0')]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Nevay 👋

Speaking with @brettmc and he says you had some comments on .env processing n the past here. I did not recall this before throwing this together, apologies!

Do you have any concerns with delegating .env processing to the appropriately available packages via SPI?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I was only concerned about implementing our own .env parsing.

$env ??= array_filter(
Dotenv::createArrayBacked([getcwd()])->safeLoad(),
// Discard any environment variables that do not start with OTEL_
fn (string $name) => str_starts_with($name, 'OTEL_'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming that the same approach will be used for file configuration EnvReader:
IMO we shouldn't remove non-OTEL_ keys, users might want to reference them in their config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, I shall drop this filtering. 👍


try {
$env ??= array_filter(
Dotenv::createArrayBacked([getcwd()])->safeLoad(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use ::createImmutable() as .env might reference environment variables defined outside of the .env file. For example the following should work:

# .env
OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_LOG_LEVEL=${LOG_LEVEL}
LOG_LEVEL=debug php vendor/autoload.php

If using ::createImmutable(): should backup $_SERVER and $_ENV before reading the .env file to avoid visible side effects; I've decided to write an implementation too, see
Nevay/otel-sdk-config@d5be39f#diff-ba9503c0f072a1539d96dc365912b509cc45ce92648a7765c53a86c9419687a7 for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for highlighting this, I'm hoping it's okay that I port your improvements over?! 😅

@@ -60,6 +60,9 @@
"spi": {
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\HookManagerInterface": [
"OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\ExtensionHookManager"
],
"OpenTelemetry\\SDK\\Common\\Configuration\\Resolver\\ResolverInterface": [
"OpenTelemetry\\SDK\\Common\\Configuration\\Resolver\\SdkConfigurationResolver"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only kicks in when open-telemetry/sdk-configuration is available.

@@ -18,6 +19,7 @@ public static function instance(): self
{
static $instance;
$instance ??= new self([
...ServiceLoader::load(ResolverInterface::class),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This effectively replaces the below resolvers because it will use the ServerEnvSource & PhpIniEnvSource sources.

--

Should open-telemetry/sdk-configuration be promoted to the SDK rather than remain as an optional dependency? 🤔

Copy link

codecov bot commented Mar 16, 2025

Codecov Report

Attention: Patch coverage is 1.85185% with 53 lines in your changes missing coverage. Please review.

Project coverage is 70.50%. Comparing base (68462e0) to head (938c2f6).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...onfiguration/Resolver/SdkConfigurationResolver.php 0.00% 11 Missing ⚠️
src/Config/SDK/Configuration.php 0.00% 10 Missing ⚠️
src/Config/SDK/Instrumentation.php 0.00% 10 Missing ⚠️
...tion/Environment/Adapter/SymfonyDotenvProvider.php 0.00% 9 Missing ⚠️
...on/Environment/Adapter/VlucasPhpdotenvProvider.php 0.00% 7 Missing ⚠️
...ig/SDK/Configuration/Environment/LazyEnvSource.php 0.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1523      +/-   ##
============================================
- Coverage     70.76%   70.50%   -0.26%     
- Complexity     2763     2776      +13     
============================================
  Files           408      412       +4     
  Lines          8346     8392      +46     
============================================
+ Hits           5906     5917      +11     
- Misses         2440     2475      +35     
Flag Coverage Δ
8.1 70.25% <1.85%> (-0.24%) ⬇️
8.2 70.44% <1.85%> (-0.25%) ⬇️
8.3 70.38% <1.85%> (-0.32%) ⬇️
8.4 70.45% <1.85%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ommon/Configuration/Resolver/CompositeResolver.php 100.00% <100.00%> (ø)
...ig/SDK/Configuration/Environment/LazyEnvSource.php 0.00% <0.00%> (ø)
...on/Environment/Adapter/VlucasPhpdotenvProvider.php 0.00% <0.00%> (ø)
...tion/Environment/Adapter/SymfonyDotenvProvider.php 0.00% <0.00%> (ø)
src/Config/SDK/Configuration.php 0.00% <0.00%> (ø)
src/Config/SDK/Instrumentation.php 0.00% <0.00%> (ø)
...onfiguration/Resolver/SdkConfigurationResolver.php 0.00% <0.00%> (ø)

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68462e0...938c2f6. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

"bamarni/composer-bin-plugin": "^1.8",
"dg/bypass-finals": "^1.4",
"grpc/grpc": "^1.30",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort package config re-ordered this.

@ChrisLightfootWild ChrisLightfootWild marked this pull request as ready for review March 16, 2025 21:24
@ChrisLightfootWild ChrisLightfootWild requested a review from a team as a code owner March 16, 2025 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants