Skip to content

Commit 2f4d319

Browse files
committed
add tests for cloud extension
1 parent 522cf91 commit 2f4d319

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

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

Lines changed: 26 additions & 3 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
{
@@ -1737,6 +1739,21 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
17371739
Assert.Equal(logRecord.Exception.Message, mapping["env_ex_msg"]);
17381740
}
17391741

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

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

18111828
foreach (var item in resource.Attributes)
18121829
{
1830+
if (item.Key == "service.name" || item.Key == "service.instanceId")
1831+
{
1832+
// these ones are already checked.
1833+
continue;
1834+
}
1835+
18131836
if (exporterOptions.CustomFields == null || exporterOptions.CustomFields.Contains(item.Key))
18141837
{
18151838
// It should be found as a custom field

0 commit comments

Comments
 (0)