Skip to content
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 AddOpenTelemetryLogging ILoggingBuilder extension (proposal 2) #4501

Conversation

CodeBlanch
Copy link
Member

Relates to #4433
Relates to #4496

Changes

  • Introduce ILoggingBuilder.AddOpenTelemetryLogging extension for configuring LoggerProviderBuilder
  • Introduce LoggerProviderBuilder.ConfigureLoggerOptions extension for configuring OpenTelemetryLoggerOptions

Overview

This is a draft implementation of @noahfalk's comment: #4496 (comment)

I went with AddOpenTelemetryLogging instead of SendToOpenTelemetry because all of the ILoggingBuilder extensions today are named "AddThing" so it just seemed weird. But I'm open to naming it whatever.

Details

Today we configure logging like this:

appBuilder.Logging.AddOpenTelemetry(options =>
{
   options.IncludeFormattedMessage = true;
   options.AddConsoleExporter();
});

"options" is OpenTelemetryLoggerOptions class.

Now the OpenTelemetry Specification has LoggerProvider and we have a LoggerProviderBuilder API. The SDK LoggerProvider is fed into the ILogger integration (OpenTelemetryLoggerProvider).

There are different ways we could approach this. Today we have extensions for logging that target OpenTelemetryLoggerOptions. We will need to target LoggerProviderBuilder now. We could forever have two versions of every extension, but that seems lame.

This PR is adding a new extension AddOpenTelemetryLogging to try and bridge the two worlds. AddOpenTelemetry extension and OpenTelemetryLoggerOptions.AddProcessor and OpenTelemetryLoggerOptions.SetResourceBuilder methods would be obsoleted as would our existing extensions on OpenTelemetryLoggerOptions.

All of these styles can be interchanged.

// Configure OTel via ILoggingBuilder
appBuilder.Logging
   .AddOpenTelemetryLogging(builder => builder
      .ConfigureLoggerOptions(options => options.IncludeFormattedMessage = true)
      .AddConsoleExporter());
// Configure OTel via OpenTelemetryBuilder
appBuilder.Services
   .AddOpenTelemetry()
   .WithLogging(builder => builder
      .ConfigureLoggerOptions(options => options.IncludeFormattedMessage = true)
      .AddConsoleExporter());
// 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);
// Configure OTel via ILoggingBuilder
appBuilder.Logging
   .AddOpenTelemetryLogging(builder => builder
      .AddConsoleExporter());

// Configure ILogger options via Options API
appBuilder.Services.Configure<OpenTelemetryLoggerOptions>(options => options.IncludeFormattedMessage = true);

Merge requirement checklist

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

@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Merging #4501 (c345f6d) into main (d63c32f) will decrease coverage by 0.07%.
The diff coverage is 92.50%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4501      +/-   ##
==========================================
- Coverage   85.21%   85.15%   -0.07%     
==========================================
  Files         315      316       +1     
  Lines       12549    12592      +43     
==========================================
+ Hits        10694    10723      +29     
- Misses       1855     1869      +14     
Impacted Files Coverage Δ
...ry/Logs/Builder/LoggerProviderBuilderExtensions.cs 92.15% <0.00%> (-5.76%) ⬇️
...lemetry/Logs/ILogger/OpenTelemetryLoggerOptions.cs 85.00% <ø> (ø)
...try/Logs/ILogger/OpenTelemetryLoggingExtensions.cs 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

@noahfalk
Copy link

I went with AddOpenTelemetryLogging instead of SendToOpenTelemetry because all of the ILoggingBuilder extensions today are named "AddThing" so it just seemed weird. But I'm open to naming it whatever.

Yeah, I think any name we pick will be more awkward than AddOpenTelemetry() and its just a matter of picking which particular awkward one we want. If I was picking my favorite I'd probably still take SendToOpenTelemetry(), but this one seems fine too.

@github-actions
Copy link
Contributor

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 github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label May 26, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants