Skip to content

Commit

Permalink
Add perf test for exporting request telemetry (#35223)
Browse files Browse the repository at this point in the history
* draft

* draft

* Add perf test for ActivityKind.Server

* Running instructions

* rename

* remove mock transport
  • Loading branch information
vishweshbankwar authored Apr 3, 2023
1 parent 0ffec3d commit b4c0695
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Monitor.OpenTelemetry.Exporter.Perf", "perf\Azure.Monitor.OpenTelemetry.Exporter.Perf.csproj", "{D18AC472-8802-4F0B-A8A4-E6E3DA12881E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{5083A0B8-24CE-4AC4-AC23-C9BD87EE2FC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5083A0B8-24CE-4AC4-AC23-C9BD87EE2FC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5083A0B8-24CE-4AC4-AC23-C9BD87EE2FC8}.Release|Any CPU.Build.0 = Release|Any CPU
{D18AC472-8802-4F0B-A8A4-E6E3DA12881E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D18AC472-8802-4F0B-A8A4-E6E3DA12881E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D18AC472-8802-4F0B-A8A4-E6E3DA12881E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D18AC472-8802-4F0B-A8A4-E6E3DA12881E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Reflection;
using Azure.Test.Perf;

await PerfProgram.Main(Assembly.GetEntryAssembly(), args);
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.Monitor.OpenTelemetry.Exporter;
using Azure.Monitor.OpenTelemetry.Exporter.Internals;
using Azure.Test.Perf;
using OpenTelemetry;
using OpenTelemetry.Trace;

namespace Azure.Monitor.OpenTelemetry.AspNetCore.Perf
{
public class ActivityKindServer : PerfTest<PerfOptions>
{
// please refer to https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/template/Azure.Template/perf/TemplateClientTest.cs to write perf test.
/* How to run
* Build
dotnet build -c Release -f <TargetFramework>
* Run
* dotnet run -c Release -f net7.0 --no-build --project <Path to this Project> ActivityKindServer --sync true
*/
private const string ActivitySourceName = nameof(ActivityKindServer);
private readonly Batch<Activity> _activityBatch;
private readonly AzureMonitorTraceExporter _traceExporter;

public ActivityKindServer(PerfOptions options) : base(options)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;

var listener = new ActivityListener
{
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData,
};

ActivitySource.AddActivityListener(listener);

var exporterOptions = new AzureMonitorExporterOptions();
exporterOptions.EnableStatsbeat = false;
exporterOptions.DisableOfflineStorage = true;
exporterOptions.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000";
_traceExporter = new AzureMonitorTraceExporter(exporterOptions);

ActivitySource activitySource = new(ActivitySourceName);
using var activity = activitySource.StartActivity(
"ActivityKindServer",
ActivityKind.Server,
parentContext: new ActivityContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded),
startTime: DateTime.UtcNow);
activity?.Stop();

activity?.SetStatus(Status.Ok);
activity?.SetTag(SemanticConventions.AttributeHttpMethod, "Get");
activity?.SetTag(SemanticConventions.AttributeHttpScheme, "https");
activity?.SetTag(SemanticConventions.AttributeHttpTarget, "api/123");
activity?.SetTag(SemanticConventions.AttributeHttpFlavor, "1.1");
activity?.SetTag(SemanticConventions.AttributeHttpRoute, "api/{searchId}");
activity?.SetTag(SemanticConventions.AttributeNetHostName, "localhost");
activity?.SetTag(SemanticConventions.AttributeNetHostPort, "9999");
activity?.SetTag(SemanticConventions.AttributeHttpUserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0");
activity?.SetTag(SemanticConventions.AttributeHttpStatusCode, 200);

_activityBatch = new Batch<Activity>(new Activity[] { activity ?? new Activity("Placeholder") }, 1);
}

public override void Run(CancellationToken cancellationToken)
{
var exportResult = _traceExporter.Export(_activityBatch);
}

public override Task RunAsync(CancellationToken cancellationToken)
{
// We do not have async export
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.Integration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.E2E.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.Benchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
[assembly: InternalsVisibleTo("Azure.Monitor.OpenTelemetry.Exporter.Perf, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]

// Moq
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

0 comments on commit b4c0695

Please sign in to comment.