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

Add otlp log extension methods for LoggerProviderBuilder #4596

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Jun 15, 2023

Towards #4454
Fixes #4388

Changes

Adds the otlp log exporter extension methods LoggerProviderBuilder. Also, includes some fixes by @CodeBlanch for the issues surfaced during testing for LoggerProvider.

Usage Examples

// With OTel data model
using var provider = Sdk.CreateLoggerProviderBuilder()
    .AddOtlpExporter()
    .Build();

var otelLogger = provider.GetLogger();

otelLogger.EmitLog(new LogRecordData { Body = "Hello world " });

// With ILogger
var services = new ServiceCollection();

services.AddLogging(builder => builder.AddOpenTelemetry());
services.ConfigureOpenTelemetryLoggerProvider(builder => builder.AddOtlpExporter());

using var sp = services.BuildServiceProvider();

var loggerFactory = sp.GetService<ILoggerFactory>();

var iLogger = loggerFactory?.CreateLogger("MyILogger");
iLogger?.LogInformation("Hello ILogger");

// With named LogRecordExportProcessorOptions
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddOpenTelemetry());
services.Configure<LogRecordExportProcessorOptions>("MyOtlpOptions", p => p.ExportProcessorType = ExportProcessorType.Simple);
services.ConfigureOpenTelemetryLoggerProvider(builder => builder.AddOtlpExporter(name: "MyOtlpOptions", configureExporterAndProcessor: null));

using var sp = services.BuildServiceProvider();

var loggerFactory = sp.GetService<ILoggerFactory>();

var iLogger = loggerFactory?.CreateLogger("MyILogger");
iLogger?.LogInformation("Hello ILogger");

TODO:
Add changelog and Readme

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@codecov
Copy link

codecov bot commented Jun 22, 2023

Codecov Report

Merging #4596 (f1f7de7) into main (2a228f9) will increase coverage by 1.63%.
The diff coverage is 98.60%.

❗ Current head f1f7de7 differs from pull request most recent head aac88aa. Consider uploading reports for the commit aac88aa to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4596      +/-   ##
==========================================
+ Coverage   83.61%   85.24%   +1.63%     
==========================================
  Files         296      314      +18     
  Lines       12484    12861     +377     
==========================================
+ Hits        10438    10963     +525     
+ Misses       2046     1898     -148     
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...lemetry.Extensions.Hosting/OpenTelemetryBuilder.cs 89.65% <100.00%> (ø)
...elemetry/Logs/Builder/LoggerProviderBuilderBase.cs 97.14% <100.00%> (+0.17%) ⬆️
...try/Logs/ILogger/OpenTelemetryLoggingExtensions.cs 100.00% <100.00%> (+5.88%) ⬆️
...lemetryProtocol/OtlpLogExporterHelperExtensions.cs 96.66% <98.07%> (+6.19%) ⬆️

... and 226 files with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2023

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.

@CodeBlanch
Copy link
Member

@vishweshbankwar

FYI I just pushed a commit to disable IHttpClientFactory integration for OtlpLogExporter.

There is a circular reference issue I haven't been able to figure out a way to make it work reliably. I figured best to just not support it for now.

See: dotnet/runtime#77312 (comment)

@vishweshbankwar vishweshbankwar marked this pull request as ready for review July 7, 2023 19:36
@vishweshbankwar vishweshbankwar requested a review from a team as a code owner July 7, 2023 19:36
@github-actions github-actions bot removed the Stale label Jul 8, 2023
@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 label Jul 15, 2023
@github-actions github-actions bot removed the Stale label Jul 18, 2023
@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 label Jul 26, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

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

@github-actions github-actions bot closed this Aug 2, 2023
@vishweshbankwar vishweshbankwar marked this pull request as draft November 16, 2023 23:55
@github-actions github-actions bot removed the Stale label Nov 17, 2023
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.

Copy link
Contributor

github-actions bot commented Dec 3, 2023

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

@github-actions github-actions bot closed this Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BatchExportProcessorOptions for otlp log exporter
3 participants