another round of analyzer fixed (#889)
* another round of analyzer fixed * more fixes
This commit is contained in:
Родитель
0e7b63bdbe
Коммит
098ca27fb7
|
@ -6,6 +6,7 @@
|
|||
#else
|
||||
using System.Threading;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.
|
||||
/// </summary>
|
||||
|
@ -15,7 +16,6 @@
|
|||
#if NET451 || NET46
|
||||
private static readonly string Key = typeof(ContextData<T>).FullName;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the ambient data.
|
||||
/// </summary>
|
||||
|
@ -27,6 +27,7 @@
|
|||
var handle = CallContext.LogicalGetData(Key) as ObjectHandle;
|
||||
return handle != null ? (T)handle.Unwrap() : default(T);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CallContext.LogicalSetData(Key, new ObjectHandle(value));
|
||||
|
|
|
@ -115,6 +115,7 @@
|
|||
string originalParentId = currentActivity.ParentId;
|
||||
|
||||
Activity newActivity = null;
|
||||
|
||||
// W3C
|
||||
if (this.enableW3CHeaders)
|
||||
{
|
||||
|
@ -133,12 +134,14 @@
|
|||
alternativeRootIdValues != StringValues.Empty)
|
||||
{
|
||||
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener)
|
||||
.SetParentId(StringUtilities.EnforceMaxLength(alternativeRootIdValues.First(),
|
||||
InjectionGuardConstants.RequestHeaderMaxLength));
|
||||
.SetParentId(StringUtilities.EnforceMaxLength(
|
||||
alternativeRootIdValues.First(),
|
||||
InjectionGuardConstants.RequestHeaderMaxLength));
|
||||
|
||||
if (httpContext.Request.Headers.TryGetValue(RequestResponseHeaders.StandardParentIdHeader, out StringValues parentId))
|
||||
{
|
||||
originalParentId = StringUtilities.EnforceMaxLength(parentId.First(),
|
||||
originalParentId = StringUtilities.EnforceMaxLength(
|
||||
parentId.First(),
|
||||
InjectionGuardConstants.RequestHeaderMaxLength);
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +156,6 @@
|
|||
// So if there is no current Activity (i.e. there were no Request-Id header in the incoming request), we'll override ParentId on
|
||||
// the current Activity by the properly formatted one. This workaround should go away
|
||||
// with W3C support on .NET https://github.com/dotnet/corefx/issues/30331
|
||||
|
||||
newActivity = new Activity(ActivityCreatedByHostingDiagnosticListener);
|
||||
if (this.enableW3CHeaders)
|
||||
{
|
||||
|
@ -164,6 +166,7 @@
|
|||
{
|
||||
newActivity.SetParentId(W3CUtilities.GenerateTraceId());
|
||||
}
|
||||
|
||||
// end of workaround
|
||||
}
|
||||
|
||||
|
@ -173,7 +176,7 @@
|
|||
currentActivity = newActivity;
|
||||
}
|
||||
|
||||
var requestTelemetry = InitializeRequestTelemetry(httpContext, currentActivity, Stopwatch.GetTimestamp());
|
||||
var requestTelemetry = this.InitializeRequestTelemetry(httpContext, currentActivity, Stopwatch.GetTimestamp());
|
||||
if (this.enableW3CHeaders && sourceAppId != null)
|
||||
{
|
||||
requestTelemetry.Source = sourceAppId;
|
||||
|
@ -216,6 +219,7 @@
|
|||
IHeaderDictionary requestHeaders = httpContext.Request.Headers;
|
||||
|
||||
string originalParentId = null;
|
||||
|
||||
// W3C
|
||||
if (this.enableW3CHeaders)
|
||||
{
|
||||
|
@ -253,7 +257,8 @@
|
|||
|
||||
if (originalParentId == null && requestHeaders.TryGetValue(RequestResponseHeaders.StandardParentIdHeader, out StringValues parentId))
|
||||
{
|
||||
originalParentId = StringUtilities.EnforceMaxLength(parentId.First(),
|
||||
originalParentId = StringUtilities.EnforceMaxLength(
|
||||
parentId.First(),
|
||||
InjectionGuardConstants.RequestHeaderMaxLength);
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +273,6 @@
|
|||
// So if there is no current Activity (i.e. there were no Request-Id header in the incoming request), we'll override ParentId on
|
||||
// the current Activity by the properly formatted one. This workaround should go away
|
||||
// with W3C support on .NET https://github.com/dotnet/corefx/issues/30331
|
||||
|
||||
if (this.enableW3CHeaders)
|
||||
{
|
||||
activity.GenerateW3CContext();
|
||||
|
@ -358,6 +362,7 @@
|
|||
{
|
||||
this.OnHttpRequestInStart(httpContext);
|
||||
}
|
||||
|
||||
break;
|
||||
case "Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop":
|
||||
httpContext = this.httpContextFetcherStop.Fetch(value.Value) as HttpContext;
|
||||
|
@ -365,6 +370,7 @@
|
|||
{
|
||||
this.OnHttpRequestInStop(httpContext);
|
||||
}
|
||||
|
||||
break;
|
||||
case "Microsoft.AspNetCore.Hosting.BeginRequest":
|
||||
httpContext = this.httpContextFetcherBeginRequest.Fetch(value.Value) as HttpContext;
|
||||
|
@ -373,6 +379,7 @@
|
|||
{
|
||||
this.OnBeginRequest(httpContext, timestamp.Value);
|
||||
}
|
||||
|
||||
break;
|
||||
case "Microsoft.AspNetCore.Hosting.EndRequest":
|
||||
httpContext = this.httpContextFetcherEndRequest.Fetch(value.Value) as HttpContext;
|
||||
|
@ -381,6 +388,7 @@
|
|||
{
|
||||
this.OnEndRequest(httpContext, timestamp.Value);
|
||||
}
|
||||
|
||||
break;
|
||||
case "Microsoft.AspNetCore.Diagnostics.UnhandledException":
|
||||
httpContext = this.httpContextFetcherDiagExceptionUnhandled.Fetch(value.Value) as HttpContext;
|
||||
|
@ -397,6 +405,7 @@
|
|||
{
|
||||
this.OnDiagnosticsHandledException(httpContext, exception);
|
||||
}
|
||||
|
||||
break;
|
||||
case "Microsoft.AspNetCore.Hosting.UnhandledException":
|
||||
httpContext = this.httpContextFetcherHostingExceptionUnhandled.Fetch(value.Value) as HttpContext;
|
||||
|
@ -405,6 +414,7 @@
|
|||
{
|
||||
this.OnHostingException(httpContext, exception);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -448,7 +458,7 @@
|
|||
|
||||
this.client.InitializeInstrumentationKey(requestTelemetry);
|
||||
|
||||
requestTelemetry.Source = GetAppIdFromRequestHeader(httpContext.Request.Headers, requestTelemetry.Context.InstrumentationKey);
|
||||
requestTelemetry.Source = this.GetAppIdFromRequestHeader(httpContext.Request.Headers, requestTelemetry.Context.InstrumentationKey);
|
||||
|
||||
requestTelemetry.Start(timestamp);
|
||||
httpContext.Features.Set(requestTelemetry);
|
||||
|
@ -494,7 +504,8 @@
|
|||
RequestResponseHeaders.RequestContextTargetKey)))
|
||||
{
|
||||
string applicationId = null;
|
||||
if (this.applicationIdProvider?.TryGetApplicationId(requestTelemetry.Context.InstrumentationKey,
|
||||
if (this.applicationIdProvider?.TryGetApplicationId(
|
||||
requestTelemetry.Context.InstrumentationKey,
|
||||
out applicationId) ?? false)
|
||||
{
|
||||
HttpHeadersUtilities.SetRequestContextKeyValue(
|
||||
|
@ -589,12 +600,14 @@
|
|||
sourceAppId = null;
|
||||
if (requestHeaders.TryGetValue(W3C.W3CConstants.TraceParentHeader, out StringValues traceParentValues))
|
||||
{
|
||||
var parentTraceParent = StringUtilities.EnforceMaxLength(traceParentValues.First(),
|
||||
var parentTraceParent = StringUtilities.EnforceMaxLength(
|
||||
traceParentValues.First(),
|
||||
InjectionGuardConstants.TraceParentHeaderMaxLength);
|
||||
activity.SetTraceparent(parentTraceParent);
|
||||
}
|
||||
|
||||
string[] traceStateValues = HttpHeadersUtilities.SafeGetCommaSeparatedHeaderValues(requestHeaders,
|
||||
string[] traceStateValues = HttpHeadersUtilities.SafeGetCommaSeparatedHeaderValues(
|
||||
requestHeaders,
|
||||
W3C.W3CConstants.TraceStateHeader,
|
||||
InjectionGuardConstants.TraceStateHeaderMaxLength,
|
||||
InjectionGuardConstants.TraceStateMaxPairs);
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
|
|||
result = headerValues.SelectMany(headerValue => headerValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
|
|||
{
|
||||
if (value.Key == "Microsoft.AspNetCore.Mvc.BeforeAction")
|
||||
{
|
||||
var context = httpContextFetcher.Fetch(value.Value) as HttpContext;
|
||||
var context = this.httpContextFetcher.Fetch(value.Value) as HttpContext;
|
||||
var routeData = routeDataFetcher.Fetch(value.Value);
|
||||
var routeValues = routeValuesFetcher.Fetch(routeData) as IDictionary<string, object>;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System.Reflection;
|
||||
|
||||
// see https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
|
||||
|
||||
/// <summary>
|
||||
/// Efficient implementation of fetching properties of anonymous types with reflection.
|
||||
/// </summary>
|
||||
|
@ -31,7 +32,7 @@
|
|||
{
|
||||
/// <summary>
|
||||
/// Create a property fetcher from a .NET Reflection PropertyInfo class that
|
||||
/// represents a property of a particular type.
|
||||
/// represents a property of a particular type.
|
||||
/// </summary>
|
||||
public static PropertyFetch FetcherForProperty(PropertyInfo propertyInfo)
|
||||
{
|
||||
|
@ -48,7 +49,7 @@
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given an object, fetch the property that this propertyFetch represents.
|
||||
/// Given an object, fetch the property that this propertyFetch represents.
|
||||
/// </summary>
|
||||
public virtual object Fetch(object obj)
|
||||
{
|
||||
|
|
|
@ -27,10 +27,11 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
|
|||
/// <summary>
|
||||
/// Prevents a default instance of the <see cref="AspNetCoreEventSource"/> class from being created.
|
||||
/// </summary>
|
||||
private AspNetCoreEventSource() : base()
|
||||
private AspNetCoreEventSource()
|
||||
: base()
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
this.ApplicationName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
|
||||
}
|
||||
catch (Exception exp)
|
||||
|
@ -42,7 +43,13 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
|
|||
/// <summary>
|
||||
/// Gets the application name for use in logging events.
|
||||
/// </summary>
|
||||
public string ApplicationName { [NonEvent] get; [NonEvent]private set; }
|
||||
public string ApplicationName
|
||||
{
|
||||
[NonEvent]
|
||||
get;
|
||||
[NonEvent]
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs an event for the TelemetryInitializerBase Initialize method when the HttpContext is null.
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
/// <param name="services">The <see cref="IServiceCollection"/> instance.</param>
|
||||
/// <param name="instrumentationKey">Instrumentation key to use for telemetry.</param>
|
||||
/// <returns>The <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCollection services,
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(
|
||||
this IServiceCollection services,
|
||||
string instrumentationKey)
|
||||
{
|
||||
services.AddApplicationInsightsTelemetry(options => options.InstrumentationKey = instrumentationKey);
|
||||
|
@ -73,7 +74,8 @@
|
|||
/// <param name="services">The <see cref="IServiceCollection"/> instance.</param>
|
||||
/// <param name="configuration">Configuration to use for sending telemetry.</param>
|
||||
/// <returns>The <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCollection services,
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddApplicationInsightsTelemetry(options => AddTelemetryConfiguration(configuration, options));
|
||||
|
@ -88,7 +90,8 @@
|
|||
/// <returns>
|
||||
/// The <see cref="IServiceCollection"/>.
|
||||
/// </returns>
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCollection services,
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(
|
||||
this IServiceCollection services,
|
||||
Action<ApplicationInsightsServiceOptions> options)
|
||||
{
|
||||
services.AddApplicationInsightsTelemetry();
|
||||
|
@ -104,7 +107,8 @@
|
|||
/// <returns>
|
||||
/// The <see cref="IServiceCollection"/>.
|
||||
/// </returns>
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCollection services,
|
||||
public static IServiceCollection AddApplicationInsightsTelemetry(
|
||||
this IServiceCollection services,
|
||||
ApplicationInsightsServiceOptions options)
|
||||
{
|
||||
services.AddApplicationInsightsTelemetry();
|
||||
|
@ -202,7 +206,7 @@
|
|||
// Using startup filter instead of starting DiagnosticListeners directly because
|
||||
// AspNetCoreHostingDiagnosticListener injects TelemetryClient that injects TelemetryConfiguration
|
||||
// that requires IOptions infrastructure to run and initialize
|
||||
services.AddSingleton<IStartupFilter, ApplicationInsightsStartupFilter>();
|
||||
services.AddSingleton<IStartupFilter, ApplicationInsightsStartupFilter>();
|
||||
services.AddSingleton<JavaScriptSnippet>();
|
||||
|
||||
services.AddOptions();
|
||||
|
@ -211,7 +215,7 @@
|
|||
.AddSingleton<IConfigureOptions<TelemetryConfiguration>, TelemetryConfigurationOptionsSetup>();
|
||||
|
||||
// NetStandard2.0 has a package reference to Microsoft.Extensions.Logging.ApplicationInsights, and
|
||||
// enables ApplicationInsightsLoggerProvider by default.
|
||||
// enables ApplicationInsightsLoggerProvider by default.
|
||||
#if NETSTANDARD2_0
|
||||
services.AddLogging(loggingBuilder =>
|
||||
{
|
||||
|
@ -226,7 +230,7 @@
|
|||
// }
|
||||
// },
|
||||
// The reason is as both rules will match the filter, the last one added wins.
|
||||
// To ensure that the default filter is in the beginning of filter rules, so that user override from Configuration will always win,
|
||||
// To ensure that the default filter is in the beginning of filter rules, so that user override from Configuration will always win,
|
||||
// we add code filter rule to the 0th position as below.
|
||||
loggingBuilder.Services.Configure<LoggerFilterOptions>(
|
||||
options => options.Rules.Insert(
|
||||
|
@ -237,6 +241,7 @@
|
|||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -281,7 +286,7 @@
|
|||
|
||||
if (!telemetryProcessorType.GetTypeInfo().ImplementedInterfaces.Contains(typeof(ITelemetryProcessor)))
|
||||
{
|
||||
throw new ArgumentException(nameof(telemetryProcessorType));
|
||||
throw new ArgumentException(nameof(telemetryProcessorType) + "does not implement ITelemetryProcessor.");
|
||||
}
|
||||
|
||||
return services.AddSingleton<ITelemetryProcessorFactory>(serviceProvider =>
|
||||
|
@ -297,7 +302,7 @@
|
|||
/// The <see cref="IServiceCollection"/>.
|
||||
/// </returns>
|
||||
[Obsolete("Use ConfigureTelemetryModule overload that accepts ApplicationInsightsServiceOptions.")]
|
||||
public static IServiceCollection ConfigureTelemetryModule<T>(this IServiceCollection services, Action<T> configModule)
|
||||
public static IServiceCollection ConfigureTelemetryModule<T>(this IServiceCollection services, Action<T> configModule)
|
||||
where T : ITelemetryModule
|
||||
{
|
||||
if (configModule == null)
|
||||
|
@ -316,9 +321,10 @@
|
|||
/// <param name="configModule">Action used to configure the module.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="IServiceCollection"/>.
|
||||
/// </returns>
|
||||
public static IServiceCollection ConfigureTelemetryModule<T>(this IServiceCollection services,
|
||||
Action<T, ApplicationInsightsServiceOptions> configModule)
|
||||
/// </returns>
|
||||
public static IServiceCollection ConfigureTelemetryModule<T>(
|
||||
this IServiceCollection services,
|
||||
Action<T, ApplicationInsightsServiceOptions> configModule)
|
||||
where T : ITelemetryModule
|
||||
{
|
||||
if (configModule == null)
|
||||
|
@ -351,7 +357,11 @@
|
|||
if (developerMode != null)
|
||||
{
|
||||
telemetryConfigValues.Add(new KeyValuePair<string, string>(DeveloperModeForWebSites,
|
||||
#if !NETSTANDARD1_6
|
||||
developerMode.Value.ToString(CultureInfo.InvariantCulture)));
|
||||
#else
|
||||
developerMode.Value.ToString()));
|
||||
#endif
|
||||
wasAnythingSet = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
{
|
||||
webHostBuilder.ConfigureServices(collection =>
|
||||
{
|
||||
collection.AddApplicationInsightsTelemetry();
|
||||
collection.AddApplicationInsightsTelemetry();
|
||||
});
|
||||
|
||||
return webHostBuilder;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
/// </summary>
|
||||
public static class HttpRequestExtensions
|
||||
{
|
||||
|
||||
private const string UnknownHostName = "UNKNOWN-HOST";
|
||||
|
||||
/// <summary>
|
||||
|
@ -18,17 +17,17 @@
|
|||
/// <param name="request">The <see cref="HttpRequest"/></param>
|
||||
/// <returns>A New Uri object representing request Uri.</returns>
|
||||
public static Uri GetUri(this HttpRequest request)
|
||||
{
|
||||
if (null == request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (true == string.IsNullOrWhiteSpace(request.Scheme))
|
||||
if (string.IsNullOrWhiteSpace(request.Scheme) == true)
|
||||
{
|
||||
throw new ArgumentException("Http request Scheme is not specified");
|
||||
}
|
||||
|
||||
|
||||
return new Uri(string.Concat(
|
||||
request.Scheme,
|
||||
"://",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
public RequestCollectionOptions()
|
||||
{
|
||||
this.InjectResponseHeaders = true;
|
||||
|
||||
// In NetStandard20, ApplicationInsightsLoggerProvider is enabled by default,
|
||||
// which captures Exceptions. Disabling it in RequestCollectionModule to avoid duplication.
|
||||
#if NETSTANDARD2_0
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
Type TelemetryModuleType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configures the given <see cref="ITelemetryModule"/>
|
||||
/// Configures the given <see cref="ITelemetryModule"/>
|
||||
/// </summary>
|
||||
[Obsolete("Use Configure(ITelemetryModule telemetryModule, ApplicationInsightsServiceOptions options) instead.")]
|
||||
void Configure(ITelemetryModule telemetryModule);
|
||||
|
||||
/// <summary>
|
||||
/// Configures the given <see cref="ITelemetryModule"/>.
|
||||
/// Configures the given <see cref="ITelemetryModule"/>.
|
||||
/// </summary>
|
||||
void Configure(ITelemetryModule telemetryModule, ApplicationInsightsServiceOptions options);
|
||||
void Configure(ITelemetryModule telemetryModule, ApplicationInsightsServiceOptions options);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace Microsoft.ApplicationInsights.AspNetCore
|
||||
{
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
@ -28,7 +28,7 @@
|
|||
catch (Exception ex)
|
||||
{
|
||||
AspNetCoreEventSource.Instance.LogWarning(ex.Message);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.ApplicationInsights.AspNetCore;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
|
||||
using Microsoft.ApplicationInsights.Extensibility.W3C;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
foreach (ITelemetryModuleConfigurator telemetryModuleConfigurator in this.telemetryModuleConfigurators)
|
||||
{
|
||||
ITelemetryModule telemetryModule = this.modules.FirstOrDefault(((module) => module.GetType() == telemetryModuleConfigurator.TelemetryModuleType));
|
||||
ITelemetryModule telemetryModule = this.modules.FirstOrDefault((module) => module.GetType() == telemetryModuleConfigurator.TelemetryModuleType);
|
||||
if (telemetryModule != null)
|
||||
{
|
||||
telemetryModuleConfigurator.Configure(telemetryModule, this.applicationInsightsServiceOptions);
|
||||
|
@ -128,7 +128,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
}
|
||||
}
|
||||
|
||||
// Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule depends on this nullable configuration to support Correlation.
|
||||
// Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule depends on this nullable configuration to support Correlation.
|
||||
configuration.ApplicationIdProvider = this.applicationIdProvider;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -140,10 +140,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
private void AddQuickPulse(TelemetryConfiguration configuration)
|
||||
{
|
||||
if (this.applicationInsightsServiceOptions.EnableQuickPulseMetricStream)
|
||||
{
|
||||
QuickPulseTelemetryModule quickPulseModule = this.modules.FirstOrDefault(((module) => module.GetType() == typeof(QuickPulseTelemetryModule))) as QuickPulseTelemetryModule;
|
||||
{
|
||||
QuickPulseTelemetryModule quickPulseModule = this.modules.FirstOrDefault((module) => module.GetType() == typeof(QuickPulseTelemetryModule)) as QuickPulseTelemetryModule;
|
||||
if (quickPulseModule != null)
|
||||
{
|
||||
{
|
||||
QuickPulseTelemetryProcessor processor = null;
|
||||
configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder.Use((next) =>
|
||||
{
|
||||
|
@ -155,8 +155,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
else
|
||||
{
|
||||
AspNetCoreEventSource.Instance.UnableToFindQuickPulseModuleInDI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSampling(TelemetryConfiguration configuration)
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
private readonly Action<ITelemetryModule, ApplicationInsightsServiceOptions> configure;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of <see cref="TelemetryModuleConfigurator"/>.
|
||||
/// </summary>
|
||||
/// Initializes a new instance of the <see cref="TelemetryModuleConfigurator"/> class.
|
||||
/// </summary>
|
||||
/// <param name="configure">The action used to configure telemetry module.</param>
|
||||
/// <param name="telemetryModuleType">The type of the telemetry module being configured.</param>
|
||||
public TelemetryModuleConfigurator(Action<ITelemetryModule, ApplicationInsightsServiceOptions> configure, Type telemetryModuleType)
|
||||
|
@ -37,7 +37,7 @@
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of <see cref="ITelemetryModule"/> to be configured.
|
||||
/// Gets the type of <see cref="ITelemetryModule"/> to be configured.
|
||||
/// </summary>
|
||||
public Type TelemetryModuleType { get; }
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
telemetry.Context.GetInternalContext().SdkVersion = this.sdkVersion;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="filter"></param>
|
||||
[Obsolete("ApplicationInsightsLoggerProvider is now enabled by default when enabling ApplicationInsights monitoring using UseApplicationInsights extension method on IWebHostBuilder or AddApplicationInsightsTelemetry extension method on IServiceCollection. From 2.7.0-beta3 onwards, calling this method will result in double logging and filters applied will not get applied. If interested in using just logging provider, then please use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package. Read more https://aka.ms/ApplicationInsightsILoggerFaq")]
|
||||
public static ILoggerFactory AddApplicationInsights(
|
||||
this ILoggerFactory factory,
|
||||
|
@ -67,8 +67,7 @@
|
|||
IServiceProvider serviceProvider,
|
||||
Func<string, LogLevel, bool> filter,
|
||||
Action loggerAddedCallback)
|
||||
{
|
||||
|
||||
{
|
||||
var client = serviceProvider.GetService<TelemetryClient>();
|
||||
var debugLoggerControl = serviceProvider.GetService<Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLoggerEvents>();
|
||||
var options = serviceProvider.GetService<IOptions<Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLoggerOptions>>();
|
||||
|
@ -87,8 +86,8 @@
|
|||
debugLoggerControl.LoggerAdded += loggerAddedCallback;
|
||||
}
|
||||
}
|
||||
|
||||
factory.AddProvider(new Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLoggerProvider(client, filter, options));
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "SDK intentionally catch ALL exceptions and never re-throws.")]
|
|
@ -27,7 +27,8 @@ namespace Microsoft.ApplicationInsights.AspNetCore
|
|||
/// <summary>
|
||||
/// RequestTrackingTelemetryModule.
|
||||
/// </summary>
|
||||
public RequestTrackingTelemetryModule() : this(null)
|
||||
public RequestTrackingTelemetryModule()
|
||||
: this(null)
|
||||
{
|
||||
this.CollectionOptions = new RequestCollectionOptions();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
|
||||
{
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
|
@ -23,10 +24,15 @@
|
|||
|
||||
/// <inheritdoc />
|
||||
public void Initialize(ITelemetry telemetry)
|
||||
{
|
||||
if (this.environment != null && !telemetry.Context.Properties.ContainsKey(AspNetCoreEnvironmentPropertyName))
|
||||
{
|
||||
if (this.environment != null)
|
||||
{
|
||||
telemetry.Context.Properties.Add(AspNetCoreEnvironmentPropertyName, this.environment.EnvironmentName);
|
||||
if (telemetry is ISupportProperties telProperties && !telProperties.Properties.ContainsKey(AspNetCoreEnvironmentPropertyName))
|
||||
{
|
||||
telProperties.Properties.Add(
|
||||
AspNetCoreEnvironmentPropertyName,
|
||||
this.environment.EnvironmentName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading;
|
||||
using Channel;
|
||||
using Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.Extensibility.Implementation;
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
|||
|
||||
/// <summary>
|
||||
/// Initializes role instance name and node name with the host name.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="telemetry">Telemetry item.</param>
|
||||
public void Initialize(ITelemetry telemetry)
|
||||
{
|
||||
|
@ -33,7 +33,7 @@
|
|||
{
|
||||
string hostName = Dns.GetHostName();
|
||||
|
||||
// Issue #61: For dnxcore machine name does not have domain name like in full framework
|
||||
// Issue #61: For dnxcore machine name does not have domain name like in full framework
|
||||
#if NET451 || NET46
|
||||
string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
|
||||
if (!hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
|
||||
{
|
||||
using Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class WebSessionTelemetryInitializer : TelemetryInitializerBase
|
||||
{
|
||||
private const string WebSessionCookieName = "ai_session";
|
||||
|
||||
|
||||
public WebSessionTelemetryInitializer(IHttpContextAccessor httpContextAccessor)
|
||||
: base(httpContextAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(telemetry.Context.Session.Id))
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
public class WebUserTelemetryInitializer : TelemetryInitializerBase
|
||||
{
|
||||
private const string WebUserCookieName = "ai_user";
|
||||
|
||||
|
||||
public WebUserTelemetryInitializer(IHttpContextAccessor httpContextAccessor)
|
||||
: base(httpContextAccessor)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче