[SDL] update analyzers (#1903)
* update fxcop. fix base sdk * fix other projects * update Public Api Analyzer * revert change to TelemetryBuffer
This commit is contained in:
Родитель
19b5cb7240
Коммит
4119d8d865
|
@ -13,16 +13,13 @@
|
|||
|
||||
<ItemGroup Condition=" $(OS) == 'Windows_NT' And $(Configuration) == 'Release'">
|
||||
<!--Analyzers-->
|
||||
<PackageReference Include="Desktop.Analyzers" Version="1.1.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="2.9.8">
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.0.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
/// </summary>
|
||||
public OperationContextForCallContext ParentContext;
|
||||
|
||||
private static readonly object LockObj = new object();
|
||||
|
||||
private readonly TelemetryClient telemetryClient;
|
||||
|
||||
private readonly object originalActivity = null;
|
||||
|
@ -65,7 +67,7 @@
|
|||
{
|
||||
// We need to compare the operation id and name of telemetry with operation id and name of current call context before tracking it
|
||||
// to make sure that the customer is tracking the right telemetry.
|
||||
lock (this)
|
||||
lock (LockObj)
|
||||
{
|
||||
if (!this.isDisposed)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
this.SelectInstrumentationKey(configuration);
|
||||
SelectInstrumentationKey(configuration);
|
||||
|
||||
InitializeComponents(configuration, modules);
|
||||
}
|
||||
|
@ -469,7 +469,7 @@
|
|||
return attributeDefinitions.Concat(elementDefinitions);
|
||||
}
|
||||
|
||||
private void SelectInstrumentationKey(TelemetryConfiguration configuration)
|
||||
private static void SelectInstrumentationKey(TelemetryConfiguration configuration)
|
||||
{
|
||||
if (PlatformSingleton.Current.TryGetEnvironmentVariable(ConnectionStringEnvironmentVariable, out string connectionStringEnVar))
|
||||
{
|
||||
|
|
|
@ -635,6 +635,7 @@
|
|||
public void IngestionResponseTime(int responseCode, float responseDurationInMs, string appDomainName = "Incorrect") => this.WriteEvent(67, responseCode, responseDurationInMs, this.nameProvider.Name);
|
||||
|
||||
[NonEvent]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1822: MarkMembersAsStatic", Justification = "This method does access instance data in NetStandard 2.0 scenarios.")]
|
||||
public void IngestionResponseTimeEventCounter(float responseDurationInMs)
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
|
@ -10,6 +11,7 @@
|
|||
/// <summary>
|
||||
/// Accumulates <see cref="ITelemetry"/> items for efficient transmission.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockObjectsWithWeakIdentity", Justification = "This should be removed, but there is currently a dependency on this behavior.")]
|
||||
internal class TelemetryBuffer : IEnumerable<ITelemetry>, ITelemetryProcessor, IDisposable
|
||||
{
|
||||
private static readonly TimeSpan DefaultFlushDelay = TimeSpan.FromSeconds(30);
|
||||
|
|
|
@ -35,6 +35,11 @@ namespace Microsoft.ApplicationInsights.EtwCollector
|
|||
}
|
||||
}
|
||||
|
||||
public static bool? IsElevated()
|
||||
{
|
||||
return TraceEventSession.IsElevated();
|
||||
}
|
||||
|
||||
public void DisableProvider(Guid providerGuid)
|
||||
{
|
||||
this.session.DisableProvider(providerGuid);
|
||||
|
@ -60,11 +65,6 @@ namespace Microsoft.ApplicationInsights.EtwCollector
|
|||
return this.session.EnableProvider(providerName, providerLevel, matchAnyKeywords, options);
|
||||
}
|
||||
|
||||
public bool? IsElevated()
|
||||
{
|
||||
return TraceEventSession.IsElevated();
|
||||
}
|
||||
|
||||
public bool Stop(bool noThrow = false)
|
||||
{
|
||||
return this.session.Stop(noThrow);
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Microsoft.ApplicationInsights.EventSourceListener
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Linq;
|
||||
using Microsoft.ApplicationInsights.EventSourceListener.Implementation;
|
||||
|
@ -182,6 +183,7 @@ namespace Microsoft.ApplicationInsights.EventSourceListener
|
|||
/// <param name="eventSource">EventSource instance.</param>
|
||||
/// <remarks>When an instance of an EventListener is created, it will immediately receive notifications about all EventSources already existing in the AppDomain.
|
||||
/// Then, as new EventSources are created, the EventListener will receive notifications about them.</remarks>
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockObjectsWithWeakIdentity", Justification = "This was done intentionally for a bug fix.")]
|
||||
protected override void OnEventSourceCreated(EventSource eventSource)
|
||||
{
|
||||
if (eventSource == null)
|
||||
|
|
|
@ -138,18 +138,12 @@
|
|||
/// <inheritdoc/>
|
||||
public string ListenerName { get; } = "Microsoft.AspNetCore";
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnSubscribe()
|
||||
{
|
||||
SubscriptionManager.Attach(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Mvc.BeforeAction' event.
|
||||
/// </summary>
|
||||
/// <param name="httpContext">HttpContext is used to retrieve information about the Request and Response.</param>
|
||||
/// <param name="routeValues">Used to get the name of the request.</param>
|
||||
public void OnBeforeAction(HttpContext httpContext, IDictionary<string, object> routeValues)
|
||||
public static void OnBeforeAction(HttpContext httpContext, IDictionary<string, object> routeValues)
|
||||
{
|
||||
var telemetry = httpContext.Features.Get<RequestTelemetry>();
|
||||
|
||||
|
@ -164,6 +158,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnSubscribe()
|
||||
{
|
||||
SubscriptionManager.Attach(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diagnostic event handler method for 'Microsoft.AspNetCore.Hosting.HttpRequestIn.Start' event. This is from 2.XX runtime.
|
||||
/// </summary>
|
||||
|
@ -506,7 +506,7 @@
|
|||
|
||||
if (context != null && routeValues != null)
|
||||
{
|
||||
this.OnBeforeAction(context, routeValues);
|
||||
OnBeforeAction(context, routeValues);
|
||||
}
|
||||
}
|
||||
else if (value.Key == "Microsoft.AspNetCore.Hosting.BeginRequest")
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
var stateDictionary = state as IReadOnlyList<KeyValuePair<string, object>>;
|
||||
if (exception == null || this.options?.TrackExceptionsAsExceptionTelemetry == false)
|
||||
{
|
||||
var traceTelemetry = new TraceTelemetry(formatter(state, exception), this.GetSeverityLevel(logLevel));
|
||||
var traceTelemetry = new TraceTelemetry(formatter(state, exception), GetSeverityLevel(logLevel));
|
||||
this.PopulateTelemetry(traceTelemetry, stateDictionary, eventId);
|
||||
this.telemetryClient.TrackTrace(traceTelemetry);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@
|
|||
{
|
||||
var exceptionTelemetry = new ExceptionTelemetry(exception);
|
||||
exceptionTelemetry.Message = formatter(state, exception);
|
||||
exceptionTelemetry.SeverityLevel = this.GetSeverityLevel(logLevel);
|
||||
exceptionTelemetry.SeverityLevel = GetSeverityLevel(logLevel);
|
||||
exceptionTelemetry.Properties["Exception"] = exception.ToString();
|
||||
exception.Data.Cast<DictionaryEntry>().ToList().ForEach((item) => exceptionTelemetry.Properties[item.Key.ToString()] = (item.Value ?? "null").ToString());
|
||||
this.PopulateTelemetry(exceptionTelemetry, stateDictionary, eventId);
|
||||
|
@ -89,6 +89,25 @@
|
|||
}
|
||||
}
|
||||
|
||||
private static SeverityLevel GetSeverityLevel(LogLevel logLevel)
|
||||
{
|
||||
switch (logLevel)
|
||||
{
|
||||
case LogLevel.Critical:
|
||||
return SeverityLevel.Critical;
|
||||
case LogLevel.Error:
|
||||
return SeverityLevel.Error;
|
||||
case LogLevel.Warning:
|
||||
return SeverityLevel.Warning;
|
||||
case LogLevel.Information:
|
||||
return SeverityLevel.Information;
|
||||
case LogLevel.Debug:
|
||||
case LogLevel.Trace:
|
||||
default:
|
||||
return SeverityLevel.Verbose;
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateTelemetry(ITelemetry telemetry, IReadOnlyList<KeyValuePair<string, object>> stateDictionary, EventId eventId)
|
||||
{
|
||||
var telemetryWithProperties = telemetry as ISupportProperties;
|
||||
|
@ -121,25 +140,6 @@
|
|||
|
||||
telemetry.Context.GetInternalContext().SdkVersion = this.sdkVersion;
|
||||
}
|
||||
|
||||
private SeverityLevel GetSeverityLevel(LogLevel logLevel)
|
||||
{
|
||||
switch (logLevel)
|
||||
{
|
||||
case LogLevel.Critical:
|
||||
return SeverityLevel.Critical;
|
||||
case LogLevel.Error:
|
||||
return SeverityLevel.Error;
|
||||
case LogLevel.Warning:
|
||||
return SeverityLevel.Warning;
|
||||
case LogLevel.Information:
|
||||
return SeverityLevel.Information;
|
||||
case LogLevel.Debug:
|
||||
case LogLevel.Trace:
|
||||
default:
|
||||
return SeverityLevel.Verbose;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
this.injectLegacyHeaders = injectLegacyHeaders;
|
||||
this.httpInstrumentationVersion = instrumentationVersion != HttpInstrumentationVersion.Unknown ?
|
||||
instrumentationVersion :
|
||||
this.GetInstrumentationVersion();
|
||||
GetInstrumentationVersion();
|
||||
this.injectRequestIdInW3CMode = injectRequestIdInW3CMode;
|
||||
this.subscriber = new HttpCoreDiagnosticSourceSubscriber(
|
||||
this,
|
||||
|
@ -493,6 +493,45 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
}
|
||||
}
|
||||
|
||||
private static HttpInstrumentationVersion GetInstrumentationVersion()
|
||||
{
|
||||
HttpInstrumentationVersion version = HttpInstrumentationVersion.Unknown;
|
||||
|
||||
var httpClientAssembly = typeof(HttpClient).GetTypeInfo().Assembly;
|
||||
var httpClientVersion = httpClientAssembly.GetName().Version;
|
||||
string httpClientInformationalVersion =
|
||||
httpClientAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
|
||||
string.Empty;
|
||||
|
||||
if (httpClientInformationalVersion.StartsWith("3.", StringComparison.Ordinal))
|
||||
{
|
||||
version = HttpInstrumentationVersion.V3;
|
||||
}
|
||||
else if (httpClientVersion.Major == 4 && httpClientVersion.Minor == 2)
|
||||
{
|
||||
// .NET Core 3.0 has the same version of http client lib as 2.*
|
||||
// but AssemblyInformationalVersionAttribute is different.
|
||||
version = HttpInstrumentationVersion.V2;
|
||||
}
|
||||
else if (httpClientVersion.Major == 4 && httpClientVersion.Minor < 2)
|
||||
{
|
||||
version = HttpInstrumentationVersion.V1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// fallback to V3 assuming unknown SDKs are from future versions
|
||||
version = HttpInstrumentationVersion.V3;
|
||||
}
|
||||
|
||||
DependencyCollectorEventSource.Log.HttpCoreDiagnosticListenerInstrumentationVersion(
|
||||
(int)version,
|
||||
httpClientVersion.Major,
|
||||
httpClientVersion.Minor,
|
||||
httpClientInformationalVersion);
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private void InjectRequestHeaders(HttpRequestMessage request, string instrumentationKey)
|
||||
{
|
||||
try
|
||||
|
@ -637,45 +676,6 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
}
|
||||
}
|
||||
|
||||
private HttpInstrumentationVersion GetInstrumentationVersion()
|
||||
{
|
||||
HttpInstrumentationVersion version = HttpInstrumentationVersion.Unknown;
|
||||
|
||||
var httpClientAssembly = typeof(HttpClient).GetTypeInfo().Assembly;
|
||||
var httpClientVersion = httpClientAssembly.GetName().Version;
|
||||
string httpClientInformationalVersion =
|
||||
httpClientAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
|
||||
string.Empty;
|
||||
|
||||
if (httpClientInformationalVersion.StartsWith("3.", StringComparison.Ordinal))
|
||||
{
|
||||
version = HttpInstrumentationVersion.V3;
|
||||
}
|
||||
else if (httpClientVersion.Major == 4 && httpClientVersion.Minor == 2)
|
||||
{
|
||||
// .NET Core 3.0 has the same version of http client lib as 2.*
|
||||
// but AssemblyInformationalVersionAttribute is different.
|
||||
version = HttpInstrumentationVersion.V2;
|
||||
}
|
||||
else if (httpClientVersion.Major == 4 && httpClientVersion.Minor < 2)
|
||||
{
|
||||
version = HttpInstrumentationVersion.V1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// fallback to V3 assuming unknown SDKs are from future versions
|
||||
version = HttpInstrumentationVersion.V3;
|
||||
}
|
||||
|
||||
DependencyCollectorEventSource.Log.HttpCoreDiagnosticListenerInstrumentationVersion(
|
||||
(int)version,
|
||||
httpClientVersion.Major,
|
||||
httpClientVersion.Minor,
|
||||
httpClientInformationalVersion);
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diagnostic listener implementation that listens for events specific to outgoing dependency requests.
|
||||
/// </summary>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
string type = this.GetType(currentActivity);
|
||||
string type = GetType(currentActivity);
|
||||
|
||||
if (telemetry == null)
|
||||
{
|
||||
|
@ -61,12 +61,12 @@
|
|||
|
||||
if (type != null && type.EndsWith(RemoteDependencyConstants.AzureEventHubs, StringComparison.Ordinal))
|
||||
{
|
||||
this.SetEventHubsProperties(currentActivity, telemetry);
|
||||
SetEventHubsProperties(currentActivity, telemetry);
|
||||
}
|
||||
|
||||
if (this.linksPropertyFetcher.Fetch(evnt.Value) is IEnumerable<Activity> activityLinks)
|
||||
{
|
||||
this.PopulateLinks(activityLinks, telemetry);
|
||||
PopulateLinks(activityLinks, telemetry);
|
||||
|
||||
if (telemetry is RequestTelemetry request &&
|
||||
TryGetAverageTimeInQueueForBatch(activityLinks, currentActivity.StartTimeUtc, out long enqueuedTime))
|
||||
|
@ -85,7 +85,7 @@
|
|||
|
||||
if (telemetry is DependencyTelemetry dependency && dependency.Type == RemoteDependencyConstants.HTTP)
|
||||
{
|
||||
this.SetHttpProperties(currentActivity, dependency);
|
||||
SetHttpProperties(currentActivity, dependency);
|
||||
if (evnt.Value != null)
|
||||
{
|
||||
dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value);
|
||||
|
@ -190,7 +190,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
private string GetType(Activity currentActivity)
|
||||
private static string GetType(Activity currentActivity)
|
||||
{
|
||||
string kind = RemoteDependencyConstants.InProc;
|
||||
string component = null;
|
||||
|
@ -242,7 +242,7 @@
|
|||
return kind ?? string.Empty;
|
||||
}
|
||||
|
||||
private void SetHttpProperties(Activity activity, DependencyTelemetry dependency)
|
||||
private static void SetHttpProperties(Activity activity, DependencyTelemetry dependency)
|
||||
{
|
||||
string method = null;
|
||||
string url = null;
|
||||
|
@ -290,7 +290,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
private void SetEventHubsProperties(Activity activity, OperationTelemetry telemetry)
|
||||
private static void SetEventHubsProperties(Activity activity, OperationTelemetry telemetry)
|
||||
{
|
||||
string endpoint = null;
|
||||
string queueName = null;
|
||||
|
@ -332,7 +332,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
private void PopulateLinks(IEnumerable<Activity> links, OperationTelemetry telemetry)
|
||||
private static void PopulateLinks(IEnumerable<Activity> links, OperationTelemetry telemetry)
|
||||
{
|
||||
if (links.Any())
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using Microsoft.ApplicationInsights.Common;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
|
@ -13,6 +14,7 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
/// Concrete class with all processing logic to generate RDD data from the callbacks
|
||||
/// received from Profiler instrumentation for HTTP .
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "These methods have extra parameters to match callbacks with specific number of parameters.")]
|
||||
internal sealed class ProfilerHttpProcessing : HttpProcessing
|
||||
{
|
||||
internal ObjectInstanceBasedOperationHolder<DependencyTelemetry> TelemetryTable;
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights.Common;
|
||||
|
@ -15,6 +16,7 @@ namespace Microsoft.ApplicationInsights.DependencyCollector.Implementation
|
|||
/// <summary>
|
||||
/// Base class with all processing logic to generate dependencies from the callbacks received from Profiler instrumentation for SQL.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "These methods have extra parameters to match callbacks with specific number of parameters.")]
|
||||
internal abstract class ProfilerSqlProcessingBase
|
||||
{
|
||||
internal ObjectInstanceBasedOperationHolder<DependencyTelemetry> TelemetryTable;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
/// </summary>
|
||||
internal class EventCounterListener : EventListener
|
||||
{
|
||||
private static readonly object LockObj = new object();
|
||||
private readonly string refreshIntervalInSecs;
|
||||
private readonly int refreshInternalInSecInt;
|
||||
private readonly EventLevel level = EventLevel.Critical;
|
||||
|
@ -80,7 +81,7 @@
|
|||
protected override void OnEventSourceCreated(EventSource eventSource)
|
||||
{
|
||||
// Keeping track of all EventSources here, as this call may happen before initialization.
|
||||
lock (this)
|
||||
lock (LockObj)
|
||||
{
|
||||
if (this.allEventSourcesCreated == null)
|
||||
{
|
||||
|
|
|
@ -163,26 +163,6 @@
|
|||
|
||||
#endregion
|
||||
|
||||
[NonEvent]
|
||||
private string GetApplicationName()
|
||||
{
|
||||
string name;
|
||||
try
|
||||
{
|
||||
#if NETSTANDARD2_0
|
||||
name = new AssemblyName(Assembly.GetEntryAssembly().FullName).Name;
|
||||
#else
|
||||
name = AppDomain.CurrentDomain.FriendlyName;
|
||||
#endif
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
name = "Undefined " + exp.Message ?? exp.ToString();
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public class Keywords
|
||||
{
|
||||
public const EventKeywords UserActionable = (EventKeywords)0x1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче