Skip to content

Commit ea5d607

Browse files
authored
[geneva] Remove remaining project-level warning suppressions and update code to be compliant (open-telemetry#2063)
1 parent c37985d commit ea5d607

15 files changed

+67
-38
lines changed

src/OpenTelemetry.Exporter.Geneva/GenevaExporterHelperExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderBu
9191

9292
private static BaseProcessor<Activity> BuildGenevaTraceExporter(GenevaExporterOptions options, BatchExportActivityProcessorOptions batchActivityExportProcessor)
9393
{
94+
#pragma warning disable CA2000 // Dispose objects before losing scope
9495
var exporter = new GenevaTraceExporter(options);
96+
#pragma warning restore CA2000 // Dispose objects before losing scope
97+
9598
if (exporter.IsUsingUnixDomainSocket)
9699
{
97100
return new BatchActivityExportProcessor(

src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GenevaLogExporter(GenevaExporterOptions options)
6161
break;
6262

6363
default:
64-
throw new ArgumentOutOfRangeException(nameof(connectionStringBuilder.Protocol));
64+
throw new NotSupportedException($"Protocol '{connectionStringBuilder.Protocol}' is not supported");
6565
}
6666

6767
if (useMsgPackExporter)

src/OpenTelemetry.Exporter.Geneva/GenevaLoggingExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ public static OpenTelemetryLoggerOptions AddGenevaLogExporter(
3030

3131
var genevaOptions = new GenevaExporterOptions();
3232
configure?.Invoke(genevaOptions);
33+
34+
#pragma warning disable CA2000 // Dispose objects before losing scope
3335
var exporter = new GenevaLogExporter(genevaOptions);
36+
#pragma warning restore CA2000 // Dispose objects before losing scope
37+
3438
if (exporter.IsUsingUnixDomainSocket)
3539
{
36-
return options.AddProcessor(new BatchLogRecordExportProcessor(exporter));
40+
return options.AddProcessor(sp => new BatchLogRecordExportProcessor(exporter));
3741
}
3842
else
3943
{
40-
return options.AddProcessor(new ReentrantExportProcessor<LogRecord>(exporter));
44+
return options.AddProcessor(sp => new ReentrantExportProcessor<LogRecord>(exporter));
4145
}
4246
}
4347

@@ -123,7 +127,10 @@ internal static BaseProcessor<LogRecord> BuildGenevaLogExporter(
123127
{
124128
Debug.Assert(exporterOptions != null, "exporterOptions was null");
125129

130+
#pragma warning disable CA2000 // Dispose objects before losing scope
126131
var exporter = new GenevaLogExporter(exporterOptions);
132+
#pragma warning restore CA2000 // Dispose objects before losing scope
133+
127134
if (exporter.IsUsingUnixDomainSocket)
128135
{
129136
return new BatchLogRecordExportProcessor(

src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GenevaTraceExporter(GenevaExporterOptions options)
6161
break;
6262

6363
default:
64-
throw new ArgumentOutOfRangeException(nameof(connectionStringBuilder.Protocol));
64+
throw new NotSupportedException($"Protocol '{connectionStringBuilder.Protocol}' is not supported");
6565
}
6666

6767
if (useMsgPackExporter)

src/OpenTelemetry.Exporter.Geneva/Internal/ReentrantExportProcessor.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ namespace OpenTelemetry.Exporter.Geneva;
1414
internal class ReentrantExportProcessor<T> : BaseExportProcessor<T>
1515
where T : class
1616
{
17-
private static readonly Func<T, Batch<T>> CreateBatch;
18-
19-
static ReentrantExportProcessor()
20-
{
21-
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
22-
var ctor = typeof(Batch<T>).GetConstructor(flags, null, new Type[] { typeof(T) }, null);
23-
var value = Expression.Parameter(typeof(T), null);
24-
var lambda = Expression.Lambda<Func<T, Batch<T>>>(Expression.New(ctor, value), value);
25-
CreateBatch = lambda.Compile();
26-
}
17+
private static readonly Func<T, Batch<T>> CreateBatch = BuildCreateBatchDelegate();
2718

2819
public ReentrantExportProcessor(BaseExporter<T> exporter)
2920
: base(exporter)
@@ -34,4 +25,13 @@ protected override void OnExport(T data)
3425
{
3526
this.exporter.Export(CreateBatch(data));
3627
}
28+
29+
private static Func<T, Batch<T>> BuildCreateBatchDelegate()
30+
{
31+
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
32+
var ctor = typeof(Batch<T>).GetConstructor(flags, null, new Type[] { typeof(T) }, null);
33+
var value = Expression.Parameter(typeof(T), null);
34+
var lambda = Expression.Lambda<Func<T, Batch<T>>>(Expression.New(ctor, value), value);
35+
return lambda.Compile();
36+
}
3737
}

src/OpenTelemetry.Exporter.Geneva/Metrics/GenevaMetricExporterExtensions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ public static MeterProviderBuilder AddGenevaMetricExporter(this MeterProviderBui
5959
private static PeriodicExportingMetricReader BuildGenevaMetricExporter(GenevaMetricExporterOptions options, Action<GenevaMetricExporterOptions> configure = null)
6060
{
6161
configure?.Invoke(options);
62-
return new PeriodicExportingMetricReader(new GenevaMetricExporter(options), options.MetricExportIntervalMilliseconds)
63-
{ TemporalityPreference = MetricReaderTemporalityPreference.Delta };
62+
63+
#pragma warning disable CA2000 // Dispose objects before losing scope
64+
var exporter = new GenevaMetricExporter(options);
65+
#pragma warning restore CA2000 // Dispose objects before losing scope
66+
67+
return new PeriodicExportingMetricReader(
68+
exporter,
69+
options.MetricExportIntervalMilliseconds)
70+
{
71+
TemporalityPreference = MetricReaderTemporalityPreference.Delta,
72+
};
6473
}
6574
}

src/OpenTelemetry.Exporter.Geneva/Metrics/TlvMetricExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal TlvMetricExporter(ConnectionStringBuilder connectionStringBuilder, IRea
5757
}
5858

5959
default:
60-
throw new ArgumentOutOfRangeException(nameof(connectionStringBuilder.Protocol));
60+
throw new NotSupportedException($"Protocol '{connectionStringBuilder.Protocol}' is not supported");
6161
}
6262

6363
unsafe

src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricEtwDataTransport.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public unsafe void SendOtlpProtobufEvent(byte[] data, int size)
6161
}
6262
}
6363

64+
#pragma warning disable CA1822 // Mark members as static
65+
6466
[Event(OtlpProtobufMetricEventId)]
6567
public void OtlpProtobufEvent()
6668
{
@@ -86,6 +88,8 @@ public void TLVMetricEvent()
8688
{
8789
}
8890

91+
#pragma warning restore CA1822 // Mark members as static
92+
8993
protected override void Dispose(bool disposing)
9094
{
9195
if (this.isDisposed)

src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackLogExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public MsgPackLogExporter(GenevaExporterOptions options)
7575
this.dataTransport = new UnixDomainSocketDataTransport(unixDomainSocketPath);
7676
break;
7777
default:
78-
throw new ArgumentOutOfRangeException(nameof(connectionStringBuilder.Protocol));
78+
throw new NotSupportedException($"Protocol '{connectionStringBuilder.Protocol}' is not supported");
7979
}
8080

8181
if (options.PrepopulatedFields != null)

src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackTraceExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
9292
this.dataTransport = new UnixDomainSocketDataTransport(unixDomainSocketPath);
9393
break;
9494
default:
95-
throw new ArgumentOutOfRangeException(nameof(connectionStringBuilder.Protocol));
95+
throw new NotSupportedException($"Protocol '{connectionStringBuilder.Protocol}' is not supported");
9696
}
9797

9898
// TODO: Validate custom fields (reserved name? etc).

0 commit comments

Comments
 (0)