-
Notifications
You must be signed in to change notification settings - Fork 773
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 + otlp] Add log processor factory overload #4916
[sdk + otlp] Add log processor factory overload #4916
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test to validate this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see:
opentelemetry-dotnet/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs
Line 1297 in a505998
public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggerFactoryCreate(string name, bool optionalNameMatch) |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - Needs test #4916 (comment)
test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs
Outdated
Show resolved
Hide resolved
test/OpenTelemetry.Tests/Logs/OpenTelemetryLoggerProviderTests.cs
Outdated
Show resolved
Hide resolved
…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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
AddProcessor
overload onOpenTelemetryLoggerOptions
which 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 name
to 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
IServiceCollection
behind the builders and then interact with the finalIServiceProvider
during startup. This PR adds half of that support to logs: interacting with the finalIServiceProvider
during startup. This is useful for OTLP because it can now retrieveIConfiguration
andIOptions
instances.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.md
files updated for non-trivial changes