[sdk + otlp] Add log processor factory overload#4916
[sdk + otlp] Add log processor factory overload#4916utpilla merged 37 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4916 +/- ##
==========================================
- Coverage 83.40% 83.27% -0.14%
==========================================
Files 296 296
Lines 12301 12357 +56
==========================================
+ Hits 10260 10290 +30
- Misses 2041 2067 +26
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
|
||
| var name = Options.DefaultName; | ||
|
|
||
| return loggerOptions.AddProcessor(sp => |
There was a problem hiding this comment.
From end user perspective: This scenario of enabling IConfiguration/SdkLimitOptions/BatchOptions will only be possible when they have the servicecollection already available like in ASP.NET Core apps. Unlike in case of tracing/metrics where they can call ConfigureServices extension. Is my understanding correct?
There was a problem hiding this comment.
Typically I would expect only host users (AspNetCore or generic host) to care about deep IConfiguration integration. But it is also available for manual scenarios too if users want it.
Here is how you would do it manually for traces & logs:
var config = new ConfigurationBuilder()
.AddJsonFile("appSettings.json")
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services => services.AddSingleton<IConfiguration>(config))
.AddOtlpExporter()
.Build();
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.Services.AddSingleton<IConfiguration>(config);
builder.AddOpenTelemetry(logging => logging.AddOtlpExporter());
});There was a problem hiding this comment.
Could we add a test to validate this scenario?
There was a problem hiding this comment.
|
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. |
…opentelemetry-dotnet into otlp-logs-options-di
…opentelemetry-dotnet into otlp-logs-options-di
| > | ||
| > ```csharp | ||
| > appBuilder.Services.AddOpenTelemetry() | ||
| > .WithTracing(builder => builder.AddOtlpExporter("tracing", configure: null)) |
There was a problem hiding this comment.
Maybe provide a non-null configure Action for one of the signals. This might give the wrong impression to people who are new that this the right way to do it:
- Provide a null configure Action.
- Then,use appBuilder.Services.Configure
There was a problem hiding this comment.
I just switched it to be specific to binding the options via IConfiguration. If you supply the delegate inline to do code-based configuration you really don't need to use the name at all so I thought this would be better LMK.
Relates to #4892
Fixes #4259
Changes
Adds an
AddProcessoroverload onOpenTelemetryLoggerOptionswhich exposes the factory pattern (Func<IServiceProvider, BaseProcessor<LogRecord>> implementationFactory).Uses the factory overload in OTLP log exporter registration to support options being configured through
IConfiguration.Adds an OTLP log exporter registration overload accepting
string nameto support named options being configured throughIConfiguration.Details
The goal of this work is to close some of the gap between logs & traces/metrics. Currently in traces & metrics users may modify the
IServiceCollectionbehind the builders and then interact with the finalIServiceProviderduring startup. This PR adds half of that support to logs: interacting with the finalIServiceProviderduring startup. This is useful for OTLP because it can now retrieveIConfigurationandIOptionsinstances.A couple features which will be enabled with this PR:
Setting sdk limits & experimental options through
IConfiguration.Configuring exporter settings through Options API, eg:
Configuring batch settings through Options API, eg:
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes