open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.23k stars 765 forks source link

[otlp] Workaround DI containers which create unregistered services #5808

Closed CodeBlanch closed 2 months ago

CodeBlanch commented 2 months ago

Fixes #5537 Fixes #5803

Changes

Merge requirement checklist

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 86.23%. Comparing base (6250307) to head (8c3a151). Report is 300 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/graphs/tree.svg?width=650&height=150&src=pr&token=vscyfvPfy5&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) ```diff @@ Coverage Diff @@ ## main #5808 +/- ## ========================================== + Coverage 83.38% 86.23% +2.84% ========================================== Files 297 257 -40 Lines 12531 11150 -1381 ========================================== - Hits 10449 9615 -834 + Misses 2082 1535 -547 ``` | [Flag](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `?` | | | [unittests-Project-Experimental](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.21% <100.00%> (?)` | | | [unittests-Project-Stable](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.14% <100.00%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [...enTelemetryProtocol/Builder/OtlpExporterBuilder.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FBuilder%2FOtlpExporterBuilder.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL0J1aWxkZXIvT3RscEV4cG9ydGVyQnVpbGRlci5jcw==) | `100.00% <100.00%> (ø)` | | | [...tryProtocol/Builder/UseOtlpExporterRegistration.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FBuilder%2FUseOtlpExporterRegistration.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL0J1aWxkZXIvVXNlT3RscEV4cG9ydGVyUmVnaXN0cmF0aW9uLmNz) | `100.00% <100.00%> (ø)` | | ... and [212 files with indirect coverage changes](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5808/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)
reyang commented 2 months ago

Do you think that it is worth to add some additional DI to our coverage?

+1, if this is a scenario we would support, a test case is needed.

CodeBlanch commented 2 months ago

Do you think that it is worth to add some additional DI to our coverage?

I commented about that a bit on here and we discussed somewhat on the SIG this week. Short answer is I feel like we should do something but I don't know what that something is 🤣 I don't feel a test in OtlpExporter project would be super useful. Because any dev at any time in this repo or contrib who introduces a serviceProvider.GetService(...) or serviceProvider.GetServices(...) call may run into this again. We would need coverage over everything using all known containers which exist or may exist in the future. Yuck!

I just spun up this issue in runtime to see if there might be a better way to do it or if some other safe way could be added: https://github.com/dotnet/runtime/issues/107153

secovel commented 2 months ago

What version can I expect to see this fix in? We need to get off 1.7.0 due to some vulnerability reports.