Skip to content

Commit fd74132

Browse files
author
Timothy Mothra
authored
[AzureMonitor] update live tests (Azure#49023)
* update tests * cleanup * cleanup csproj * rearranging tests to fix git compare * testing disabling timeout
1 parent eedbc40 commit fd74132

File tree

7 files changed

+2242
-2566
lines changed

7 files changed

+2242
-2566
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Integration.Tests/Azure.Monitor.OpenTelemetry.AspNetCore.Integration.Tests.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,4 @@
1414
<ProjectReference Include="..\..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />
1515
</ItemGroup>
1616

17-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
18-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
19-
</ItemGroup>
20-
21-
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
22-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
23-
</ItemGroup>
24-
2517
</Project>

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Integration.Tests/BaseLiveTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public void Setup()
5050
));
5151
}
5252

53+
public override void GlobalTimeoutTearDown()
54+
{
55+
// Turn off global timeout errors because these tests can be slower
56+
// base.GlobalTimeoutTearDown();
57+
}
58+
5359
internal async Task QueryAndVerifyDependency(string workspaceId, string description, string query, ExpectedAppDependency expectedAppDependency)
5460
{
5561
LogsTable? logsTable = await _logsQueryClient!.QueryTelemetryAsync(workspaceId, description, query);

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/tests/Azure.Monitor.OpenTelemetry.AspNetCore.Integration.Tests/DistroWebAppLiveTests.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Azure.Monitor.Query;
1313
using Azure.Monitor.Query.Models;
1414
using Microsoft.AspNetCore.Builder;
15+
using Microsoft.AspNetCore.Hosting;
1516
using Microsoft.Extensions.DependencyInjection;
1617
using Microsoft.Extensions.Logging;
1718
using NUnit.Framework;
@@ -50,7 +51,7 @@ public DistroWebAppLiveTests(bool isAsync) : base(isAsync) { }
5051

5152
[RecordedTest]
5253
[SyncOnly] // This test cannot run concurrently with another test because OTel instruments the process and will cause side effects.
53-
public async Task VerifyDistro()
54+
public async Task VerifyDistro_UseAzureMonitor()
5455
{
5556
// SETUP WEBAPPLICATION WITH OPENTELEMETRY
5657
var builder = WebApplication.CreateBuilder();
@@ -181,31 +182,27 @@ public async Task VerifySendingToTwoResources_UsingExporter()
181182

182183
[RecordedTest]
183184
[SyncOnly] // This test cannot run concurrently with another test because OTel instruments the process and will cause side effects.
184-
[Ignore("TODO: Repurpose this test to validate the error.")]
185-
public async Task VerifySendingToTwoResources_UsingDistroWithExporter()
185+
public async Task VerifyExporter_UseAzureMonitorExporter()
186186
{
187187
// SETUP WEBAPPLICATION WITH OPENTELEMETRY
188188
var builder = WebApplication.CreateBuilder();
189+
190+
builder.WebHost.UseUrls(TestServerUrl);
191+
189192
builder.Logging.ClearProviders();
190193
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddProcessor(new ActivityEnrichingProcessor()));
191194
builder.Services.AddOpenTelemetry()
192-
.UseAzureMonitor(options =>
195+
.UseAzureMonitorExporter(options =>
193196
{
194197
options.EnableLiveMetrics = false;
195198
options.ConnectionString = TestEnvironment.ConnectionString;
196199
})
197-
.WithTracing(builder =>
198-
{
199-
builder.AddAzureMonitorTraceExporter(name: "secondary", configure: options => options.ConnectionString = TestEnvironment.SecondaryConnectionString);
200-
})
201-
.WithMetrics(builder =>
202-
{
203-
builder.AddAzureMonitorMetricExporter(name: "secondary", configure: options => options.ConnectionString = TestEnvironment.SecondaryConnectionString);
204-
})
205-
.WithLogging(builder =>
206-
{
207-
builder.AddAzureMonitorLogExporter(name: "secondary", configure: options => options.ConnectionString = TestEnvironment.SecondaryConnectionString);
208-
})
200+
.WithTracing(builder => builder
201+
.AddAspNetCoreInstrumentation()
202+
.AddHttpClientInstrumentation())
203+
.WithMetrics(builder => builder
204+
.AddAspNetCoreInstrumentation()
205+
.AddHttpClientInstrumentation())
209206
// Custom resources must be added AFTER AzureMonitor to override the included ResourceDetectors.
210207
.ConfigureResource(x => x.AddAttributes(_testResourceAttributes));
211208

@@ -218,7 +215,7 @@ public async Task VerifySendingToTwoResources_UsingDistroWithExporter()
218215
return "Response from Test Server";
219216
});
220217

221-
_ = app.RunAsync(TestServerUrl);
218+
await app.StartAsync().ConfigureAwait(false); // Start HostedServices
222219

223220
// ACT
224221
using var httpClient = new HttpClient();
@@ -238,7 +235,6 @@ public async Task VerifySendingToTwoResources_UsingDistroWithExporter()
238235

239236
// ASSERT
240237
await VerifyTelemetry(workspaceId: TestEnvironment.WorkspaceId);
241-
await VerifyTelemetry(workspaceId: TestEnvironment.SecondaryWorkspaceId);
242238
}
243239

244240
private async Task VerifyTelemetry(string workspaceId)

0 commit comments

Comments
 (0)