Skip to content

Commit 15ed85c

Browse files
committed
proof reading
1 parent 0bf70d1 commit 15ed85c

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterAFDCorrelationTests.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public void AFDCorrelationIdLogProcessor_MultithreadedAccess_HandlesGracefully()
6767

6868
List<string> exportedCorrelationIds = [];
6969
int foundWithoutCorrelationIds = 0;
70-
var msgPackExporter = exporter.Exporter as MsgPackLogExporter;
71-
msgPackExporter.DataTransportListener = (data) =>
70+
(exporter.Exporter as MsgPackLogExporter).DataTransportListener = (data) =>
7271
{
7372
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(data, MessagePack.Resolvers.ContractlessStandardResolver.Options);
7473
var signal = (fluentdData as object[])[0] as string;
@@ -211,18 +210,17 @@ public void AFDCorrelationIdLogProcessor_WithoutCorrelationId_HandlesGracefully(
211210
receiverSocket.ReceiveTimeout = 10000;
212211
}
213212

214-
byte[] serializedData = null;
215-
var msgPackExporter = exporter.Exporter as MsgPackLogExporter;
216-
msgPackExporter.DataTransportListener = (data) => serializedData = [.. data];
213+
List<ArraySegment<byte>> exportedData = [];
214+
(exporter.Exporter as MsgPackLogExporter).DataTransportListener = (data) => exportedData.Add(data);
217215

218216
// In this test, AFDCorrelationId is not set in RuntimeContext
219217
var logger = loggerFactory.CreateLogger<GenevaLogExporterTests>();
220218
logger.LogInformation("No correlation ID should be present");
221219
loggerFactory.Dispose();
222220

223-
Assert.NotNull(serializedData);
221+
Assert.Single(exportedData);
224222

225-
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(serializedData, MessagePack.Resolvers.ContractlessStandardResolver.Options);
223+
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
226224
var signal = (fluentdData as object[])[0] as string;
227225
var TimeStampAndMappings = ((fluentdData as object[])[1] as object[])[0];
228226
var mapping = (TimeStampAndMappings as object[])[1] as Dictionary<object, object>;
@@ -298,21 +296,17 @@ public void GenevaExporter_WithAFDCorrelationId_IncludesCorrelationId()
298296
receiverSocket.ReceiveTimeout = 10000;
299297
}
300298

301-
byte[] serializedData = null;
302-
var msgPackExporter = exporter.Exporter as MsgPackLogExporter;
303-
msgPackExporter.DataTransportListener = (data) =>
304-
{
305-
serializedData = [.. data];
306-
};
299+
List<ArraySegment<byte>> exportedData = [];
300+
(exporter.Exporter as MsgPackLogExporter).DataTransportListener = (data) => exportedData.Add(data);
307301

308302
// Emit a LogRecord and grab a copy of internal buffer for validation.
309303
var logger = loggerFactory.CreateLogger<GenevaLogExporterTests>();
310304
logger.LogInformation("Hello from {Food} {Price}.", "artichoke", 3.99);
311305
loggerFactory.Dispose();
312306

313-
Assert.NotNull(serializedData); // data should have been sent by now
307+
Assert.Single(exportedData);
314308

315-
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(serializedData, MessagePack.Resolvers.ContractlessStandardResolver.Options);
309+
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
316310
var signal = (fluentdData as object[])[0] as string;
317311
var TimeStampAndMappings = ((fluentdData as object[])[1] as object[])[0];
318312
var mapping = (TimeStampAndMappings as object[])[1] as Dictionary<object, object>;

test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,17 @@ public void PassThruTableMappingsWhenTheRuleIsEnabled()
320320
server.Listen(1);
321321
}
322322

323+
using var exporter = new GenevaLogExporter(exporterOptions);
324+
323325
using var loggerFactory = LoggerFactory.Create(builder => builder
324326
.AddOpenTelemetry(options =>
325327
{
326-
options.AddInMemoryExporter(logRecordList);
328+
options.AddProcessor(new ReentrantExportProcessor<LogRecord>(exporter));
327329
})
328330
.AddFilter("*", LogLevel.Trace)); // Enable all LogLevels
329331

330-
// Create a test exporter to get MessagePack byte data to validate if the data was serialized correctly.
331-
using var exporter = new MsgPackLogExporter(exporterOptions, () => Resource.Empty);
332-
333-
ArraySegment<byte>? exportedData = null;
334-
exporter.DataTransportListener = (data) => exportedData = data;
332+
List<ArraySegment<byte>> exportedData = [];
333+
(exporter.Exporter as MsgPackLogExporter).DataTransportListener = (data) => exportedData.Add(data);
335334

336335
ILogger passThruTableMappingsLogger, userInitializedTableMappingsLogger;
337336
object fluentdData;
@@ -340,35 +339,31 @@ public void PassThruTableMappingsWhenTheRuleIsEnabled()
340339
// Verify that the category table mappings specified by the users in the Geneva Configuration are mapped correctly.
341340
foreach (var mapping in userInitializedCategoryToTableNameMappings)
342341
{
343-
exportedData = null;
344342
if (mapping.Key != "*")
345343
{
346344
userInitializedTableMappingsLogger = loggerFactory.CreateLogger(mapping.Key);
347345
userInitializedTableMappingsLogger.LogInformation("This information does not matter.");
348346
Assert.Single(logRecordList);
347+
Assert.Single(exportedData);
349348

350-
_ = exporter.Export(new Batch<LogRecord>(logRecordList[0]));
351-
Assert.True(exportedData.HasValue);
352-
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData.Value, MessagePack.Resolvers.ContractlessStandardResolver.Options);
349+
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
353350
actualTableName = (fluentdData as object[])[0] as string;
354351
userInitializedCategoryToTableNameMappings.TryGetValue(mapping.Key, out var expectedTableNme);
355352
Assert.Equal(expectedTableNme, actualTableName);
356-
357-
logRecordList.Clear();
358353
}
354+
logRecordList.Clear();
355+
exportedData.Clear();
359356
}
360357

361358
// Verify that when the "*" = "*" were enabled, the correct table names were being deduced following the set of rules.
362359
foreach (var mapping in expectedCategoryToTableNameList)
363360
{
364-
exportedData = null;
365361
passThruTableMappingsLogger = loggerFactory.CreateLogger(mapping.Key);
366362
passThruTableMappingsLogger.LogInformation("This information does not matter.");
367-
Assert.Single(logRecordList);
368363

369-
_ = exporter.Export(new Batch<LogRecord>(logRecordList[0]));
370-
Assert.True(exportedData.HasValue);
371-
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData.Value, MessagePack.Resolvers.ContractlessStandardResolver.Options);
364+
Assert.Single(logRecordList);
365+
Assert.Single(exportedData);
366+
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
372367
actualTableName = (fluentdData as object[])[0] as string;
373368
var expectedTableName = string.Empty;
374369
expectedTableName = mapping.Value;
@@ -415,7 +410,7 @@ public void SerializeILoggerScopes(bool hasCustomFields)
415410
exporterOptions.CustomFields = ["Food", "Name", "Key1"];
416411
}
417412

418-
var exportedItems = new List<LogRecord>();
413+
var exportedLogs = new List<LogRecord>();
419414

420415
var resourceBuilder = ResourceBuilder.CreateEmpty().AddAttributes([
421416
new KeyValuePair<string, object>("resourceAttr", "from resource"),
@@ -430,7 +425,7 @@ public void SerializeILoggerScopes(bool hasCustomFields)
430425
{
431426
options.IncludeScopes = true;
432427
options.SetResourceBuilder(resourceBuilder);
433-
options.AddInMemoryExporter(exportedItems);
428+
options.AddInMemoryExporter(exportedLogs);
434429
options.AddProcessor(new ReentrantExportProcessor<LogRecord>(exporter));
435430
}));
436431

@@ -449,9 +444,9 @@ public void SerializeILoggerScopes(bool hasCustomFields)
449444
logger.LogInformation("Hello from {Food} {Price}.", "artichoke", 3.99);
450445
}
451446

452-
Assert.Single(exportedItems);
447+
Assert.Single(exportedLogs);
453448
Assert.Single(exportedData);
454-
var logRecord = exportedItems[0];
449+
var logRecord = exportedLogs[0];
455450

456451
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
457452
var signal = (fluentdData as object[])[0] as string;
@@ -545,14 +540,14 @@ public void SerializationTestWithILoggerLogMethod(bool includeFormattedMessage,
545540
]);
546541

547542
using var exporter = new GenevaLogExporter(exporterOptions);
548-
List<LogRecord> exportedItems = [];
543+
List<LogRecord> exportedLogs = [];
549544

550545
using var loggerFactory = LoggerFactory.Create(builder => builder
551546
.AddOpenTelemetry(options =>
552547
{
553548
options.SetResourceBuilder(resourceBuilder);
554549
options.AddProcessor(new ReentrantExportProcessor<LogRecord>(exporter));
555-
options.AddInMemoryExporter(exportedItems);
550+
options.AddInMemoryExporter(exportedLogs);
556551
options.IncludeFormattedMessage = includeFormattedMessage;
557552
})
558553
.AddFilter(typeof(GenevaLogExporterTests).FullName, LogLevel.Trace)); // Enable all LogLevels
@@ -577,13 +572,14 @@ public void SerializationTestWithILoggerLogMethod(bool includeFormattedMessage,
577572
(state, ex) => "Formatted Message");
578573

579574
// VALIDATE
575+
Assert.Single(exportedLogs);
580576
Assert.Single(exportedData);
581577
var fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
582-
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedItems[0]);
578+
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedLogs[0]);
583579

584580
// ARRANGE
581+
exportedLogs.Clear();
585582
exportedData.Clear();
586-
exportedItems.Clear();
587583

588584
// ACT
589585
// This is treated as Un-structured logging as the state cannot be converted to IReadOnlyList<KeyValuePair<string, object>>
@@ -595,13 +591,14 @@ public void SerializationTestWithILoggerLogMethod(bool includeFormattedMessage,
595591
formatter: (state, ex) => "Formatted Message");
596592

597593
// VALIDATE
594+
Assert.Single(exportedLogs);
598595
Assert.Single(exportedData);
599596
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
600-
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedItems[0]);
597+
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedLogs[0]);
601598

602599
// ARRANGE
600+
exportedLogs.Clear();
603601
exportedData.Clear();
604-
exportedItems.Clear();
605602

606603
// ACT
607604
// This is treated as Un-structured logging as the state cannot be converted to IReadOnlyList<KeyValuePair<string, object>>
@@ -613,13 +610,14 @@ public void SerializationTestWithILoggerLogMethod(bool includeFormattedMessage,
613610
formatter: null);
614611

615612
// VALIDATE
613+
Assert.Single(exportedLogs);
616614
Assert.Single(exportedData);
617615
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
618-
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedItems[0]);
616+
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedLogs[0]);
619617

620618
// ARRANGE
619+
exportedLogs.Clear();
621620
exportedData.Clear();
622-
exportedItems.Clear();
623621

624622
// ACT
625623
// This is treated as Structured logging as the state can be converted to IReadOnlyList<KeyValuePair<string, object>>
@@ -634,9 +632,10 @@ public void SerializationTestWithILoggerLogMethod(bool includeFormattedMessage,
634632
formatter: (state, ex) => "Example formatted message.");
635633

636634
// VALIDATE
635+
Assert.Single(exportedLogs);
637636
Assert.Single(exportedData);
638637
fluentdData = MessagePack.MessagePackSerializer.Deserialize<object>(exportedData[0], MessagePack.Resolvers.ContractlessStandardResolver.Options);
639-
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedItems[0]);
638+
this.AssertFluentdForwardModeForLogRecord(exporterOptions, resourceBuilder.Build(), fluentdData, exportedLogs[0]);
640639
}
641640
finally
642641
{
@@ -1931,7 +1930,7 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
19311930

19321931
if (exporterOptions.ResourceFieldNames != null && exporterOptions.ResourceFieldNames.Contains(item.Key))
19331932
{
1934-
// It should be found as a custom field
1933+
// It should always be found as a custom field
19351934
if (item.Value != null)
19361935
{
19371936
Assert.Equal(item.Value, mapping[item.Key]);

test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public void GenevaTraceExporter_Success_Windows()
217217
}
218218
}
219219

220+
// hasResourceAttributes and hasPrepopulatedFields are mutually exclusive
220221
[Theory]
221222
[InlineData(false, false, false, false, true)]
222223
[InlineData(false, true, false, false, true)]
@@ -234,6 +235,14 @@ public void GenevaTraceExporter_Success_Windows()
234235
[InlineData(false, true, true, true, false)]
235236
[InlineData(true, false, true, true, false)]
236237
[InlineData(true, true, true, true, false)]
238+
[InlineData(false, false, false, false, false)]
239+
[InlineData(false, true, false, false, false)]
240+
[InlineData(true, false, false, false, false)]
241+
[InlineData(true, true, false, false, false)]
242+
[InlineData(false, false, true, false, false)]
243+
[InlineData(false, true, true, false, false)]
244+
[InlineData(true, false, true, false, false)]
245+
[InlineData(true, true, true, false, false)]
237246
public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping, bool hasCustomFields, bool includeTraceState, bool hasPrepopulatedFields, bool hasResourceAttributes)
238247
{
239248
var path = string.Empty;

0 commit comments

Comments
 (0)