Cleaning files (#1323)

* Cleaning files

* applying fxcop suggestions

* fixing taskscheduler warning

removing fxcop
This commit is contained in:
Eddy Nakamura 2020-10-07 00:24:32 -03:00 committed by GitHub
parent 04eb1d877d
commit 6348f387f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 31 additions and 190 deletions

View File

@ -15,7 +15,6 @@
// </copyright>
using System;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
internal static class LoggerExtensions

View File

@ -16,8 +16,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Logs;
internal class MyProcessor : LogProcessor

View File

@ -19,7 +19,6 @@ using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
#endif
using Microsoft.Extensions.Logging;
using OpenTelemetry;
public class Program
{

View File

@ -16,7 +16,6 @@
using System;
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
internal class MyProcessor : ActivityProcessor

View File

@ -15,8 +15,6 @@
// </copyright>
using System;
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
internal class MySampler : Sampler

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -83,6 +83,7 @@ namespace OpenTelemetry.Trace
/// <param name="tagName">Case-sensitive tag name to retrieve.</param>
/// <returns>Tag value or null if a match was not found.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public static object GetTagValue(this Activity activity, string tagName)
{
Debug.Assert(activity != null, "Activity should not be null");
@ -101,6 +102,7 @@ namespace OpenTelemetry.Trace
/// <param name="activity">Activity instance.</param>
/// <param name="tagEnumerator">Tag enumerator.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public static void EnumerateTagValues<T>(this Activity activity, ref T tagEnumerator)
where T : struct, IActivityEnumerator<KeyValuePair<string, object>>
{
@ -116,6 +118,7 @@ namespace OpenTelemetry.Trace
/// <param name="activity">Activity instance.</param>
/// <param name="linkEnumerator">Link enumerator.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public static void EnumerateLinks<T>(this Activity activity, ref T linkEnumerator)
where T : struct, IActivityEnumerator<ActivityLink>
{
@ -131,6 +134,7 @@ namespace OpenTelemetry.Trace
/// <param name="activity">Activity instance.</param>
/// <param name="eventEnumerator">Event enumerator.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public static void EnumerateEvents<T>(this Activity activity, ref T eventEnumerator)
where T : struct, IActivityEnumerator<ActivityEvent>
{

View File

@ -15,7 +15,6 @@
// </copyright>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using OpenTelemetry.Internal;

View File

@ -63,7 +63,7 @@ namespace OpenTelemetry.Exporter.Prometheus
new CancellationTokenSource() :
CancellationTokenSource.CreateLinkedTokenSource(token);
this.workerThread = Task.Factory.StartNew(this.WorkerThread, TaskCreationOptions.LongRunning);
this.workerThread = Task.Factory.StartNew(this.WorkerThread, default, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
}

View File

@ -65,7 +65,7 @@ namespace OpenTelemetry.Exporter.ZPages
new CancellationTokenSource() :
CancellationTokenSource.CreateLinkedTokenSource(token);
this.workerThread = Task.Factory.StartNew(this.WorkerThread, TaskCreationOptions.LongRunning);
this.workerThread = Task.Factory.StartNew(this.WorkerThread, default, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
}

View File

@ -29,6 +29,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
public const string RequestCustomPropertyName = "OTel.AspNet.Request";
public const string ResponseCustomPropertyName = "OTel.AspNet.Response";
private const string ActivityNameByHttpInListener = "ActivityCreatedByHttpInListener";
private const string ActivityOperationName = "Microsoft.AspNet.HttpReqIn.Start";
private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) => request.Headers.GetValues(name);
private readonly PropertyFetcher<object> routeFetcher = new PropertyFetcher<object>("Route");
private readonly PropertyFetcher<object> routeTemplateFetcher = new PropertyFetcher<object>("RouteTemplate");
@ -146,7 +147,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
// this instrumentation created in Start.
// This is because Asp.Net, under certain circumstances, restores Activity.Current
// to its own activity.
if (activity.OperationName.Equals("Microsoft.AspNet.HttpReqIn.Start"))
if (activity.OperationName.Equals(ActivityOperationName, StringComparison.Ordinal))
{
// This block is hit if Asp.Net did restore Current to its own activity,
// and we need to retrieve the one created by HttpInListener,
@ -214,7 +215,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
if (!(this.options.Propagator is TextMapPropagator))
{
if (activity.OperationName.Equals(ActivityNameByHttpInListener))
if (activity.OperationName.Equals(ActivityNameByHttpInListener, StringComparison.Ordinal))
{
// If instrumentation started a new Activity, it must
// be stopped here.

View File

@ -182,7 +182,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
}
}
if (activity.OperationName.Equals(ActivityNameByHttpInListener))
if (activity.OperationName.Equals(ActivityNameByHttpInListener, StringComparison.Ordinal))
{
// If instrumentation started a new Activity, it must
// be stopped here.

View File

@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Net.Http;
using System.Net.Sockets;
using System.Reflection;
@ -71,7 +72,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
{
var match = CoreAppMajorVersionCheckRegex.Match(framework);
this.httpClientSupportsW3C = match.Success && int.Parse(match.Groups[1].Value) >= 3;
this.httpClientSupportsW3C = match.Success && int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture) >= 3;
}
this.options = options;

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using OpenTelemetry.Trace;
using StackExchange.Redis.Profiling;

View File

@ -17,7 +17,6 @@
using System;
using System.Collections.Generic;
using global::OpenTracing;
using OpenTelemetry.Context;
namespace OpenTelemetry.Shims.OpenTracing
{

View File

@ -18,7 +18,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using global::OpenTracing;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Shims.OpenTracing

View File

@ -58,7 +58,7 @@ namespace OpenTelemetry.Internal
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (disposing)
{

View File

@ -1,130 +0,0 @@
// <copyright file="VarInt.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;
using System.IO;
namespace OpenTelemetry.Internal
{
internal static class VarInt
{
/// <summary>
/// Maximum encoded size of 32-bit positive integers (in bytes).
/// </summary>
public const int MaxVarintSize = 5;
/// <summary>
/// maximum encoded size of 64-bit longs, and negative 32-bit ints (in bytes).
/// </summary>
public const int MaxVarlongSize = 10;
public static int VarIntSize(int i)
{
var result = 0;
var ui = (uint)i;
do
{
result++;
ui = ui >> 7;
}
while (ui != 0);
return result;
}
public static int GetVarInt(byte[] src, int offset, int[] dst)
{
var result = 0;
var shift = 0;
int b;
do
{
if (shift >= 32)
{
// Out of range
throw new ArgumentOutOfRangeException(nameof(src), "varint too long.");
}
// Get 7 bits from next byte
b = src[offset++];
result |= (b & 0x7F) << shift;
shift += 7;
}
while ((b & 0x80) != 0);
dst[0] = result;
return offset;
}
/// <summary>
/// Writes an into into an array at a specific offset.
/// </summary>
/// <param name="v">The value to write.</param>
/// <param name="sink">The array to write to.</param>
/// <param name="offset">The offset at which to place the value.</param>
/// <returns>The offset.</returns>
public static int PutVarInt(int v, byte[] sink, int offset)
{
var uv = (uint)v;
do
{
// Encode next 7 bits + terminator bit
var bits = uv & 0x7F;
uv >>= 7;
var b = (byte)(bits + ((uv != 0) ? 0x80 : 0));
sink[offset++] = b;
}
while (uv != 0);
return offset;
}
/// <summary>
/// Gets an integer from a stream.
/// </summary>
/// <param name="inputStream">The stream to read from.</param>
/// <returns>The int.</returns>
public static int GetVarInt(Stream inputStream)
{
var result = 0;
var shift = 0;
int b;
do
{
if (shift >= 32)
{
// Out of range
throw new ArgumentOutOfRangeException(nameof(inputStream), "varint too long.");
}
// Get 7 bits from next byte
b = inputStream.ReadByte();
result |= (b & 0x7F) << shift;
shift += 7;
}
while ((b & 0x80) != 0);
return result;
}
/// <summary>
/// Writes an integer to a stream.
/// </summary>
/// <param name="v">The value.</param>
/// <param name="outputStream">The stream to write to.</param>
public static void PutVarInt(int v, Stream outputStream)
{
var bytes = new byte[VarIntSize(v)];
PutVarInt(v, bytes, 0);
outputStream.Write(bytes, 0, bytes.Length);
}
}
}

View File

@ -96,7 +96,7 @@ namespace OpenTelemetry.Logs
}
else
{
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
if (timeout <= 0)
{
@ -132,7 +132,7 @@ namespace OpenTelemetry.Logs
}
else
{
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
// notify all the processors, even if we run overtime
result = cur.Value.Shutdown((int)Math.Max(timeout, 0)) && result;

View File

@ -32,7 +32,7 @@ namespace OpenTelemetry.Logs
private IExternalScopeProvider scopeProvider;
public OpenTelemetryLoggerProvider(IOptionsMonitor<OpenTelemetryLoggerOptions> options)
: this(options.CurrentValue)
: this(options?.CurrentValue)
{
}
@ -117,7 +117,7 @@ namespace OpenTelemetry.Logs
return this;
}
protected void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (this.disposed)
{

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Metrics.Aggregators;
using OpenTelemetry.Trace;

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Metrics.Aggregators;
using OpenTelemetry.Trace;

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -44,7 +44,11 @@ namespace OpenTelemetry.Metrics.Export
this.metricExporter = metricExporter;
this.pushInterval = pushInterval;
this.worker = Task.Factory.StartNew(
s => this.Worker((CancellationToken)s), cts.Token);
s => this.Worker((CancellationToken)s),
cts.Token,
default,
TaskCreationOptions.None,
TaskScheduler.Default);
}
internal IEnumerable<Metric> Collect(Stopwatch sw)

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Metrics.Aggregators;
using OpenTelemetry.Trace;

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using OpenTelemetry.Context;
using OpenTelemetry.Metrics.Aggregators;
using OpenTelemetry.Trace;

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Collections.Generic;
using OpenTelemetry.Context;
using OpenTelemetry.Trace;
namespace OpenTelemetry.Metrics

View File

@ -46,17 +46,8 @@ namespace OpenTelemetry.Trace
internal ActivitySourceAdapter(Sampler sampler, ActivityProcessor activityProcessor, Resource resource)
{
if (sampler == null)
{
throw new ArgumentNullException(nameof(sampler));
}
if (resource == null)
{
throw new ArgumentNullException(nameof(resource));
}
this.sampler = sampler;
this.sampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
this.resource = resource ?? throw new ArgumentNullException(nameof(resource));
if (this.sampler is AlwaysOnSampler)
{
this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOnSampler;
@ -71,7 +62,6 @@ namespace OpenTelemetry.Trace
}
this.activityProcessor = activityProcessor;
this.resource = resource;
}
private ActivitySourceAdapter()
@ -83,6 +73,7 @@ namespace OpenTelemetry.Trace
/// </summary>
/// <param name="activity"><see cref="Activity"/> to be started.</param>
/// <param name="kind">ActivityKind to be set of the activity.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public void Start(Activity activity, ActivityKind kind)
{
SetKindProperty(activity, kind);

View File

@ -151,7 +151,7 @@ namespace OpenTelemetry.Trace
}
else
{
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
if (timeout <= 0)
{
@ -192,7 +192,7 @@ namespace OpenTelemetry.Trace
var sw = Stopwatch.StartNew();
this.exporterThread.Join(timeoutMilliseconds);
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
return this.exporter.Shutdown((int)Math.Max(timeout, 0));
}

View File

@ -107,7 +107,7 @@ namespace OpenTelemetry.Trace
}
else
{
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
if (timeout <= 0)
{
@ -143,7 +143,7 @@ namespace OpenTelemetry.Trace
}
else
{
var timeout = (long)timeoutMilliseconds - sw.ElapsedMilliseconds;
var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds;
// notify all the processors, even if we run overtime
result = cur.Value.Shutdown((int)Math.Max(timeout, 0)) && result;

View File

@ -28,8 +28,8 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
var id = ActivityTraceId.CreateFromBytes(new byte[] { 0x1a, 0x0f, 0x54, 0x63, 0x25, 0xa8, 0x56, 0x43, 0x1a, 0x4c, 0x24, 0xea, 0xa8, 0x60, 0xb0, 0xe8 });
var int128 = new Int128(id);
Assert.Equal<long>(unchecked((long)0x1a0f546325a85643), int128.High);
Assert.Equal<long>(unchecked((long)0x1a4c24eaa860b0e8), int128.Low);
Assert.Equal<long>(unchecked(0x1a0f546325a85643), int128.High);
Assert.Equal<long>(unchecked(0x1a4c24eaa860b0e8), int128.Low);
}
}
}

View File

@ -22,7 +22,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using OpenTelemetry.Exporter.Zipkin.Implementation;
using OpenTelemetry.Resources;
using OpenTelemetry.Tests;

View File

@ -16,7 +16,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;

View File

@ -16,7 +16,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using Moq;

View File

@ -15,7 +15,6 @@
// </copyright>
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Moq;

View File

@ -16,7 +16,6 @@
using System.Collections.Concurrent;
using System.Diagnostics.Tracing;
using OpenTelemetry.Internal;
namespace OpenTelemetry.Tests
{

View File

@ -17,7 +17,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using OpenTelemetry.Trace;
using Xunit;
namespace OpenTelemetry.Trace.Tests