Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic benchmark project for Activity based SDK. #725

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions benchmarks/OpenTelemetrySdkBenchmarksActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// <copyright file="OpenTelemetrySdkBenchmarksActivity.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Diagnostics;
using BenchmarkDotNet.Attributes;
using Benchmarks.Tracing;
using OpenTelemetry.Trace.Configuration;

namespace Benchmarks
{
[MemoryDiagnoser]
public class OpenTelemetrySdkBenchmarksActivity
{
private readonly ActivitySource BenchMarkSource = new ActivitySource("BenchMark");

public OpenTelemetrySdkBenchmarksActivity()
{
// Not configuring pipeline, which will result in default NoOpActivityProcessor.
var openTel = OpenTelemetrySdk.EnableOpenTelemetry(
(builder) => builder.AddActivitySource("BenchMark")
);
}

[Benchmark]
public Activity CreateActivity_NoOpProcessor()
{
return ActivityCreationScenarios.CreateActivity(this.BenchMarkSource);
}


[Benchmark]
public Activity CreateActivity_WithAttributes_NoOpProcessor()
{
return ActivityCreationScenarios.CreateActivityWithAttributes(this.BenchMarkSource);
}

[Benchmark]
public Activity CreateActivity_WithAttributesAndCustomProp_NoOpProcessor()
{
return ActivityCreationScenarios.CreateActivityWithAttributesAndCustomProperty(this.BenchMarkSource);
}
}
}
3 changes: 3 additions & 0 deletions benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ internal static class Program
{
public static void Main(string[] args)
{
// examples to run from command line:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably put this in a simple README.md file?

// navigate to opentelemetry-dotnet\src\benchmarks directory and run the following
// dotnet run --framework netcoreapp3.1 --configuration Release --filter *OpenTelemetrySdkBenchmarksActivity*
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
Expand Down
54 changes: 54 additions & 0 deletions benchmarks/Tracing/ActivityCreationScenarios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// <copyright file="ActivityCreationScenarios.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Diagnostics;
using OpenTelemetry.Trace;

namespace Benchmarks.Tracing
{
internal class ActivityCreationScenarios
{
public static Activity CreateActivity(ActivitySource source)
{
var activity = source.StartActivity("name");
activity?.Stop();
return activity;
}

public static Activity CreateActivityWithAttributes(ActivitySource source)
{
var activity = source.StartActivity("name");
activity?.AddTag("tag1", "value1");
activity?.AddTag("tag2", "value2");
activity?.AddTag("customPropTag1", "somecustomValue");
activity?.Stop();
return activity;
}

public static Activity CreateActivityWithAttributesAndCustomProperty(ActivitySource source)
{
var activity = source.StartActivity("name");
activity?.AddTag("tag1", "value1");
activity?.AddTag("tag2", "value2");

// use custom property instead of tags
//activity?.AddTag("customPropTag1", "somecustomValue");
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
activity?.SetCustomProperty("customPropTag1", "somecustomValue");
activity?.Stop();
return activity;
}
}
}