Skip to content

Commit 4fe49d6

Browse files
[OTLP] Assert no warnings or errors
Verify that there are no warnings or errors during the integration tests.
1 parent 22bb5ef commit 4fe49d6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public void TraceExportResultIsSuccess(
176176
Assert.Single(exportResults);
177177
Assert.Equal(ExportResult.Success, exportResults[0]);
178178
}
179+
180+
Assert.Empty(this.openTelemetryEventListener.Errors);
181+
Assert.Empty(this.openTelemetryEventListener.Warnings);
179182
}
180183

181184
[Trait("CategoryName", "CollectorIntegrationTests")]
@@ -198,7 +201,8 @@ public void MetricExportResultIsSuccess(
198201
var meterName = "otlp.collector.test";
199202

200203
var builder = Sdk.CreateMeterProviderBuilder()
201-
.AddMeter(meterName);
204+
.AddMeter(meterName)
205+
.AddMeter("System.Net.Http", "System.Net.NameResolution", "System.Runtime");
202206

203207
var readerOptions = new MetricReaderOptions();
204208
readerOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = useManualExport ? Timeout.Infinite : ExportIntervalMilliseconds;
@@ -252,6 +256,9 @@ public void MetricExportResultIsSuccess(
252256
Assert.Single(exportResults);
253257
Assert.Equal(ExportResult.Success, exportResults[0]);
254258
}
259+
260+
Assert.Empty(this.openTelemetryEventListener.Errors);
261+
Assert.Empty(this.openTelemetryEventListener.Warnings);
255262
}
256263

257264
[Trait("CategoryName", "CollectorIntegrationTests")]
@@ -324,6 +331,9 @@ public void LogExportResultIsSuccess(
324331
default:
325332
throw new NotSupportedException("Unexpected processor type encountered.");
326333
}
334+
335+
Assert.Empty(this.openTelemetryEventListener.Errors);
336+
Assert.Empty(this.openTelemetryEventListener.Warnings);
327337
}
328338

329339
private static OtlpExporterOptions CreateExporterOptions(OtlpExportProtocol protocol, string scheme, string endpoint) =>
@@ -335,6 +345,10 @@ private static OtlpExporterOptions CreateExporterOptions(OtlpExportProtocol prot
335345

336346
private sealed class OpenTelemetryEventListener(ITestOutputHelper outputHelper) : EventListener
337347
{
348+
public List<string> Errors { get; } = [];
349+
350+
public List<string> Warnings { get; } = [];
351+
338352
protected override void OnEventSourceCreated(EventSource eventSource)
339353
{
340354
base.OnEventSourceCreated(eventSource);
@@ -354,6 +368,15 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
354368
message = string.Format(CultureInfo.InvariantCulture, "[{0}] {1}", eventData.Level, message);
355369

356370
outputHelper.WriteLine(message);
371+
372+
if (eventData.Level == EventLevel.Error)
373+
{
374+
this.Errors.Add(message);
375+
}
376+
else if (eventData.Level == EventLevel.Warning)
377+
{
378+
this.Warnings.Add(message);
379+
}
357380
}
358381
}
359382
}

0 commit comments

Comments
 (0)