diff --git a/test/Benchmarks/Helper/ActivityCreationScenarios.cs b/test/Benchmarks/Helper/ActivityCreationScenarios.cs index 6b1b9f2a1b4..48c67b4c3d4 100644 --- a/test/Benchmarks/Helper/ActivityCreationScenarios.cs +++ b/test/Benchmarks/Helper/ActivityCreationScenarios.cs @@ -13,30 +13,31 @@ public static void CreateActivity(ActivitySource source) activity?.Stop(); } - public static void CreateActivityWithKind(ActivitySource source) - { - using var activity = source.StartActivity("name", ActivityKind.Client); - activity?.Stop(); - } - public static void CreateActivityFromParentContext(ActivitySource source, ActivityContext parentCtx) { using var activity = source.StartActivity("name", ActivityKind.Internal, parentCtx); activity?.Stop(); } - public static void CreateActivityFromParentId(ActivitySource source, string parentId) + public static void CreateActivityWithSetTags(ActivitySource source) { - using var activity = source.StartActivity("name", ActivityKind.Internal, parentId); + using var activity = source.StartActivity("name"); + activity?.SetTag("tag1", "string"); + activity?.SetTag("tag2", 1); + activity?.SetTag("tag3", true); + activity?.SetTag("tag4", "string-again"); + activity?.SetTag("tag5", "string-more"); activity?.Stop(); } - public static void CreateActivityWithAttributes(ActivitySource source) + public static void CreateActivityWithAddTags(ActivitySource source) { using var activity = source.StartActivity("name"); - activity?.SetTag("tag1", "string"); - activity?.SetTag("tag2", 1); - activity?.SetTag("tag3", true); + activity?.AddTag("tag1", "string"); + activity?.AddTag("tag2", 1); + activity?.AddTag("tag3", true); + activity?.AddTag("tag4", "string-again"); + activity?.AddTag("tag5", "string-more"); activity?.Stop(); } } diff --git a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs index b7c30f1212a..447e550bd87 100644 --- a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs +++ b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs @@ -8,20 +8,19 @@ using OpenTelemetry.Trace; /* -BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000) -Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores +BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.2861) +11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores .NET SDK 8.0.100 [Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 -| Method | Mean | Error | StdDev | Gen0 | Allocated | -|----------------------------------------------- |----------:|---------:|---------:|-------:|----------:| -| CreateActivity_NoopProcessor | 307.12 ns | 5.769 ns | 6.172 ns | 0.0663 | 416 B | -| CreateActivity_WithParentContext_NoopProcessor | 75.18 ns | 0.399 ns | 0.354 ns | - | - | -| CreateActivity_WithParentId_NoopProcessor | 156.52 ns | 1.609 ns | 1.426 ns | 0.0229 | 144 B | -| CreateActivity_WithAttributes_NoopProcessor | 372.34 ns | 6.215 ns | 4.852 ns | 0.0992 | 624 B | -| CreateActivity_WithKind_NoopProcessor | 302.24 ns | 5.859 ns | 8.402 ns | 0.0663 | 416 B | +| Method | Mean | Error | StdDev | Median | +|----------------------------------------------- |----------:|---------:|----------:|----------:| +| CreateActivity_NoopProcessor | 247.22 ns | 4.977 ns | 13.198 ns | 240.34 ns | +| CreateActivity_WithParentContext_NoopProcessor | 55.17 ns | 1.131 ns | 1.111 ns | 54.98 ns | +| CreateActivity_WithSetTags_NoopProcessor | 375.2 ns | 7.52 ns | 18.44 ns | 370.4 ns | +| CreateActivity_WithAddTags_NoopProcessor | 340.9 ns | 6.27 ns | 12.81 ns | 336.1 ns | */ namespace Benchmarks.Trace; @@ -30,7 +29,6 @@ public class ActivityCreationBenchmarks { private readonly ActivitySource benchmarkSource = new("Benchmark"); private readonly ActivityContext parentCtx = new(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None); - private readonly string parentId = $"00-{ActivityTraceId.CreateRandom()}.{ActivitySpanId.CreateRandom()}.00"; private TracerProvider tracerProvider; [GlobalSetup] @@ -38,6 +36,7 @@ public void GlobalSetup() { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("BenchMark") + .AddProcessor(new NoopActivityProcessor()) .Build(); } @@ -55,11 +54,12 @@ public void GlobalCleanup() public void CreateActivity_WithParentContext_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentContext(this.benchmarkSource, this.parentCtx); [Benchmark] - public void CreateActivity_WithParentId_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentId(this.benchmarkSource, this.parentId); + public void CreateActivity_WithSetTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithSetTags(this.benchmarkSource); [Benchmark] - public void CreateActivity_WithAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource); + public void CreateActivity_WithAddTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddTags(this.benchmarkSource); - [Benchmark] - public void CreateActivity_WithKind_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithKind(this.benchmarkSource); + internal class NoopActivityProcessor : BaseProcessor + { + } }