Skip to content

Commit

Permalink
OpenTelemetryLoggerProvider is now unaffected by changes to OpenTelem…
Browse files Browse the repository at this point in the history
…etryLoggerOptions after the LoggerFactory is built. (#3055)
  • Loading branch information
TimothyMothra authored Mar 30, 2022
1 parent add7eee commit eefffa9
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 283 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
`readonly`
([#3065](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3065))

* [Bug fix] OpenTelemetryLoggerProvider is now unaffected by changes to
OpenTelemetryLoggerOptions after the LoggerFactory is built.
([#3055](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3055))

## 1.2.0-rc3

Released 2022-Mar-04
Expand Down
13 changes: 6 additions & 7 deletions src/OpenTelemetry/Logs/OpenTelemetryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
return;
}

var processor = this.provider.Processor;
var provider = this.provider;
var processor = provider.Processor;
if (processor != null)
{
var options = this.provider.Options;

var record = new LogRecord(
options.IncludeScopes ? this.ScopeProvider : null,
provider.IncludeScopes ? this.ScopeProvider : null,
DateTime.UtcNow,
this.categoryName,
logLevel,
eventId,
options.IncludeFormattedMessage ? formatter?.Invoke(state, exception) : null,
options.ParseStateValues ? null : state,
provider.IncludeFormattedMessage ? formatter?.Invoke(state, exception) : null,
provider.ParseStateValues ? null : state,
exception,
options.ParseStateValues ? this.ParseState(state) : null);
provider.ParseStateValues ? this.ParseState(state) : null);

processor.OnEnd(record);

Expand Down
9 changes: 7 additions & 2 deletions src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace OpenTelemetry.Logs
[ProviderAlias("OpenTelemetry")]
public class OpenTelemetryLoggerProvider : BaseProvider, ILoggerProvider, ISupportExternalScope
{
internal readonly OpenTelemetryLoggerOptions Options;
internal readonly bool IncludeScopes;
internal readonly bool IncludeFormattedMessage;
internal readonly bool ParseStateValues;
internal BaseProcessor<LogRecord> Processor;
internal Resource Resource;
private readonly Hashtable loggers = new();
Expand All @@ -48,7 +50,10 @@ internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options)
{
Guard.ThrowIfNull(options);

this.Options = options;
this.IncludeScopes = options.IncludeScopes;
this.IncludeFormattedMessage = options.IncludeFormattedMessage;
this.ParseStateValues = options.ParseStateValues;

this.Resource = options.ResourceBuilder.Build();

foreach (var processor in options.Processors)
Expand Down
Loading

0 comments on commit eefffa9

Please sign in to comment.