Skip to content

Commit

Permalink
use Demo for testing. REVERT THIS BEFORE MERGING
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra committed Feb 27, 2024
1 parent 032c5b3 commit 38bf3f3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
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>
<Description>An OpenTelemetry .NET distro that exports to Azure Monitor</Description>
<AssemblyTitle>AzureMonitor OpenTelemetry ASP.NET Core Distro</AssemblyTitle>
Expand All @@ -24,11 +24,11 @@

<!-- FOR PUBLIC RELEASES, MUST USE PackageReference. THIS REQUIRES A STAGGERED RELEASE IF SHIPPING A NEW EXPORTER. -->
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.LiveMetrics" />
<!--<PackageReference Include="Azure.Monitor.OpenTelemetry.LiveMetrics" />-->

<!-- FOR LOCAL DEV, ProjectReference IS PREFERRED. -->
<!--<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />-->
<!--<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\Azure.Monitor.OpenTelemetry.LiveMetrics.csproj" />-->
<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.LiveMetrics\src\Azure.Monitor.OpenTelemetry.LiveMetrics.csproj" />
</ItemGroup>

<!-- Shared source from Exporter -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// Licensed under the MIT License.

#if NET6_0_OR_GREATER
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using Azure.Monitor.OpenTelemetry.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry().UseAzureMonitor();
//builder.Services.AddOpenTelemetry().UseAzureMonitor();

/*
builder.Services.AddOpenTelemetry().UseAzureMonitor(o =>
Expand All @@ -33,5 +38,52 @@
return $"Hello World! OpenTelemetry Trace: {Activity.Current?.Id}";
});

#if !NETFRAMEWORK
app.MapGet("/StressTest", () =>
{
RunStressTest();
return "StressTest!";
});
#endif

app.Run();
#endif

#if !NETFRAMEWORK
void RunStressTest()
{
// Get the number of available processors
int numProcessors = Environment.ProcessorCount;

Task[] tasks = new Task[numProcessors];

// Start each task
for (int i = 0; i < numProcessors; i++)
{
tasks[i] = Task.Run(() => Compute(cancellationTokenSource.Token));
}

var timeStamp = DateTime.Now.AddSeconds(20);
while (DateTime.Now < timeStamp)
{
// do nothing
}

cancellationTokenSource.Cancel();

Task.WaitAll(tasks);
}

void Compute(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
// Simulate intensive computation
double result = 0;
for (int i = 0; i < 1000000; i++)
{
result += Math.Sqrt(i);
}
}
}
#endif

0 comments on commit 38bf3f3

Please sign in to comment.