-
Notifications
You must be signed in to change notification settings - Fork 765
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
[sdk-logs] Introduce ConfigureOpenTelemetry ILoggingBuilder extension (proposal 1) #4496
[sdk-logs] Introduce ConfigureOpenTelemetry ILoggingBuilder extension (proposal 1) #4496
Conversation
This got a bit longer than I originally imagined :) Hopefully its useful though. Potential alternative APIWhat do you think of this alternative? // Configure OTel via ILoggingBuilder
appBuilder.Logging
.SendToOpenTelemetry(builder => builder
.AddConsoleExporter()
.ConfigureLoggerOptions(options => options.IncludeFormattedMessage = true)); // Configure OTel via OpenTelemetryBuilder
appBuilder.Services
.AddOpenTelemetry()
.WithLogging(builder => builder
.AddConsoleExporter()
.ConfigureLoggerOptions(options => options.IncludeFormattedMessage = true)); // Configure OTel via OpenTelemetryBuilder
appBuilder.Services
.AddOpenTelemetry()
.WithLogging(builder => builder.AddConsoleExporter());
// Configure ILogger options via Options API
appBuilder.Services.Configure<OpenTelemetryLoggerOptions>(options => options.IncludeFormattedMessage = true); At the implementation level I am imagining you would mark ILoggingBuilder.AddOpenTelemetry() obsolete or just recommend Assuming the runtime adds MetricsBuilder and DistributedTracingBuilder in the future then I am imagining the // In the future this would work:
appBuilder.Logging.SendToOpenTelemetry(otelLoggingBuilder => ...);
appBuilder.Metrics.SendToOpenTelemetry(otelMetricsBuilder => ...);
appBuilder.DistributedTracing.SendToOpenTelemetry(otelTracingBuilder => ...);
// Though I still hope we can get this pattern supported as well because it allows for
// less duplication setting up each signal. This is what I would recommend in examples:
services.AddOpenTelemetry(builder => builder
.AddConsoleExporter()
.SetResource(...)
.WithLogging()
.WithMetrics()
.WithTracing() DefaultsAs an orthogonal issue, if WithLogging() is automatically subscribing to LoggingBuilder I think it would set a precedent that devs would expect WithMetrics() and WithTracing() should automatically subscribe to MetricsBuilder and DistributedTracingBuilder if/when those exist in the future. I think that kind of default would be nice, but it does mean:
If either of those behaviors are worrisome then you might want to go the other way set the precedent that data coming from LoggingBuilder is off-by-default when calling WithLogging(). Then devs would enable it either by calling an extension method on LoggingBuilder (AddOpenTelemetry, SendToOpenTelemetry, ConfigureOpenTelemetry, etc), or via some other switch on the OTel API surface. In a future off-by-default world an example might look like this: // Option A - opt-in using SendToOpenTelemetry() (or alternate named extension method)
host.Services.AddOpenTelemetry(builder => builder
.AddConsoleExporter()
.SetResource(...)
host.Logging.SendToOpenTelemetry();
host.Metrics.SendToOpenTelemetry();
host.DistributedTracing.SendToOpenTelemetry(); // Option B - opt-in using some newly defined OTel API
host.Services.AddOpenTelemetry(builder => builder
.AddConsoleExporter()
.SetResource(...)
.AddDefaultAppInstrumentation() // this would subscribe to all the runtime configured telemetry
// across all signals, same behavior as option A. |
Note: I updated this to include |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4496 +/- ##
==========================================
- Coverage 85.21% 85.11% -0.11%
==========================================
Files 315 316 +1
Lines 12549 12589 +40
==========================================
+ Hits 10694 10715 +21
- Misses 1855 1874 +19
|
I think the ideal pattern is that you can register the Logging integration with OTel, either via logging which you do today, or via OTEL and adding logging to it, so you can setup all the telemetry in one place/off one OTEL object. I don't think that using WithMetrics() on its own does much today does it until you add either a Meter name or register a provider such as ASPNetCoreMetrics. |
@samsp-msft - Am I paraphrasing your comment correctly? "WithLogging() should not listen to ILogger by default, it should be opt-in"
That is my understanding as well. |
@CodeBlanch - is this draft going to be closed in favor of #4501, or you are evaluating different options side by side to get feedback? |
@noahfalk I ended up opening 4 different ones:
Going to leave them open for a bit to gather feedback. We'll probably discuss on the next SIG meeting. Hoping one will emerge as the favorite/least bad choice 🤣 |
Probably no surprise my vote is for 2. Among the rest 1 would be my next choice, 3 and 4 feel very shady. |
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. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Relates to #4433
/cc @noahfalk
Changes
ILoggingBuilder.ConfigureOpenTelemetry
extension for configuringLoggerProviderBuilder
LoggerProviderBuilder.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 extension
ConfigureOpenTelemetry
to try and bridge the two worlds.AddProcessor
andSetResourceBuilder
onOpenTelemetryLoggerOptions
would be obsoleted as would our existing extensions onOpenTelemetryLoggerOptions
.API Usage
All of these styles can be interchanged.
Merge requirement checklist