Skip to content

Commit 7f29ef3

Browse files
authored
[geneva] Nullable annotations for the internal folder (open-telemetry#2076)
1 parent 4a9d97c commit 7f29ef3

File tree

10 files changed

+43
-18
lines changed

10 files changed

+43
-18
lines changed

src/OpenTelemetry.Exporter.Geneva/EventNameExportMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
namespace OpenTelemetry.Exporter.Geneva;
57

68
/// <summary>

src/OpenTelemetry.Exporter.Geneva/ExceptionStackExportMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
namespace OpenTelemetry.Exporter.Geneva;
57

68
/// <summary>

src/OpenTelemetry.Exporter.Geneva/External/TraceLoggingDynamic.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ that is larger than the buffer size of the recording session.
7070
Most ETW decoding tools are unable to decode an event with more than 128
7171
fields.
7272
*/
73+
74+
#nullable enable
75+
7376
namespace OpenTelemetry.Exporter.Geneva.External;
7477

7578
using System;
@@ -315,7 +318,7 @@ public static Guid GetGuidForName(string providerName)
315318

316319
// Guid = Hash[0..15], with Hash[7] tweaked approximately following RFC 4122
317320
byte[] guidBytes = new byte[16];
318-
Buffer.BlockCopy(sha1.Hash, 0, guidBytes, 0, 16);
321+
Buffer.BlockCopy(sha1.Hash!, 0, guidBytes, 0, 16);
319322
guidBytes[7] = (byte)((guidBytes[7] & 0x0F) | 0x50);
320323
return new Guid(guidBytes);
321324
}

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
using System.Globalization;
57
using OpenTelemetry.Internal;
68

@@ -67,16 +69,22 @@ public string EtwSession
6769
set => this.parts[nameof(this.EtwSession)] = value;
6870
}
6971

70-
public string PrivatePreviewEnableTraceLoggingDynamic
72+
public bool PrivatePreviewEnableTraceLoggingDynamic
7173
{
72-
get => this.ThrowIfNotExists<string>(nameof(this.PrivatePreviewEnableTraceLoggingDynamic));
73-
set => this.parts[nameof(this.PrivatePreviewEnableTraceLoggingDynamic)] = value;
74+
get
75+
{
76+
return this.parts.TryGetValue(nameof(this.PrivatePreviewEnableTraceLoggingDynamic), out var value)
77+
&& bool.TrueString.Equals(value, StringComparison.OrdinalIgnoreCase);
78+
}
7479
}
7580

76-
public string PrivatePreviewEnableOtlpProtobufEncoding
81+
public bool PrivatePreviewEnableOtlpProtobufEncoding
7782
{
78-
get => this.parts.TryGetValue(nameof(this.PrivatePreviewEnableOtlpProtobufEncoding), out var value) ? value : null;
79-
set => this.parts[nameof(this.PrivatePreviewEnableOtlpProtobufEncoding)] = value;
83+
get
84+
{
85+
return this.parts.TryGetValue(nameof(this.PrivatePreviewEnableOtlpProtobufEncoding), out var value)
86+
&& bool.TrueString.Equals(value, StringComparison.OrdinalIgnoreCase);
87+
}
8088
}
8189

8290
public string Endpoint
@@ -94,8 +102,7 @@ public TransportProtocol Protocol
94102
// Checking Etw first, since it's preferred for Windows and enables fail fast on Linux
95103
if (this.parts.ContainsKey(nameof(this.EtwSession)))
96104
{
97-
_ = this.parts.TryGetValue(nameof(this.PrivatePreviewEnableTraceLoggingDynamic), out var privatePreviewEnableTraceLoggingDynamic);
98-
if (privatePreviewEnableTraceLoggingDynamic != null && privatePreviewEnableTraceLoggingDynamic.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
105+
if (this.PrivatePreviewEnableTraceLoggingDynamic)
99106
{
100107
return TransportProtocol.EtwTld;
101108
}
@@ -127,7 +134,7 @@ public int TimeoutMilliseconds
127134
{
128135
get
129136
{
130-
if (!this.parts.TryGetValue(nameof(this.TimeoutMilliseconds), out string value))
137+
if (!this.parts.TryGetValue(nameof(this.TimeoutMilliseconds), out string? value))
131138
{
132139
return UnixDomainSocketDataTransport.DefaultTimeoutMilliseconds;
133140
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
using System.Diagnostics.Tracing;
57
using OpenTelemetry.Internal;
68

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
using System.Diagnostics;
57

68
namespace OpenTelemetry.Exporter.Geneva;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
using System.Linq.Expressions;
57
using System.Reflection;
68

@@ -29,7 +31,8 @@ protected override void OnExport(T data)
2931
private static Func<T, Batch<T>> BuildCreateBatchDelegate()
3032
{
3133
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
32-
var ctor = typeof(Batch<T>).GetConstructor(flags, null, new Type[] { typeof(T) }, null);
34+
var ctor = typeof(Batch<T>).GetConstructor(flags, null, new Type[] { typeof(T) }, null)
35+
?? throw new InvalidOperationException("Batch ctor accepting a single item could not be found reflectively");
3336
var value = Expression.Parameter(typeof(T), null);
3437
var lambda = Expression.Lambda<Func<T, Batch<T>>>(Expression.New(ctor, value), value);
3538
return lambda.Compile();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
namespace OpenTelemetry.Exporter.Geneva;
57

68
internal static class Schema

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#nullable enable
5+
46
using System.Diagnostics;
57
using System.Runtime.CompilerServices;
68
using System.Text;
@@ -23,7 +25,7 @@ indicate an invalid name. We need a different instance to trigger the
2325
private static readonly StringComparer DictionaryKeyComparer = StringComparer.Ordinal;
2426

2527
private readonly byte[] defaultTableName;
26-
private readonly Dictionary<string, byte[]> tableMappings;
28+
private readonly Dictionary<string, byte[]>? tableMappings;
2729
private readonly bool shouldPassThruTableMappings;
2830
private readonly object lockObject = new();
2931
private TableNameCacheDictionary tableNameCache = new();
@@ -35,7 +37,7 @@ public TableNameSerializer(GenevaExporterOptions options, string defaultTableNam
3537

3638
this.defaultTableName = BuildStr8BufferForAsciiString(defaultTableName);
3739

38-
if (options.TableNameMappings != null)
40+
if (options!.TableNameMappings != null)
3941
{
4042
var tempTableMappings = new Dictionary<string, byte[]>(options.TableNameMappings.Count, DictionaryKeyComparer);
4143
foreach (var kv in options.TableNameMappings)
@@ -164,7 +166,7 @@ private byte[] ResolveTableMappingForCategoryName(string categoryName)
164166
{
165167
var tableNameCache = this.tableNameCache;
166168

167-
if (tableNameCache.TryGetValue(categoryName, out byte[] tableName))
169+
if (tableNameCache.TryGetValue(categoryName, out byte[]? tableName))
168170
{
169171
return tableName;
170172
}
@@ -174,15 +176,15 @@ private byte[] ResolveTableMappingForCategoryName(string categoryName)
174176

175177
private byte[] ResolveTableMappingForCategoryNameRare(string categoryName)
176178
{
177-
byte[] mappedTableName = null;
179+
byte[]? mappedTableName = null;
178180

179181
// If user configured table name mappings run resolution logic.
180182
if (this.tableMappings != null
181183
&& !this.tableMappings.TryGetValue(categoryName, out mappedTableName))
182184
{
183185
// Find best match if an exact match was not found.
184186

185-
string currentKey = null;
187+
string? currentKey = null;
186188

187189
foreach (var mapping in this.tableMappings)
188190
{
@@ -230,7 +232,7 @@ private byte[] ResolveTableMappingForCategoryNameRare(string categoryName)
230232

231233
// Check if another thread added the mapping while we waited on the
232234
// lock.
233-
if (tableNameCache.TryGetValue(categoryName, out byte[] tableName))
235+
if (tableNameCache.TryGetValue(categoryName, out byte[]? tableName))
234236
{
235237
return tableName;
236238
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public GenevaMetricExporter(GenevaMetricExporterOptions options)
5353
DisableOpenTelemetrySdkMetricNameValidation();
5454
}
5555

56-
if (connectionStringBuilder.PrivatePreviewEnableOtlpProtobufEncoding != null && connectionStringBuilder.PrivatePreviewEnableOtlpProtobufEncoding.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
56+
if (connectionStringBuilder.PrivatePreviewEnableOtlpProtobufEncoding)
5757
{
5858
var otlpProtobufExporter = new OtlpProtobufMetricExporter(
5959
() => { return this.Resource; },

0 commit comments

Comments
 (0)