Skip to content

Commit fe9fbea

Browse files
[geneva] Update code to follow more of the repo style conventions (open-telemetry#2052)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent 4791960 commit fe9fbea

23 files changed

+778
-808
lines changed

src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace OpenTelemetry.Exporter.Geneva;
1111
/// </summary>
1212
public class GenevaExporterOptions
1313
{
14-
private IReadOnlyDictionary<string, object> _fields = new Dictionary<string, object>(1)
14+
private IReadOnlyDictionary<string, object> fields = new Dictionary<string, object>(1)
1515
{
1616
[Schema.V40.PartA.Ver] = "4.0",
1717
};
1818

19-
private IReadOnlyDictionary<string, string> _tableNameMappings;
19+
private IReadOnlyDictionary<string, string> tableNameMappings;
2020

2121
/// <summary>
2222
/// Gets or sets the connection string.
@@ -48,7 +48,7 @@ public class GenevaExporterOptions
4848
/// </summary>
4949
public IReadOnlyDictionary<string, string> TableNameMappings
5050
{
51-
get => this._tableNameMappings;
51+
get => this.tableNameMappings;
5252
set
5353
{
5454
Guard.ThrowIfNull(value);
@@ -89,7 +89,7 @@ public IReadOnlyDictionary<string, string> TableNameMappings
8989
copy[entry.Key] = entry.Value;
9090
}
9191

92-
this._tableNameMappings = copy;
92+
this.tableNameMappings = copy;
9393
}
9494
}
9595

@@ -98,7 +98,7 @@ public IReadOnlyDictionary<string, string> TableNameMappings
9898
/// </summary>
9999
public IReadOnlyDictionary<string, object> PrepopulatedFields
100100
{
101-
get => this._fields;
101+
get => this.fields;
102102
set
103103
{
104104
Guard.ThrowIfNull(value);
@@ -153,7 +153,7 @@ public IReadOnlyDictionary<string, object> PrepopulatedFields
153153
copy[entry.Key] = val; // shallow copy
154154
}
155155

156-
this._fields = copy;
156+
this.fields = copy;
157157
}
158158
}
159159
}

src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ public class GenevaLogExporter : GenevaBaseExporter<LogRecord>
1515
{
1616
internal bool IsUsingUnixDomainSocket;
1717

18-
private bool isDisposed;
19-
20-
private delegate ExportResult ExportLogRecordFunc(in Batch<LogRecord> batch);
21-
2218
private readonly ExportLogRecordFunc exportLogRecord;
23-
2419
private readonly IDisposable exporter;
2520

21+
private bool isDisposed;
22+
2623
/// <summary>
2724
/// Initializes a new instance of the <see cref="GenevaLogExporter"/> class.
2825
/// </summary>
@@ -83,6 +80,8 @@ public GenevaLogExporter(GenevaExporterOptions options)
8380
}
8481
}
8582

83+
private delegate ExportResult ExportLogRecordFunc(in Batch<LogRecord> batch);
84+
8685
/// <inheritdoc/>
8786
public override ExportResult Export(in Batch<LogRecord> batch)
8887
{

src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ public class GenevaTraceExporter : GenevaBaseExporter<Activity>
1515
{
1616
internal readonly bool IsUsingUnixDomainSocket;
1717

18-
private bool isDisposed;
19-
20-
private delegate ExportResult ExportActivityFunc(in Batch<Activity> batch);
21-
2218
private readonly ExportActivityFunc exportActivity;
23-
2419
private readonly IDisposable exporter;
2520

21+
private bool isDisposed;
22+
2623
/// <summary>
2724
/// Initializes a new instance of the <see cref="GenevaTraceExporter"/> class.
2825
/// </summary>
@@ -83,6 +80,8 @@ public GenevaTraceExporter(GenevaExporterOptions options)
8380
}
8481
}
8582

83+
private delegate ExportResult ExportActivityFunc(in Batch<Activity> batch);
84+
8685
/// <inheritdoc/>
8786
public override ExportResult Export(in Batch<Activity> batch)
8887
{

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal enum TransportProtocol
1818

1919
internal sealed class ConnectionStringBuilder
2020
{
21-
private readonly Dictionary<string, string> _parts = new Dictionary<string, string>(StringComparer.Ordinal);
21+
private readonly Dictionary<string, string> parts = new Dictionary<string, string>(StringComparer.Ordinal);
2222

2323
public ConnectionStringBuilder(string connectionString)
2424
{
@@ -52,10 +52,10 @@ public ConnectionStringBuilder(string connectionString)
5252
throw new ArgumentException("Connection string cannot contain empty keys or values.");
5353
}
5454

55-
this._parts[key] = value;
55+
this.parts[key] = value;
5656
}
5757

58-
if (this._parts.Count == 0)
58+
if (this.parts.Count == 0)
5959
{
6060
throw new ArgumentNullException(nameof(connectionString), $"{nameof(connectionString)} is invalid.");
6161
}
@@ -64,25 +64,25 @@ public ConnectionStringBuilder(string connectionString)
6464
public string EtwSession
6565
{
6666
get => this.ThrowIfNotExists<string>(nameof(this.EtwSession));
67-
set => this._parts[nameof(this.EtwSession)] = value;
67+
set => this.parts[nameof(this.EtwSession)] = value;
6868
}
6969

7070
public string PrivatePreviewEnableTraceLoggingDynamic
7171
{
7272
get => this.ThrowIfNotExists<string>(nameof(this.PrivatePreviewEnableTraceLoggingDynamic));
73-
set => this._parts[nameof(this.PrivatePreviewEnableTraceLoggingDynamic)] = value;
73+
set => this.parts[nameof(this.PrivatePreviewEnableTraceLoggingDynamic)] = value;
7474
}
7575

7676
public string PrivatePreviewEnableOtlpProtobufEncoding
7777
{
78-
get => this._parts.TryGetValue(nameof(this.PrivatePreviewEnableOtlpProtobufEncoding), out var value) ? value : null;
79-
set => this._parts[nameof(this.PrivatePreviewEnableOtlpProtobufEncoding)] = value;
78+
get => this.parts.TryGetValue(nameof(this.PrivatePreviewEnableOtlpProtobufEncoding), out var value) ? value : null;
79+
set => this.parts[nameof(this.PrivatePreviewEnableOtlpProtobufEncoding)] = value;
8080
}
8181

8282
public string Endpoint
8383
{
8484
get => this.ThrowIfNotExists<string>(nameof(this.Endpoint));
85-
set => this._parts[nameof(this.Endpoint)] = value;
85+
set => this.parts[nameof(this.Endpoint)] = value;
8686
}
8787

8888
public TransportProtocol Protocol
@@ -92,9 +92,9 @@ public TransportProtocol Protocol
9292
try
9393
{
9494
// Checking Etw first, since it's preferred for Windows and enables fail fast on Linux
95-
if (this._parts.ContainsKey(nameof(this.EtwSession)))
95+
if (this.parts.ContainsKey(nameof(this.EtwSession)))
9696
{
97-
_ = this._parts.TryGetValue(nameof(this.PrivatePreviewEnableTraceLoggingDynamic), out var privatePreviewEnableTraceLoggingDynamic);
97+
_ = this.parts.TryGetValue(nameof(this.PrivatePreviewEnableTraceLoggingDynamic), out var privatePreviewEnableTraceLoggingDynamic);
9898
if (privatePreviewEnableTraceLoggingDynamic != null && privatePreviewEnableTraceLoggingDynamic.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
9999
{
100100
return TransportProtocol.EtwTld;
@@ -103,7 +103,7 @@ public TransportProtocol Protocol
103103
return TransportProtocol.Etw;
104104
}
105105

106-
if (!this._parts.ContainsKey(nameof(this.Endpoint)))
106+
if (!this.parts.ContainsKey(nameof(this.Endpoint)))
107107
{
108108
return TransportProtocol.Unspecified;
109109
}
@@ -123,41 +123,11 @@ public TransportProtocol Protocol
123123
}
124124
}
125125

126-
/// <summary>
127-
/// Replace first charater of string if it matches with <paramref name="oldChar"/> with <paramref name="newChar"/>.
128-
/// </summary>
129-
/// <param name="str">String to be updated.</param>
130-
/// <param name="oldChar">Old character to be replaced.</param>
131-
/// <param name="newChar">New character to be replaced with.</param>
132-
/// <returns>Updated string.</returns>
133-
internal static string ReplaceFirstChar(string str, char oldChar, char newChar)
134-
{
135-
if (str.Length > 0 && str[0] == oldChar)
136-
{
137-
return $"{newChar}{str.Substring(1)}";
138-
}
139-
140-
return str;
141-
}
142-
143-
public string ParseUnixDomainSocketPath()
144-
{
145-
try
146-
{
147-
var endpoint = new Uri(this.Endpoint);
148-
return ReplaceFirstChar(endpoint.AbsolutePath, '@', '\0');
149-
}
150-
catch (UriFormatException ex)
151-
{
152-
throw new ArgumentException($"{nameof(this.Endpoint)} value is malformed.", ex);
153-
}
154-
}
155-
156126
public int TimeoutMilliseconds
157127
{
158128
get
159129
{
160-
if (!this._parts.TryGetValue(nameof(this.TimeoutMilliseconds), out string value))
130+
if (!this.parts.TryGetValue(nameof(this.TimeoutMilliseconds), out string value))
161131
{
162132
return UnixDomainSocketDataTransport.DefaultTimeoutMilliseconds;
163133
}
@@ -186,7 +156,7 @@ public int TimeoutMilliseconds
186156
ex);
187157
}
188158
}
189-
set => this._parts[nameof(this.TimeoutMilliseconds)] = value.ToString(CultureInfo.InvariantCulture);
159+
set => this.parts[nameof(this.TimeoutMilliseconds)] = value.ToString(CultureInfo.InvariantCulture);
190160
}
191161

192162
public string Host
@@ -229,32 +199,62 @@ public int Port
229199
public string Account
230200
{
231201
get => this.ThrowIfNotExists<string>(nameof(this.Account));
232-
set => this._parts[nameof(this.Account)] = value;
202+
set => this.parts[nameof(this.Account)] = value;
233203
}
234204

235205
public string Namespace
236206
{
237207
get => this.ThrowIfNotExists<string>(nameof(this.Namespace));
238-
set => this._parts[nameof(this.Namespace)] = value;
208+
set => this.parts[nameof(this.Namespace)] = value;
239209
}
240210

241211
public bool DisableMetricNameValidation
242212
{
243213
get
244214
{
245-
if (!this._parts.TryGetValue(nameof(this.DisableMetricNameValidation), out var value))
215+
if (!this.parts.TryGetValue(nameof(this.DisableMetricNameValidation), out var value))
246216
{
247217
return false;
248218
}
249219

250220
return string.Equals(bool.TrueString, value, StringComparison.OrdinalIgnoreCase);
251221
}
252-
set => this._parts[nameof(this.DisableMetricNameValidation)] = value ? bool.TrueString : bool.FalseString;
222+
set => this.parts[nameof(this.DisableMetricNameValidation)] = value ? bool.TrueString : bool.FalseString;
223+
}
224+
225+
public string ParseUnixDomainSocketPath()
226+
{
227+
try
228+
{
229+
var endpoint = new Uri(this.Endpoint);
230+
return ReplaceFirstChar(endpoint.AbsolutePath, '@', '\0');
231+
}
232+
catch (UriFormatException ex)
233+
{
234+
throw new ArgumentException($"{nameof(this.Endpoint)} value is malformed.", ex);
235+
}
236+
}
237+
238+
/// <summary>
239+
/// Replace first charater of string if it matches with <paramref name="oldChar"/> with <paramref name="newChar"/>.
240+
/// </summary>
241+
/// <param name="str">String to be updated.</param>
242+
/// <param name="oldChar">Old character to be replaced.</param>
243+
/// <param name="newChar">New character to be replaced with.</param>
244+
/// <returns>Updated string.</returns>
245+
internal static string ReplaceFirstChar(string str, char oldChar, char newChar)
246+
{
247+
if (str.Length > 0 && str[0] == oldChar)
248+
{
249+
return $"{newChar}{str.Substring(1)}";
250+
}
251+
252+
return str;
253253
}
254254

255255
private T ThrowIfNotExists<T>(string name)
256256
{
257-
if (!this._parts.TryGetValue(name, out var value))
257+
if (!this.parts.TryGetValue(name, out var value))
258258
{
259259
throw new ArgumentException($"'{name}' value is missing in connection string.");
260260
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ 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+
1719
static ReentrantExportProcessor()
1820
{
1921
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
@@ -32,6 +34,4 @@ protected override void OnExport(T data)
3234
{
3335
this.exporter.Export(CreateBatch(data));
3436
}
35-
36-
private static readonly Func<T, Batch<T>> CreateBatch;
3737
}

0 commit comments

Comments
 (0)