Skip to content

Conversation

@brettmc
Copy link
Contributor

@brettmc brettmc commented Jul 13, 2023

  • We have a need in some contrib packages to fetch configuration settings. Move the non-SDK-specific parts of Configuration into the API.
  • add the ability to fetch config from .env file

* We have a need in some contrib packages to fetch configuration settings. Move the non-SDK-specific parts
of Configuration into the API.
* add the ability to fetch config from .env file
@brettmc brettmc requested a review from a team July 13, 2023 02:52
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #1079 (0a22ea9) into main (cc92a07) will increase coverage by 0.05%.
The diff coverage is 89.18%.

❗ Current head 0a22ea9 differs from pull request most recent head 22d699e. Consider uploading reports for the commit 22d699e to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1079      +/-   ##
============================================
+ Coverage     81.67%   81.73%   +0.05%     
- Complexity     2187     2208      +21     
============================================
  Files           278      282       +4     
  Lines          6231     6284      +53     
============================================
+ Hits           5089     5136      +47     
- Misses         1142     1148       +6     
Flag Coverage Δ
7.4 80.39% <89.18%> (+0.07%) ⬆️
8.0 81.67% <89.18%> (+0.05%) ⬆️
8.1 81.80% <89.18%> (+0.05%) ⬆️
8.2 81.80% <89.18%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
src/API/Configuration/ClassConstantAccessor.php 100.00% <ø> (ø)
src/API/Configuration/Parser/BooleanParser.php 88.88% <ø> (ø)
src/API/Configuration/Parser/ListParser.php 87.50% <ø> (ø)
src/API/Configuration/Parser/MapParser.php 94.44% <ø> (ø)
src/API/Configuration/Parser/RatioParser.php 100.00% <ø> (ø)
...API/Configuration/Resolver/EnvironmentResolver.php 100.00% <ø> (ø)
src/API/Configuration/Resolver/PhpIniAccessor.php 0.00% <ø> (ø)
src/API/Configuration/Resolver/PhpIniResolver.php 100.00% <ø> (ø)
src/Contrib/Otlp/LogsExporterFactory.php 100.00% <ø> (ø)
src/Contrib/Otlp/MetricExporterFactory.php 97.77% <ø> (ø)
... and 32 more

... and 1 file 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 cc92a07...22d699e. Read the comment docs.

/**
* @psalm-internal \OpenTelemetry
*/
class ClassConstantAccessor
Copy link
Contributor

Choose a reason for hiding this comment

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

Only used in SDK Configuration -> can stay in SDK?

* Resolve variables from a `.env` file
* @psalm-internal \OpenTelemetry\API\Configuration
*/
class DotEnvResolver implements ResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should add this resolver, users that use .env files are likely already using vlucas/phpdotenv or symfony/dotenv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use-case I can think of is if you're using the SDK autoloading feature, including for auto-instrumentation. Since that all happens during composer autoloading, dotenv libraries won't have run yet.
That said, I don't have a strong opinion on having .env support or not, it just seemed like a quick win and potentially useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

The dotenv libraries seem to be more complex and handle more cases, I'm mainly concerned that the DotEnvResolver might only support a subset of the .env specification.

@Nevay
Copy link
Contributor

Nevay commented Jul 16, 2023

We have a need in some contrib packages to fetch configuration settings.

Do we need access to the configuration only within hooks or also before initializing hooks?
For the former I would prefer the usage of configuration objects that are injected into the instrumentation (via context or globally) instead of relying on Configuration directly, especially because some configuration options might be too complex to configure via environment variables.

@brettmc
Copy link
Contributor Author

brettmc commented Jul 16, 2023

Do we need access to the configuration only within hooks or also before initializing hooks?
For the former I would prefer the usage of configuration objects that are injected into the instrumentation (via context or globally) instead of relying on Configuration directly, especially because some configuration options might be too complex to configure via environment variables.

Right now, only within hooks. But I can imagine a need to have this configuration when initializing hooks: to be able to control which methods are observed. It might not make a big difference in reality, but I think that not observing a method would be more efficient than observing it but making it a no-op based on a check.

The problem I've got is this part of the spec: Instrumentation authors MUST NOT directly reference any SDK package of any kind, only the API.
I assume the creation of a Configuration object would be the responsibility of the SDK? That might work if there was an API ConfigurationInterface, and config was pulled from Context, such that you got a no-op config without an SDK.

Or, if it worked in the other direction, and there was a ConfigurationResolver in context, and a package requested config from the resolver.

There's also scope to have SIG-specific exclusions of parts of the spec, so we could decide to ignore that part of the spec.

edit: created draft PR #1083 which is simpler and avoids moving a heap of code into the API

@brettmc brettmc marked this pull request as draft July 18, 2023 00:08
@brettmc
Copy link
Contributor Author

brettmc commented Jul 24, 2023

Closing in favour of #1083

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