Skip to content

[otlp] Add foundation for signal-specific envvars#5429

Merged
CodeBlanch merged 7 commits into
open-telemetry:mainfrom
CodeBlanch:otlp-exporter-options-signal-specific
Mar 11, 2024
Merged

[otlp] Add foundation for signal-specific envvars#5429
CodeBlanch merged 7 commits into
open-telemetry:mainfrom
CodeBlanch:otlp-exporter-options-signal-specific

Conversation

@CodeBlanch
Copy link
Copy Markdown
Member

@CodeBlanch CodeBlanch commented Mar 8, 2024

[Originally part of #5400]

Changes

  • Adds a code path for configuring OtlpExporterOptions using signal-specific spec envvars. Note: This is NOT currently utilized meaning AddOtlpExporter extension does NOT gain the ability to use these as of this PR.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated

@CodeBlanch CodeBlanch added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Mar 8, 2024
@CodeBlanch CodeBlanch requested a review from a team March 8, 2024 21:45
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 98.27586% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 84.78%. Comparing base (6250307) to head (f1f1d15).
Report is 123 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5429      +/-   ##
==========================================
+ Coverage   83.38%   84.78%   +1.39%     
==========================================
  Files         297      282      -15     
  Lines       12531    12170     -361     
==========================================
- Hits        10449    10318     -131     
+ Misses       2082     1852     -230     
Flag Coverage Δ
unittests ?
unittests-Solution-Experimental 84.54% <98.27%> (?)
unittests-Solution-Stable 84.74% <98.27%> (?)

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

Files Coverage Δ
...nTelemetryProtocol/OtlpMetricExporterExtensions.cs 99.00% <100.00%> (ø)
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 96.93% <98.21%> (+0.57%) ⬆️

... and 57 files with indirect coverage changes

Comment thread src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs Outdated
OtlpSpecConfigDefinitions.TracesHeadersEnvVarName,
OtlpSpecConfigDefinitions.TracesTimeoutEnvVarName);
}
else
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove this code if we don't expect it to called?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is a defensive thing. This code is here to alert a future dev who might add a new definition to OtlpExporterOptionsConfigurationType that they need to update this code in order for things to work.

var options = new OtlpExporterOptions();

Assert.Equal(new Uri("http://localhost:4317"), options.Endpoint);
Assert.Equal(new Uri(OtlpExporterOptions.DefaultGrpcEndpoint), options.Endpoint);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's better to use the hardcoded string "http://localhost:4317" for the test instead of relying on the constant defined in src file otherwise the test would never complain even if the constant defined in the src file accidentally gets changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We've debated this before 🤣 I subscribe to the DRY/single source of truth principle. If a dev wants to change the value, it should be defined in a single spot. If a dev changes the constant sure the tests might break. Or that dev could just update the tests too. Either case it is going to have to pass code review. Have we encountered issues with people trying to change our constants to be incorrect?

Copy link
Copy Markdown
Contributor

@utpilla utpilla Mar 11, 2024

Choose a reason for hiding this comment

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

Either case it is going to have to pass code review. Have we encountered issues with people trying to change our constants to be incorrect?

I feel, when possible, having unit tests that signal someone that they messed up is better. It's much quicker than the issue being caught in a PR review. It also slightly reduces the burden on the reviewer.

We've debated this before 🤣

Haha yes. I remember now. I'll leave this up to you. It's kind of similar to why we would want to keep this check. We don't expect anyone to add another signal type and any future dev who tries to add it should be informed not to do so in the code review 😀

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either case it is going to have to pass code review. Have we encountered issues with people trying to change our constants to be incorrect?

I feel, when possible, having unit tests that signal someone that they messed up is better. It's much quicker than the issue being caught in a PR review. It also slightly reduces the burden on the reviewer.

+1, I don't have super strong opinion here, but my preference is: if there is a behavior change in the production code, it should be caught by unit test. In other words, if a dev wants to make a behavior change, both production code and unit test code need to be updated.

Environment.SetEnvironmentVariable(OtlpExporterSpecEnvVarKeyDefinitions.DefaultProtocolEnvVarName, "invalid");
var values = new Dictionary<string, string>()
{
["InvalidEndpoint"] = "invalid",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we testing the behavior for invalid keys? This test was meant to test the behavior with invalid values, right? We would never provide invalid key names as parameters for ApplyConfigurationUsingSpecificationEnvVars anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry those names were kind of misleading. There is nothing invalid about the names, only the values. I just tweaked the names so it should be less confusing now.

@CodeBlanch CodeBlanch merged commit 8593365 into open-telemetry:main Mar 11, 2024
@CodeBlanch CodeBlanch deleted the otlp-exporter-options-signal-specific branch March 11, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants