Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information

using System.Runtime.InteropServices;
using FluentAssertions;
using Nullean.Xunit.Partitions.Sdk;
using Xunit;

Expand All @@ -15,12 +14,13 @@ public class PluginLoaderTests(ExampleApplicationContainer exampleApplicationCon
public async Task ObserveDistributionPluginLoad()
{
await Task.Delay(TimeSpan.FromSeconds(3));

var output = exampleApplicationContainer.FailureTestOutput();
output.Should()
.NotBeNullOrWhiteSpace()
.And.Contain("Elastic Distribution of OpenTelemetry .NET:")
.And.Contain("ElasticOpenTelemetryBuilder initialized")
.And.Contain("Added 'Elastic.OpenTelemetry.Processors.ElasticCompatibilityProcessor'");

Assert.False(string.IsNullOrWhiteSpace(output));
Assert.Contains("Elastic Distribution of OpenTelemetry (EDOT) .NET:", output);
Assert.Contains("ElasticOpenTelemetryBuilder initialized", output);
Assert.Contains("Added 'Elastic.OpenTelemetry.Processors.ElasticCompatibilityProcessor'", output);
}
}

Expand Down
11 changes: 3 additions & 8 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
</PropertyGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(ProjectName), '^(.*)Tests$'))">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="All" />
<PackageReference Include="JunitXml.TestLogger" Version="3.1.12" PrivateAssets="All" />
<PackageReference Include="Nullean.VsTest.Pretty.TestLogger" Version="0.4.0" PrivateAssets="All" />

<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.31.0" />

<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information

using System.Net;
using FluentAssertions;
using Xunit;

namespace Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;

Expand All @@ -19,7 +19,7 @@ public async Task Start(DistributedApplicationFixture distributedInfra)
for (var i = 0; i < 10; i++)
{
var get = await distributedInfra.AspNetApplication.HttpClient.GetAsync("e2e");
get.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, get.StatusCode);
_ = await get.Content.ReadAsStringAsync();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
Expand All @@ -11,12 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.49.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.50.0" />
<PackageReference Include="Nullean.Xunit.Partitions" Version="0.5.0" />
<PackageReference Include="Proc" Version="0.8.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Proc" Version="0.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.2" />
</ItemGroup>

</Project>
15 changes: 5 additions & 10 deletions tests/Elastic.OpenTelemetry.EndToEndTests/EndToEndOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using Elastic.OpenTelemetry.EndToEndTests;
using Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Nullean.Xunit.Partitions;
using Xunit;
Expand All @@ -29,19 +28,15 @@ public override void OnBeforeTestsRun()
if (testSuite == null || (
!testSuite.Equals("e2e", StringComparison.InvariantCultureIgnoreCase)
&& !testSuite.Equals("all", StringComparison.InvariantCultureIgnoreCase))
)
)
return;

try
{
configuration["E2E:Endpoint"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:Endpoint configuration");
configuration["E2E:Authorization"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:Authorization configuration");
configuration["E2E:BrowserEmail"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:BrowserEmail configuration");
configuration["E2E:BrowserPassword"].Should()
.NotBeNullOrWhiteSpace("Missing E2E:BrowserPassword configuration");
Assert.False(string.IsNullOrWhiteSpace(configuration["E2E:Endpoint"]), userMessage: "Missing E2E:Endpoint configuration");
Assert.False(string.IsNullOrWhiteSpace(configuration["E2E:Authorization"]), userMessage: "Missing E2E:Authorization configuration");
Assert.False(string.IsNullOrWhiteSpace(configuration["E2E:BrowserEmail"]), userMessage: "Missing E2E:BrowserEmail configuration");
Assert.False(string.IsNullOrWhiteSpace(configuration["E2E:BrowserPassword"]), userMessage: "Missing E2E:BrowserPassword configuration");
}
catch (Exception e)
{
Expand Down
3 changes: 1 addition & 2 deletions tests/Elastic.OpenTelemetry.EndToEndTests/ServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information

using Elastic.OpenTelemetry.EndToEndTests.DistributedFixture;
using FluentAssertions;
using Microsoft.Playwright;
using Nullean.Xunit.Partitions.Sdk;
using Xunit;
Expand All @@ -20,12 +19,12 @@
private IPage _page = null!;

[Fact]
public void EnsureApplicationWasStarted() => fixture.Started.Should().BeTrue();
public void EnsureApplicationWasStarted() => Assert.True(fixture.Started);

Check failure on line 22 in tests/Elastic.OpenTelemetry.EndToEndTests/ServiceTests.cs

View workflow job for this annotation

GitHub Actions / test

Elastic.OpenTelemetry.EndToEndTests.EndToEndTests.EnsureApplicationWasStarted

System.TimeoutException : Timeout 5000ms exceeded. Call log: - - waiting for GetByRole(AriaRole.Link, new() { Name = "dotnet-e2e-ca4cf42639c5" }) to be visible

[Fact]
public async Task LatencyShowsAGraph()
{
var timeout = (float)TimeSpan.FromSeconds(30).TotalMilliseconds;

Check failure on line 27 in tests/Elastic.OpenTelemetry.EndToEndTests/ServiceTests.cs

View workflow job for this annotation

GitHub Actions / test

Elastic.OpenTelemetry.EndToEndTests.EndToEndTests.LatencyShowsAGraph

System.TimeoutException : Timeout 5000ms exceeded. Call log: - - waiting for GetByRole(AriaRole.Link, new() { Name = "dotnet-e2e-ca4cf42639c5" }) to be visible

// click on service in service overview page.
var uri = new Uri(fixture.ApmUI.KibanaAppUri, $"/app/apm/services/{fixture.ServiceName}/overview").ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void WritesErrorWhenUnableToBootstrap()

var error = sut.GetErrorText();

error.Should().StartWith("Unable to bootstrap EDOT .NET due to");
error.Should().Contain(TestableAutoInstrumentationPlugin.ExceptionMessage);
Assert.StartsWith("Unable to bootstrap EDOT .NET due to", error);
Assert.Contains(TestableAutoInstrumentationPlugin.ExceptionMessage, error);
}

private class TestableAutoInstrumentationPlugin : AutoInstrumentationPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ public void DefaultCtor_SetsExpectedDefaults_WhenNoEnvironmentVariablesAreConfig
{ ELASTIC_OTEL_SKIP_OTLP_EXPORTER, null },
});

sut.GlobalLogEnabled.Should().Be(false);
Assert.False(sut.GlobalLogEnabled);

// these default to null because any other value would enable file logging
sut.LogDirectory.Should().Be(sut.LogDirectoryDefault);
sut.LogLevel.Should().Be(LogLevel.Warning);
Assert.Equal(sut.LogDirectoryDefault, sut.LogDirectory);
Assert.Equal(LogLevel.Warning, sut.LogLevel);

sut.SkipOtlpExporter.Should().Be(false);
Assert.False(sut.SkipOtlpExporter);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Count.Should().Be(ExpectedLogsLength);
Assert.Equal(ExpectedLogsLength, logger.Messages.Count);

foreach (var message in logger.Messages)
message.Should().EndWith("from [Default]");
Assert.EndsWith("from [Default]", message);
}

[Fact]
Expand All @@ -58,18 +60,17 @@ public void DefaultCtor_LoadsConfigurationFromEnvironmentVariables()
{ ELASTIC_OTEL_SKIP_OTLP_EXPORTER, "true" },
});

sut.LogDirectory.Should().Be(fileLogDirectory);
sut.LogLevel.Should().Be(ToLogLevel(fileLogLevel));
sut.SkipOtlpExporter.Should().Be(true);
Assert.Equal(fileLogDirectory, sut.LogDirectory);
Assert.Equal(ToLogLevel(fileLogLevel), sut.LogLevel);
Assert.True(sut.SkipOtlpExporter);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Should()
.Contain(s => s.EndsWith("from [Environment]"))
.And.Contain(s => s.EndsWith("from [Default]"))
.And.NotContain(s => s.EndsWith("from [IConfiguration]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Environment]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Default]"));
Assert.DoesNotContain(logger.Messages, s => s.EndsWith("from [IConfiguration]"));
}

[Fact]
Expand Down Expand Up @@ -104,21 +105,21 @@ public void ConfigurationCtor_LoadsConfigurationFromIConfiguration()

var sut = new CompositeElasticOpenTelemetryOptions(config, new Hashtable());

sut.LogDirectory.Should().Be(@"C:\Temp");
sut.LogLevel.Should().Be(ToLogLevel(fileLogLevel));
sut.SkipOtlpExporter.Should().Be(true);
sut.EventLogLevel.Should().Be(EventLevel.Warning);
sut.LogLevel.Should().Be(LogLevel.Critical);
Assert.Equal(@"C:\Temp", sut.LogDirectory);
Assert.Equal(ToLogLevel(fileLogLevel), sut.LogLevel);
Assert.True(sut.SkipOtlpExporter);
Assert.Equal(EventLevel.Warning, sut.EventLogLevel);
Assert.Equal(LogLevel.Critical, sut.LogLevel);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Count.Should().Be(ExpectedLogsLength);
logger.Messages.Should()
.Contain(s => s.EndsWith("from [IConfiguration]"))
.And.Contain(s => s.EndsWith("from [Default]"))
.And.NotContain(s => s.EndsWith("from [Environment]"));
Assert.Equal(ExpectedLogsLength, logger.Messages.Count);

Assert.Contains(logger.Messages, s => s.EndsWith("from [IConfiguration]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Default]"));
Assert.DoesNotContain(logger.Messages, s => s.EndsWith("from [Environment]"));
}

[Fact]
Expand Down Expand Up @@ -151,20 +152,19 @@ public void ConfigurationCtor_LoadsConfigurationFromIConfiguration_AndFallsBackT

var sut = new CompositeElasticOpenTelemetryOptions(config, new Hashtable());

sut.LogDirectory.Should().Be(@"C:\Temp");
sut.LogLevel.Should().Be(ToLogLevel(loggingSectionLogLevel));
sut.SkipOtlpExporter.Should().Be(true);
sut.LogLevel.Should().Be(LogLevel.Warning);
sut.EventLogLevel.Should().Be(EventLevel.Warning);
Assert.Equal(@"C:\Temp", sut.LogDirectory);
Assert.Equal(ToLogLevel(loggingSectionLogLevel), sut.LogLevel);
Assert.True(sut.SkipOtlpExporter);
Assert.Equal(EventLevel.Warning, sut.EventLogLevel);
Assert.Equal(LogLevel.Warning, sut.LogLevel);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Should()
.Contain(s => s.EndsWith("from [IConfiguration]"))
.And.Contain(s => s.EndsWith("from [Default]"))
.And.NotContain(s => s.EndsWith("from [Environment]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [IConfiguration]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Default]"));
Assert.DoesNotContain(logger.Messages, s => s.EndsWith("from [Environment]"));
}

[Fact]
Expand Down Expand Up @@ -196,19 +196,18 @@ public void ConfigurationCtor_LoadsConfigurationFromIConfiguration_AndFallsBackT

var sut = new CompositeElasticOpenTelemetryOptions(config, new Hashtable());

sut.LogDirectory.Should().Be(@"C:\Temp");
sut.LogLevel.Should().Be(ToLogLevel(loggingSectionDefaultLogLevel));
sut.SkipOtlpExporter.Should().Be(true);
sut.EventLogLevel.Should().Be(EventLevel.Informational);
Assert.Equal(@"C:\Temp", sut.LogDirectory);
Assert.Equal(ToLogLevel(loggingSectionDefaultLogLevel), sut.LogLevel);
Assert.True(sut.SkipOtlpExporter);
Assert.Equal(EventLevel.Informational, sut.EventLogLevel);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Should()
.Contain(s => s.EndsWith("from [IConfiguration]"))
.And.Contain(s => s.EndsWith("from [Default]"))
.And.NotContain(s => s.EndsWith("from [Environment]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [IConfiguration]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Default]"));
Assert.DoesNotContain(logger.Messages, s => s.EndsWith("from [Environment]"));
}

[Fact]
Expand Down Expand Up @@ -241,9 +240,10 @@ public void EnvironmentVariables_TakePrecedenceOver_ConfigValues()
{ ELASTIC_OTEL_SKIP_OTLP_EXPORTER, "true" },
});

sut.LogDirectory.Should().Be(fileLogDirectory);
sut.LogLevel.Should().Be(ToLogLevel(fileLogLevel));
sut.SkipOtlpExporter.Should().Be(true);
Assert.Equal(fileLogDirectory, sut.LogDirectory);
Assert.Equal(ToLogLevel(fileLogLevel), sut.LogLevel);
Assert.True(sut.SkipOtlpExporter);

}

[Fact]
Expand All @@ -264,17 +264,16 @@ public void InitializedProperties_TakePrecedenceOver_EnvironmentValues()
SkipOtlpExporter = false,
};

sut.LogDirectory.Should().Be(fileLogDirectory);
sut.LogLevel.Should().Be(ToLogLevel(fileLogLevel));
sut.SkipOtlpExporter.Should().Be(false);
Assert.Equal(fileLogDirectory, sut.LogDirectory);
Assert.Equal(ToLogLevel(fileLogLevel), sut.LogLevel);
Assert.False(sut.SkipOtlpExporter);

var logger = new TestLogger(output);

sut.LogConfigSources(logger);

logger.Messages.Should()
.Contain(s => s.EndsWith("from [Property]"))
.And.Contain(s => s.EndsWith("from [Default]"))
.And.NotContain(s => s.EndsWith("from [Environment]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Property]"));
Assert.Contains(logger.Messages, s => s.EndsWith("from [Default]"));
Assert.DoesNotContain(logger.Messages, s => s.EndsWith("from [Environment]"));
}
}
Loading
Loading