Skip to content

Commit

Permalink
General code improvements (#2744)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-max authored Dec 13, 2021
1 parent f3eaf4a commit 83fa9fd
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 17 deletions.
6 changes: 1 addition & 5 deletions examples/Console/TestLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;

namespace Examples.Console
Expand All @@ -33,7 +29,7 @@ internal static object Run(LogsOptions options)
builder.AddOpenTelemetry((opt) =>
{
opt.IncludeFormattedMessage = true;
if (options.UseExporter.ToLower() == "otlp")
if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase))
{
/*
* Prerequisite to run this example:
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static object Run(MetricsOptions options)
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("myservice"))
.AddMeter(meter.Name); // All instruments from this meter are enabled.

if (options.UseExporter.ToLower() == "otlp")
if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase))
{
/*
* Prerequisite to run this example:
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class TracerProviderBuilderBase : TracerProviderBuilder
private readonly List<InstrumentationFactory> instrumentationFactories = new List<InstrumentationFactory>();
private readonly List<BaseProcessor<Activity>> processors = new List<BaseProcessor<Activity>>();
private readonly List<string> sources = new List<string>();
private readonly Dictionary<string, bool> legacyActivityOperationNames = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> legacyActivityOperationNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private ResourceBuilder resourceBuilder = ResourceBuilder.CreateDefault();
private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler());

Expand Down Expand Up @@ -76,7 +76,7 @@ public override TracerProviderBuilder AddLegacySource(string operationName)
{
Guard.NullOrWhitespace(operationName, nameof(operationName));

this.legacyActivityOperationNames[operationName] = true;
this.legacyActivityOperationNames.Add(operationName);

return this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal TracerProviderSdk(
IEnumerable<TracerProviderBuilderBase.InstrumentationFactory> instrumentationFactories,
Sampler sampler,
List<BaseProcessor<Activity>> processors,
Dictionary<string, bool> legacyActivityOperationNames)
HashSet<string> legacyActivityOperationNames)
{
this.Resource = resource;
this.sampler = sampler;
Expand All @@ -53,10 +53,10 @@ internal TracerProviderSdk(
Regex legacyActivityWildcardModeRegex = null;
foreach (var legacyName in legacyActivityOperationNames)
{
if (legacyName.Key.Contains('*'))
if (legacyName.Contains('*'))
{
legacyActivityWildcardMode = true;
legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames.Keys);
legacyActivityWildcardModeRegex = GetWildcardRegex(legacyActivityOperationNames);
break;
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ internal TracerProviderSdk(
}
else
{
legacyActivityPredicate = activity => legacyActivityOperationNames.ContainsKey(activity.OperationName);
legacyActivityPredicate = activity => legacyActivityOperationNames.Contains(activity.OperationName);
}

listener.ActivityStarted = activity =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
using System.Linq;
using System.Net.Http;
using System.Threading;
#if !NET5_0_OR_GREATER
using System.Threading.Tasks;
#endif
using Moq;
using Moq.Protected;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override string GetUnknownRequestHeader(string name)

public override string GetKnownRequestHeader(int index)
{
var name = HttpWorkerRequest.GetKnownRequestHeaderName(index);
var name = GetKnownRequestHeaderName(index);

if (this.headers.ContainsKey(name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Microsoft.AspNetCore.Mvc.Testing;
using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
#if NETCOREAPP3_1
using TestApp.AspNetCore._3._1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void Start_ActivityOperationRootSpanChecks()
{
// Create an activity
var activity = new Activity("foo")
.SetIdFormat(System.Diagnostics.ActivityIdFormat.W3C)
.SetIdFormat(ActivityIdFormat.W3C)
.Start();

// matching root operation name
Expand Down
1 change: 0 additions & 1 deletion test/OpenTelemetry.Tests/Metrics/MultipleReadersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using OpenTelemetry.Exporter;
Expand Down

0 comments on commit 83fa9fd

Please sign in to comment.