Skip to content

Commit e33d6b4

Browse files
authored
[geneva] Remove reflection from tests to fix failures due to renames (open-telemetry#2062)
1 parent fe9fbea commit e33d6b4

File tree

5 files changed

+56
-78
lines changed

5 files changed

+56
-78
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ namespace OpenTelemetry.Exporter.Geneva;
1515

1616
internal sealed class MsgPackLogExporter : MsgPackExporter, IDisposable
1717
{
18+
internal static readonly ThreadLocal<byte[]> Buffer = new();
19+
1820
private const int BUFFER_SIZE = 65360; // the maximum ETW payload (inclusive)
1921

20-
private static readonly ThreadLocal<byte[]> Buffer = new();
2122
private static readonly Action<LogRecordScope, MsgPackLogExporter> ProcessScopeForIndividualColumnsAction = OnProcessScopeForIndividualColumns;
2223
private static readonly Action<LogRecordScope, MsgPackLogExporter> ProcessScopeForEnvPropertiesAction = OnProcessScopeForEnvProperties;
2324
private static readonly string[] LogLevels = new string[7]

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

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ namespace OpenTelemetry.Exporter.Geneva;
1212

1313
internal sealed class MsgPackTraceExporter : MsgPackExporter, IDisposable
1414
{
15-
private const int BUFFER_SIZE = 65360; // the maximum ETW payload (inclusive)
16-
17-
private static readonly string INVALID_SPAN_ID = default(ActivitySpanId).ToHexString();
18-
19-
private static readonly Dictionary<string, string> CS40_PART_B_MAPPING_DICTIONARY = new()
15+
internal static readonly Dictionary<string, string> CS40_PART_B_MAPPING_DICTIONARY = new()
2016
{
2117
["db.system"] = "dbSystem",
2218
["db.name"] = "dbName",
@@ -35,12 +31,27 @@ internal sealed class MsgPackTraceExporter : MsgPackExporter, IDisposable
3531
};
3632

3733
#if NET8_0_OR_GREATER
38-
private static readonly FrozenDictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY.ToFrozenDictionary();
34+
internal static readonly FrozenDictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY.ToFrozenDictionary();
35+
#else
36+
internal static readonly Dictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY;
37+
#endif
38+
39+
internal readonly ThreadLocal<byte[]> Buffer = new();
40+
41+
#if NET8_0_OR_GREATER
42+
internal readonly FrozenSet<string> CustomFields;
43+
44+
internal readonly FrozenSet<string> DedicatedFields;
3945
#else
40-
private static readonly Dictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY;
46+
internal readonly HashSet<string> CustomFields;
47+
48+
internal readonly HashSet<string> DedicatedFields;
4149
#endif
4250

43-
private readonly ThreadLocal<byte[]> buffer = new();
51+
private const int BUFFER_SIZE = 65360; // the maximum ETW payload (inclusive)
52+
53+
private static readonly string INVALID_SPAN_ID = default(ActivitySpanId).ToHexString();
54+
4455
private readonly byte[] bufferPrologue;
4556
private readonly byte[] bufferEpilogue;
4657
private readonly ushort prepopulatedFieldsCount;
@@ -49,16 +60,6 @@ internal sealed class MsgPackTraceExporter : MsgPackExporter, IDisposable
4960
private readonly IDataTransport dataTransport;
5061
private readonly bool shouldIncludeTraceState;
5162

52-
#if NET8_0_OR_GREATER
53-
private readonly FrozenSet<string> customFields;
54-
55-
private readonly FrozenSet<string> dedicatedFields;
56-
#else
57-
private readonly HashSet<string> customFields;
58-
59-
private readonly HashSet<string> dedicatedFields;
60-
#endif
61-
6263
private bool isDisposed;
6364

6465
public MsgPackTraceExporter(GenevaExporterOptions options)
@@ -117,9 +118,9 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
117118
}
118119

119120
#if NET8_0_OR_GREATER
120-
this.customFields = customFields.ToFrozenSet(StringComparer.Ordinal);
121+
this.CustomFields = customFields.ToFrozenSet(StringComparer.Ordinal);
121122
#else
122-
this.customFields = customFields;
123+
this.CustomFields = customFields;
123124
#endif
124125

125126
foreach (var name in CS40_PART_B_MAPPING.Keys)
@@ -131,9 +132,9 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
131132
dedicatedFields.Add("otel.status_description");
132133

133134
#if NET8_0_OR_GREATER
134-
this.dedicatedFields = dedicatedFields.ToFrozenSet(StringComparer.Ordinal);
135+
this.DedicatedFields = dedicatedFields.ToFrozenSet(StringComparer.Ordinal);
135136
#else
136-
this.dedicatedFields = dedicatedFields;
137+
this.DedicatedFields = dedicatedFields;
137138
#endif
138139
}
139140

@@ -180,18 +181,15 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
180181
}
181182

182183
this.bufferPrologue = new byte[cursor - 0];
183-
Buffer.BlockCopy(buffer, 0, this.bufferPrologue, 0, cursor - 0);
184+
System.Buffer.BlockCopy(buffer, 0, this.bufferPrologue, 0, cursor - 0);
184185

185186
cursor = MessagePackSerializer.Serialize(buffer, 0, new Dictionary<string, object> { { "TimeFormat", "DateTime" } });
186187

187188
this.bufferEpilogue = new byte[cursor - 0];
188-
Buffer.BlockCopy(buffer, 0, this.bufferEpilogue, 0, cursor - 0);
189+
System.Buffer.BlockCopy(buffer, 0, this.bufferEpilogue, 0, cursor - 0);
189190
}
190191

191-
internal bool IsUsingUnixDomainSocket
192-
{
193-
get => this.dataTransport is UnixDomainSocketDataTransport;
194-
}
192+
internal bool IsUsingUnixDomainSocket => this.dataTransport is UnixDomainSocketDataTransport;
195193

196194
public ExportResult Export(in Batch<Activity> batch)
197195
{
@@ -210,7 +208,7 @@ public ExportResult Export(in Batch<Activity> batch)
210208
try
211209
{
212210
var cursor = this.SerializeActivity(activity);
213-
this.dataTransport.Send(this.buffer.Value, cursor - 0);
211+
this.dataTransport.Send(this.Buffer.Value, cursor - 0);
214212
}
215213
catch (Exception ex)
216214
{
@@ -234,7 +232,7 @@ public void Dispose()
234232
try
235233
{
236234
(this.dataTransport as IDisposable)?.Dispose();
237-
this.buffer.Dispose();
235+
this.Buffer.Dispose();
238236
}
239237
catch (Exception ex)
240238
{
@@ -246,12 +244,12 @@ public void Dispose()
246244

247245
internal int SerializeActivity(Activity activity)
248246
{
249-
var buffer = this.buffer.Value;
247+
var buffer = this.Buffer.Value;
250248
if (buffer == null)
251249
{
252250
buffer = new byte[BUFFER_SIZE]; // TODO: handle OOM
253-
Buffer.BlockCopy(this.bufferPrologue, 0, buffer, 0, this.bufferPrologue.Length);
254-
this.buffer.Value = buffer;
251+
System.Buffer.BlockCopy(this.bufferPrologue, 0, buffer, 0, this.bufferPrologue.Length);
252+
this.Buffer.Value = buffer;
255253
}
256254

257255
var cursor = this.bufferPrologue.Length;
@@ -380,7 +378,7 @@ internal int SerializeActivity(Activity activity)
380378
statusDescription = Convert.ToString(entry.Value, CultureInfo.InvariantCulture);
381379
continue;
382380
}
383-
else if (this.customFields == null || this.customFields.Contains(entry.Key))
381+
else if (this.CustomFields == null || this.CustomFields.Contains(entry.Key))
384382
{
385383
// TODO: the above null check can be optimized and avoided inside foreach.
386384
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, entry.Key);
@@ -407,7 +405,7 @@ internal int SerializeActivity(Activity activity)
407405
foreach (ref readonly var entry in activity.EnumerateTagObjects())
408406
{
409407
// TODO: check name collision
410-
if (this.dedicatedFields.Contains(entry.Key))
408+
if (this.DedicatedFields.Contains(entry.Key))
411409
{
412410
continue;
413411
}
@@ -454,7 +452,7 @@ internal int SerializeActivity(Activity activity)
454452

455453
MessagePackSerializer.WriteUInt16(buffer, this.mapSizePatchIndex, cntFields);
456454

457-
Buffer.BlockCopy(this.bufferEpilogue, 0, buffer, cursor, this.bufferEpilogue.Length);
455+
System.Buffer.BlockCopy(this.bufferEpilogue, 0, buffer, cursor, this.bufferEpilogue.Length);
458456
cursor += this.bufferEpilogue.Length;
459457

460458
return cursor;

0 commit comments

Comments
 (0)