[sdk-logs] Introduce OpenTelemetryLoggingBuilder (proposal 4) #4506
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #4433
Relates to #4502
Changes
OpenTelemetryLoggingBuilder
as the thing returned by theILoggingBuilder.AddOpenTelemetry
extensionLoggerProviderBuilder.ConfigureLoggerOptions
extension for configuringOpenTelemetryLoggerOptions
Details
Today we configure logging like this:
"options" is
OpenTelemetryLoggerOptions
class.Now the OpenTelemetry Specification has
LoggerProvider
and we have aLoggerProviderBuilder
API. The SDKLoggerProvider
is fed into theILogger
integration (OpenTelemetryLoggerProvider
).There are different ways we could approach this. Today we have extensions for logging that target
OpenTelemetryLoggerOptions
. We will need to targetLoggerProviderBuilder
now. We could forever have two versions of every extension, but that seems lame.This PR is adding a new class
OpenTelemetryLoggingBuilder
to try and bridge the two worlds. Previously theILoggingBuilder.AddOpenTelemetry
extension returned theILoggingBuilder
passed into the call. Now it returnsOpenTelemetryLoggingBuilder
which implementsILoggingBuilder
. This shouldn't be a source breaking change. It may be a binary breaking change, need to investigate that.OpenTelemetryLoggerOptions.AddProcessor
andOpenTelemetryLoggerOptions.SetResourceBuilder
methods would be obsoleted as would our existing extensions onOpenTelemetryLoggerOptions
.All of these styles can be interchanged.
Considerations
Today you can do this:
Which is to chain calls on the
ILoggerBuilder
.The signature of
OpenTelemetryLoggingBuilder
hasOpenTelemetryLoggingBuilder : LoggerProviderBuilder, ILoggingBuilder
. The reason for implementingILoggingBuilder
is so that the above code does not break on upgrade.If users update their code like this...
Basically they will have to reorder things.
Or
Merge requirement checklist