-
Notifications
You must be signed in to change notification settings - Fork 847
Fix: OtlpExporterOptions
is not picking up env variables
#6559
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
base: main
Are you sure you want to change the base?
Conversation
src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6559 +/- ##
==========================================
- Coverage 86.63% 86.62% -0.01%
==========================================
Files 258 258
Lines 11888 11892 +4
==========================================
+ Hits 10299 10302 +3
- Misses 1589 1590 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look reasonable.
Can you add a test that would fail without this change to protect against regressions in the future, and also update the CHANGELOG please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at #5586.. We should avoid adding AddEnvironmentVariables to the IConfiguration provider, since it's intended to be provided by the application.
dec8d51
to
5201850
Compare
I’ve added tests and updated the CHANGELOG. I just noticed that this change also fixes #5586, so I included a test case for it as well. |
Instead of adding |
5201850
to
a6574da
Compare
When environment variables are set after IConfiguration is built (during WebHost building), even though they are set before exporters are configured, OtlpExporterOptions does not pick them up. This patch fixes the issue.
…rOptions The internal constructor was only ever called from the public constructor, and the public constructor itself is only used in tests. This made it easy to assume the internal constructor was part of normal runtime scenarios, which could cause confusion. (in normal runtime scenarios, only the factory method `OtlpExporterOptions.CreateOtlpExporterOptions` is used) Removing it simplifies the code and avoids misleading readers.
it was used in tests
a6574da
to
b5f8bce
Compare
Maybe another way to achieve the same end result is to make the configuration ??= new ConfigurationBuilder().AddEnvironmentVariables().Build();
this.ApplyConfiguration(configuration, configurationType); |
The issue is that if Host doesn’t load environment variables into |
Does it not move the decision later in a way that is equivalent to before ("no |
The problematic case is "IConfiguration is provided, but no environment variables are in it". Also, when docs says it is configurable via environment variables, I think the implementation should do so. (not "if environment variables are set and if It would be ideal if |
Fixes #6558
Changes
Update the constructor to augment the provided IConfiguration with environment variables before applying it.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes