Skip to content

Commit cd3f7e3

Browse files
CodeBlanchKielek
andauthored
[geneva] Nullable annotations for MsgPackExporter folder (open-telemetry#2092)
Co-authored-by: Piotr Kiełkowicz <[email protected]>
1 parent 6534edc commit cd3f7e3

35 files changed

+219
-147
lines changed

src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#nullable enable
55

66
using System.Runtime.InteropServices;
7-
using OpenTelemetry.Exporter.Geneva.TldExporter;
7+
using OpenTelemetry.Exporter.Geneva.MsgPack;
8+
using OpenTelemetry.Exporter.Geneva.Tld;
89
using OpenTelemetry.Internal;
910
using OpenTelemetry.Logs;
1011

@@ -29,7 +30,6 @@ public class GenevaLogExporter : GenevaBaseExporter<LogRecord>
2930
public GenevaLogExporter(GenevaExporterOptions options)
3031
{
3132
Guard.ThrowIfNull(options);
32-
Guard.ThrowIfNullOrWhitespace(options.ConnectionString);
3333

3434
bool useMsgPackExporter;
3535
var connectionStringBuilder = new ConnectionStringBuilder(options.ConnectionString);

src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
using System.Diagnostics;
77
using System.Runtime.InteropServices;
8-
using OpenTelemetry.Exporter.Geneva.TldExporter;
8+
using OpenTelemetry.Exporter.Geneva.MsgPack;
9+
using OpenTelemetry.Exporter.Geneva.Tld;
910
using OpenTelemetry.Internal;
1011

1112
namespace OpenTelemetry.Exporter.Geneva;
@@ -29,7 +30,6 @@ public class GenevaTraceExporter : GenevaBaseExporter<Activity>
2930
public GenevaTraceExporter(GenevaExporterOptions options)
3031
{
3132
Guard.ThrowIfNull(options);
32-
Guard.ThrowIfNullOrWhitespace(options.ConnectionString);
3333

3434
bool useMsgPackExporter;
3535
var connectionStringBuilder = new ConnectionStringBuilder(options.ConnectionString);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#nullable enable
55

6+
using System.Diagnostics.CodeAnalysis;
67
using System.Globalization;
8+
using OpenTelemetry.Exporter.Geneva.Transports;
79
using OpenTelemetry.Internal;
810

911
namespace OpenTelemetry.Exporter.Geneva;
@@ -20,9 +22,9 @@ internal enum TransportProtocol
2022

2123
internal sealed class ConnectionStringBuilder
2224
{
23-
private readonly Dictionary<string, string> parts = new Dictionary<string, string>(StringComparer.Ordinal);
25+
private readonly Dictionary<string, string> parts = new(StringComparer.Ordinal);
2426

25-
public ConnectionStringBuilder(string connectionString)
27+
public ConnectionStringBuilder([NotNull] string? connectionString)
2628
{
2729
Guard.ThrowIfNullOrWhitespace(connectionString);
2830

src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MessagePackSerializer.cs renamed to src/OpenTelemetry.Exporter.Geneva/Internal/MsgPack/MessagePackSerializer.cs

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

4+
#nullable enable
5+
46
#if NET
57
using System.Buffers.Binary;
68
#endif
79
using System.Globalization;
810
using System.Runtime.CompilerServices;
911
using System.Text;
1012

11-
namespace OpenTelemetry.Exporter.Geneva;
13+
namespace OpenTelemetry.Exporter.Geneva.MsgPack;
1214

1315
internal static class MessagePackSerializer
1416
{
@@ -331,7 +333,7 @@ public static void WriteStr8Header(Span<byte> buffer, int nameStartIdx, int vali
331333
}
332334

333335
[MethodImpl(MethodImplOptions.AggressiveInlining)]
334-
public static int SerializeAsciiString(byte[] buffer, int cursor, string value)
336+
public static int SerializeAsciiString(byte[] buffer, int cursor, string? value)
335337
{
336338
if (value == null)
337339
{
@@ -401,13 +403,19 @@ public static int SerializeAsciiString(byte[] buffer, int cursor, string value)
401403
#if NET
402404

403405
[MethodImpl(MethodImplOptions.AggressiveInlining)]
404-
public static int SerializeUnicodeString(byte[] buffer, int cursor, ReadOnlySpan<char> value)
406+
public static int SerializeUnicodeString(byte[] buffer, int cursor, string? value)
405407
{
406408
if (value == null)
407409
{
408410
return SerializeNull(buffer, cursor);
409411
}
410412

413+
return SerializeUnicodeString(buffer, cursor, value.AsSpan());
414+
}
415+
416+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
417+
public static int SerializeUnicodeString(byte[] buffer, int cursor, ReadOnlySpan<char> value)
418+
{
411419
int start = cursor;
412420
var cch = value.Length;
413421
int cb;
@@ -438,7 +446,7 @@ public static int SerializeUnicodeString(byte[] buffer, int cursor, ReadOnlySpan
438446
#else
439447

440448
[MethodImpl(MethodImplOptions.AggressiveInlining)]
441-
public static int SerializeUnicodeString(byte[] buffer, int cursor, string value)
449+
public static int SerializeUnicodeString(byte[] buffer, int cursor, string? value)
442450
{
443451
if (value == null)
444452
{
@@ -496,7 +504,7 @@ public static int WriteArrayHeader(byte[] buffer, int cursor, int length)
496504
}
497505

498506
[MethodImpl(MethodImplOptions.AggressiveInlining)]
499-
public static int SerializeArray<T>(byte[] buffer, int cursor, T[] array)
507+
public static int SerializeArray<T>(byte[] buffer, int cursor, T[]? array)
500508
{
501509
if (array == null)
502510
{
@@ -534,7 +542,7 @@ public static int WriteMapHeader(byte[] buffer, int cursor, int count)
534542
}
535543

536544
[MethodImpl(MethodImplOptions.AggressiveInlining)]
537-
public static int SerializeMap(byte[] buffer, int cursor, IDictionary<string, object> map)
545+
public static int SerializeMap(byte[] buffer, int cursor, IDictionary<string, object>? map)
538546
{
539547
if (map == null)
540548
{
@@ -582,7 +590,7 @@ public static int SerializeUtcDateTime(byte[] buffer, int cursor, DateTime utc)
582590
return SerializeTimestamp96(buffer, cursor, utc.Ticks);
583591
}
584592

585-
public static int Serialize(byte[] buffer, int cursor, object obj)
593+
public static int Serialize(byte[] buffer, int cursor, object? obj)
586594
{
587595
if (obj == null)
588596
{
@@ -636,7 +644,7 @@ public static int Serialize(byte[] buffer, int cursor, object obj)
636644
#endif
637645

638646
default:
639-
string repr;
647+
string? repr;
640648

641649
try
642650
{

src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackExporter.cs renamed to src/OpenTelemetry.Exporter.Geneva/Internal/MsgPack/MsgPackExporter.cs

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

4+
#nullable enable
5+
46
#if NET8_0_OR_GREATER
57
using System.Collections.Frozen;
68
#endif
79

8-
namespace OpenTelemetry.Exporter.Geneva;
10+
namespace OpenTelemetry.Exporter.Geneva.MsgPack;
911

1012
internal abstract class MsgPackExporter
1113
{
@@ -37,9 +39,9 @@ internal abstract class MsgPackExporter
3739
internal static readonly IReadOnlyDictionary<string, string> V40_PART_A_MAPPING = PART_A_MAPPING_DICTIONARY;
3840
#endif
3941

40-
protected static int AddPartAField(byte[] buffer, int cursor, string name, object value)
42+
protected static int AddPartAField(byte[] buffer, int cursor, string name, object? value)
4143
{
42-
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
44+
if (V40_PART_A_MAPPING.TryGetValue(name, out string? replacementKey))
4345
{
4446
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
4547
}
@@ -54,7 +56,7 @@ protected static int AddPartAField(byte[] buffer, int cursor, string name, objec
5456

5557
protected static int AddPartAField(byte[] buffer, int cursor, string name, ReadOnlySpan<byte> value)
5658
{
57-
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
59+
if (V40_PART_A_MAPPING.TryGetValue(name, out string? replacementKey))
5860
{
5961
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
6062
}

0 commit comments

Comments
 (0)