-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add perf test for exporting request telemetry (#35223)
* draft * draft * Add perf test for ActivityKind.Server * Running instructions * rename * remove mock transport
- Loading branch information
1 parent
0ffec3d
commit b4c0695
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...zure.Monitor.OpenTelemetry.Exporter/perf/Azure.Monitor.OpenTelemetry.Exporter.Perf.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
7 changes: 7 additions & 0 deletions
7
sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/perf/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
82 changes: 82 additions & 0 deletions
82
sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/perf/Scenarios/ActivityKindServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters