Skip to content

Commit 71abd41

Browse files
pentpKielek
andauthored
[repo] Small cleanup/simplification (#6048)
Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com>
1 parent 0c26ce2 commit 71abd41

17 files changed

+29
-67
lines changed

src/OpenTelemetry.Api.ProviderBuilderExtensions/Logs/OpenTelemetryDependencyInjectionLoggerProviderBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static LoggerProviderBuilder AddInstrumentation<
3636

3737
loggerProviderBuilder.ConfigureBuilder((sp, builder) =>
3838
{
39-
builder.AddInstrumentation(() => sp.GetRequiredService<T>());
39+
builder.AddInstrumentation(sp.GetRequiredService<T>);
4040
});
4141

4242
return loggerProviderBuilder;

src/OpenTelemetry.Api.ProviderBuilderExtensions/Metrics/OpenTelemetryDependencyInjectionMeterProviderBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static MeterProviderBuilder AddInstrumentation<
3636

3737
meterProviderBuilder.ConfigureBuilder((sp, builder) =>
3838
{
39-
builder.AddInstrumentation(() => sp.GetRequiredService<T>());
39+
builder.AddInstrumentation(sp.GetRequiredService<T>);
4040
});
4141

4242
return meterProviderBuilder;

src/OpenTelemetry.Api.ProviderBuilderExtensions/Trace/OpenTelemetryDependencyInjectionTracerProviderBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static TracerProviderBuilder AddInstrumentation<
3636

3737
tracerProviderBuilder.ConfigureBuilder((sp, builder) =>
3838
{
39-
builder.AddInstrumentation(() => sp.GetRequiredService<T>());
39+
builder.AddInstrumentation(sp.GetRequiredService<T>);
4040
});
4141

4242
return tracerProviderBuilder;

src/OpenTelemetry.Api/Internal/OpenTelemetryApiEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace OpenTelemetry.Internal;
1212
[EventSource(Name = "OpenTelemetry-Api")]
1313
internal sealed class OpenTelemetryApiEventSource : EventSource
1414
{
15-
public static OpenTelemetryApiEventSource Log = new();
15+
public static readonly OpenTelemetryApiEventSource Log = new();
1616

1717
[NonEvent]
1818
public void ActivityContextExtractException(string format, Exception ex)

src/OpenTelemetry.Api/Trace/TracerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected override void Dispose(bool disposing)
7878
{
7979
if (disposing)
8080
{
81-
var tracers = Interlocked.CompareExchange(ref this.Tracers, null, this.Tracers);
81+
var tracers = Interlocked.Exchange(ref this.Tracers, null);
8282
if (tracers != null)
8383
{
8484
lock (tracers)

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/PersistentStorage/PersistentStorageAbstractionsEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace OpenTelemetry.PersistentStorage.Abstractions;
99
[EventSource(Name = EventSourceName)]
1010
internal sealed class PersistentStorageAbstractionsEventSource : EventSource
1111
{
12-
public static PersistentStorageAbstractionsEventSource Log = new PersistentStorageAbstractionsEventSource();
12+
public static readonly PersistentStorageAbstractionsEventSource Log = new PersistentStorageAbstractionsEventSource();
1313
#if BUILDING_INTERNAL_PERSISTENT_STORAGE
1414
private const string EventSourceName = "OpenTelemetry-PersistentStorage-Abstractions-Otlp";
1515
#else

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/PersistentStorage/PersistentStorageEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace OpenTelemetry.PersistentStorage.FileSystem;
99
[EventSource(Name = EventSourceName)]
1010
internal sealed class PersistentStorageEventSource : EventSource
1111
{
12-
public static PersistentStorageEventSource Log = new PersistentStorageEventSource();
12+
public static readonly PersistentStorageEventSource Log = new PersistentStorageEventSource();
1313
#if BUILDING_INTERNAL_PERSISTENT_STORAGE
1414
private const string EventSourceName = "OpenTelemetry-PersistentStorage-FileSystem-Otlp";
1515
#else

src/OpenTelemetry.Extensions.Hosting/Implementation/HostingExtensionsEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OpenTelemetry.Extensions.Hosting.Implementation;
1111
[EventSource(Name = "OpenTelemetry-Extensions-Hosting")]
1212
internal sealed class HostingExtensionsEventSource : EventSource
1313
{
14-
public static HostingExtensionsEventSource Log = new();
14+
public static readonly HostingExtensionsEventSource Log = new();
1515

1616
[Event(1, Message = "OpenTelemetry TracerProvider was not found in application services. Tracing will remain disabled.", Level = EventLevel.Warning)]
1717
public void TracerProviderNotRegistered()

src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace OpenTelemetry.Internal;
1616
[EventSource(Name = "OpenTelemetry-Sdk")]
1717
internal sealed class OpenTelemetrySdkEventSource : EventSource, IConfigurationExtensionsLogger
1818
{
19-
public static OpenTelemetrySdkEventSource Log = new();
19+
public static readonly OpenTelemetrySdkEventSource Log = new();
2020
#if DEBUG
2121
public static OpenTelemetryEventListener Listener = new();
2222
#endif

src/OpenTelemetry/Logs/LogRecord.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,17 @@ public void ForEachScope<TState>(Action<LogRecordScope, TState> callback, TState
429429
{
430430
Guard.ThrowIfNull(callback);
431431

432-
var forEachScopeState = new ScopeForEachState<TState>(callback, state);
433-
434432
var bufferedScopes = this.ILoggerData.BufferedScopes;
435433
if (bufferedScopes != null)
436434
{
437435
foreach (object? scope in bufferedScopes)
438436
{
439-
ScopeForEachState<TState>.ForEachScope(scope, forEachScopeState);
437+
callback(new(scope), state);
440438
}
441439
}
442440
else
443441
{
444-
this.ILoggerData.ScopeProvider?.ForEachScope(ScopeForEachState<TState>.ForEachScope, forEachScopeState);
442+
this.ILoggerData.ScopeProvider?.ForEachScope(ScopeForEachState<TState>.ForEachScope, new(callback, state));
445443
}
446444
}
447445

0 commit comments

Comments
 (0)