Skip to content

Commit 35ccac1

Browse files
committed
add tests for cloud extension
1 parent 522cf91 commit 35ccac1

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,16 @@ public void SerializationTestWithILoggerLogWithTemplates(bool hasTableNameMappin
664664
{
665665
PrepopulatedFields = new Dictionary<string, object>
666666
{
667-
["cloud.role"] = "BusyWorker",
668-
["cloud.roleInstance"] = "CY1SCH030021417",
669667
["cloud.roleVer"] = "9.0.15289.2",
670668
["prepopulated"] = "prepopulated field",
671669
},
672670
};
673671

674-
var resource = ResourceBuilder.CreateEmpty().AddAttributes([new KeyValuePair<string, object>("resourceAttr", "from resource")]).Build();
672+
var resource = ResourceBuilder.CreateEmpty().AddAttributes([
673+
new KeyValuePair<string, object>("resourceAttr", "from resource"),
674+
new KeyValuePair<string, object>("service.name", "BusyWorker"),
675+
new KeyValuePair<string, object>("service.instanceId", "CY1SCH030021417")])
676+
.Build();
675677

676678
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
677679
{
@@ -1712,7 +1714,12 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
17121714
foreach (var item in exporterOptions.PrepopulatedFields)
17131715
{
17141716
var partAValue = item.Value as string;
1715-
var partAKey = MsgPackExporter.V40_PART_A_MAPPING.GetValueOrDefault(item.Key, item.Key);
1717+
var partAKey = item.Key;
1718+
if (MsgPackExporter.V40_PART_A_MAPPING.ContainsKey(item.Key))
1719+
{
1720+
partAKey = MsgPackExporter.V40_PART_A_MAPPING[item.Key];
1721+
}
1722+
17161723
Assert.Equal(partAValue, mapping[partAKey]);
17171724
}
17181725

@@ -1737,6 +1744,21 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
17371744
Assert.Equal(logRecord.Exception.Message, mapping["env_ex_msg"]);
17381745
}
17391746

1747+
// Part A cloud extensions
1748+
var serviceNameField = resource.Attributes.FirstOrDefault(attr => attr.Key == "service.name");
1749+
if (serviceNameField.Key == "service.name" && !exporterOptions.PrepopulatedFields.ContainsKey("cloud.role"))
1750+
{
1751+
Assert.Contains("env_cloud_role", mapping);
1752+
Assert.Equal(serviceNameField.Value, mapping["env_cloud_role"]);
1753+
}
1754+
1755+
var serviceInstanceField = resource.Attributes.FirstOrDefault(attr => attr.Key == "service.instanceId");
1756+
if (serviceInstanceField.Key == "service.instanceId" && !exporterOptions.PrepopulatedFields.ContainsKey("cloud.roleInstance"))
1757+
{
1758+
Assert.Contains("env_cloud_roleInstance", mapping);
1759+
Assert.Equal(serviceInstanceField.Value, mapping["env_cloud_roleInstance"]);
1760+
}
1761+
17401762
// Part B fields
17411763

17421764
// `LogRecord.LogLevel` was marked Obsolete in https://github.com/open-telemetry/opentelemetry-dotnet/pull/4568
@@ -1810,6 +1832,12 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
18101832

18111833
foreach (var item in resource.Attributes)
18121834
{
1835+
if (item.Key == "service.name" || item.Key == "service.instanceId")
1836+
{
1837+
// these ones are already checked.
1838+
continue;
1839+
}
1840+
18131841
if (exporterOptions.CustomFields == null || exporterOptions.CustomFields.Contains(item.Key))
18141842
{
18151843
// It should be found as a custom field

0 commit comments

Comments
 (0)