open-telemetry / opentelemetry-dotnet

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

[sdk] ConcurrencyMode and export processor registration APIs #5758

Closed CodeBlanch closed 1 month ago

CodeBlanch commented 2 months ago

Relates to #5642 Relates to #5643

Changes

Details

ConcurrencyModes

We want to allow users (component authors) to be able to opt-out of the lock used by SimpleExportProcessor. @reyang introduced ConcurrencyModes on #5643 but the challenge there is SimpleExportProcessor<T> needs to implement all the logic which makes it a) not very simple and b) more expensive (perf-wise). The goal here was to support ConcurrencyModes but in a way where we could specialize the implementation(s) without leaking them into public APIs. There could also be more ConcurrencyModes in the future for example Global was originally in the design which uses an OS-level synchronization mechanism and further complicates SimpleExportProcessor<T>.

AddBatchExportProcessor and AddSimpleExportProcessor extensions

Mistakes have been made in the design of BatchExportProcessor<T>. Users (component authors) must correctly pass in settings on the ctor. Those settings should be controllable by users. Some exporters do this manually (OneCollector), some do it using BatchExportActivityProcessorOptions (Geneva), and some don't give users any configurability at all (AzureMonitor).

Adding AddBatchExportProcessor and AddSimpleExportProcessor extensions allow the SDK to take care of this so it is always done correctly and gives it a spot to inspect ConcurrencyMode to select the correct implementation to use when SimpleExportProcessor<T> is requested.

Implement IDeferredLoggerProviderBuilder on OpenTelemetryLoggerOptions

In 1.9.0 we exposed LoggerProviderBuilder which is where the new extensions landed. The problem is we also have OpenTelemetryLoggerOptions and a lot of shipped registration extensions targeting it which need to create simple or batch processors. I really didn't want to add new builder methods on OpenTelemetryLoggerOptions as we ought to obsolete the existing ones. What I did was implement IDeferredLoggerProviderBuilder on OpenTelemetryLoggerOptions so that component authors can access the LoggerProviderBuilder extensions if needed. This is an explicit implementation so it is hidden from users unless they perform a cast. Is this safe to do? Yes. OpenTelemetryLoggerOptions can perform all the late-bound builder tasks because it has the IServiceProvider available. It just can't do the early stuff which needs IServiceCollection. So it may be IDeferredLoggerProviderBuilder but it can't be ILoggerProviderBuilder.

Follow-up work

PeriodicExportingMetricReader is really subject to the same pitfalls as BatchExportProcessor<T> but that isn't addressed here. If this goes forward similar work will need to happen for it. Probably an extension on MeterProviderBuilder along the lines of AddPeriodicExportingMetricReader.

Merge requirement checklist

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 76.01246% with 77 lines in your changes missing coverage. Please review.

Project coverage is 86.00%. Comparing base (6250307) to head (898c1a8). Report is 285 commits behind head on main.

Files Patch % Lines
...ry/Logs/Builder/LoggerProviderBuilderExtensions.cs 57.14% 21 Missing :warning:
...y/Trace/Builder/TracerProviderBuilderExtensions.cs 69.38% 15 Missing :warning:
...porter.Console/ConsoleExporterLoggingExtensions.cs 0.00% 9 Missing :warning:
...xporter.Console/ConsoleExporterHelperExtensions.cs 0.00% 8 Missing :warning:
...penTelemetry/SimpleMultithreadedExportProcessor.cs 0.00% 8 Missing :warning:
...ssor/SimpleMultithreadedActivityExportProcessor.cs 0.00% 6 Missing :warning:
src/OpenTelemetry/ConcurrencyModesAttribute.cs 54.54% 5 Missing :warning:
...lemetry/Logs/ILogger/OpenTelemetryLoggerOptions.cs 72.22% 5 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758/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/5758?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 #5758 +/- ## ========================================== + Coverage 83.38% 86.00% +2.62% ========================================== Files 297 261 -36 Lines 12531 11319 -1212 ========================================== - Hits 10449 9735 -714 + Misses 2082 1584 -498 ``` | [Flag](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758/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/5758/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/5758/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `85.95% <76.01%> (?)` | | | [unittests-Project-Stable](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `85.97% <76.01%> (?)` | | 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](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [...orter.InMemory/InMemoryExporterHelperExtensions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.InMemory%2FInMemoryExporterHelperExtensions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuSW5NZW1vcnkvSW5NZW1vcnlFeHBvcnRlckhlbHBlckV4dGVuc2lvbnMuY3M=) | `100.00% <100.00%> (ø)` | | | [...rter.InMemory/InMemoryExporterLoggingExtensions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.InMemory%2FInMemoryExporterLoggingExtensions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuSW5NZW1vcnkvSW5NZW1vcnlFeHBvcnRlckxvZ2dpbmdFeHRlbnNpb25zLmNz) | `100.00% <100.00%> (+33.33%)` | :arrow_up: | | [...enTelemetryProtocol/Builder/OtlpExporterBuilder.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?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%> (ø)` | | | [...etryProtocol/Builder/OtlpExporterBuilderOptions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FBuilder%2FOtlpExporterBuilderOptions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL0J1aWxkZXIvT3RscEV4cG9ydGVyQnVpbGRlck9wdGlvbnMuY3M=) | `100.00% <100.00%> (ø)` | | | [...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FOtlpExporterOptions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL090bHBFeHBvcnRlck9wdGlvbnMuY3M=) | `99.09% <100.00%> (+2.72%)` | :arrow_up: | | [...lemetryProtocol/OtlpLogExporterHelperExtensions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FOtlpLogExporterHelperExtensions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL090bHBMb2dFeHBvcnRlckhlbHBlckV4dGVuc2lvbnMuY3M=) | `94.64% <100.00%> (+23.57%)` | :arrow_up: | | [...metryProtocol/OtlpTraceExporterHelperExtensions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.OpenTelemetryProtocol%2FOtlpTraceExporterHelperExtensions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuT3BlblRlbGVtZXRyeVByb3RvY29sL090bHBUcmFjZUV4cG9ydGVySGVscGVyRXh0ZW5zaW9ucy5jcw==) | `98.76% <100.00%> (+2.09%)` | :arrow_up: | | [....Exporter.Zipkin/ZipkinExporterHelperExtensions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.Zipkin%2FZipkinExporterHelperExtensions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuWmlwa2luL1ppcGtpbkV4cG9ydGVySGVscGVyRXh0ZW5zaW9ucy5jcw==) | `100.00% <100.00%> (+1.81%)` | :arrow_up: | | [...Telemetry.Exporter.Zipkin/ZipkinExporterOptions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry.Exporter.Zipkin%2FZipkinExporterOptions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXhwb3J0ZXIuWmlwa2luL1ppcGtpbkV4cG9ydGVyT3B0aW9ucy5jcw==) | `100.00% <100.00%> (ø)` | | | [src/OpenTelemetry/BatchExportProcessorOptions.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree&filepath=src%2FOpenTelemetry%2FBatchExportProcessorOptions.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkvQmF0Y2hFeHBvcnRQcm9jZXNzb3JPcHRpb25zLmNz) | `100.00% <100.00%> (ø)` | | | ... and [11 more](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | | ... and [196 files with indirect coverage changes](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5758/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)
github-actions[bot] commented 1 month ago

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

github-actions[bot] commented 1 month ago

Closed as inactive. Feel free to reopen if this PR is still being worked on.