Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #820 from Microsoft/develop
Browse files Browse the repository at this point in the history
Develop to master 2.6.0-beta3
  • Loading branch information
cijothomas authored Jan 3, 2019
2 parents 60fae22 + a15d8e5 commit 322df6c
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 221 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 2.6.0-beta3
- Updated Web/Base SDK version dependency to 2.9.0-beta3
- [Deprecate ApplicationInsightsLoggerFactoryExtensions.AddApplicationInsights logging extensions in favor of Microsoft.Extensions.Logging.ApplicationInsights package](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/817)
- [Fix: Do not track requests by each host in the process](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/621)
- [Fix: Correlation doesn't work for localhost](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1120)

## Version 2.6.0-beta2
- Updated Web/Base SDK version dependency to 2.9.0-beta2

Expand Down
1 change: 0 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="applicationinsights" value="https://www.myget.org/F/applicationinsights/api/v3/index.json" />
</packageSources>
<disabledPackageSources />
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class HostingDiagnosticListener : IApplicationInsightDiagnosticListener
private readonly bool injectResponseHeaders;
private readonly bool trackExceptions;
private readonly bool enableW3CHeaders;

private static readonly ActiveSubsciptionManager SubscriptionManager = new ActiveSubsciptionManager();
private const string ActivityCreatedByHostingDiagnosticListener = "ActivityCreatedByHostingDiagnosticListener";

/// <summary>
Expand All @@ -49,7 +49,12 @@ internal class HostingDiagnosticListener : IApplicationInsightDiagnosticListener
/// <param name="injectResponseHeaders">Flag that indicates that response headers should be injected.</param>
/// <param name="trackExceptions">Flag that indicates that exceptions should be tracked.</param>
/// <param name="enableW3CHeaders">Flag that indicates that W3C header parsing should be enabled.</param>
public HostingDiagnosticListener(TelemetryClient client, IApplicationIdProvider applicationIdProvider, bool injectResponseHeaders, bool trackExceptions, bool enableW3CHeaders)
public HostingDiagnosticListener(
TelemetryClient client,
IApplicationIdProvider applicationIdProvider,
bool injectResponseHeaders,
bool trackExceptions,
bool enableW3CHeaders)
{
this.client = client ?? throw new ArgumentNullException(nameof(client));
this.applicationIdProvider = applicationIdProvider;
Expand All @@ -58,6 +63,12 @@ public HostingDiagnosticListener(TelemetryClient client, IApplicationIdProvider
this.enableW3CHeaders = enableW3CHeaders;
}

/// <inheritdoc />
public void OnSubscribe()
{
SubscriptionManager.Attach(this);
}

/// <inheritdoc/>
public string ListenerName { get; } = "Microsoft.AspNetCore";

Expand All @@ -78,6 +89,15 @@ public void OnHttpRequestInStart(HttpContext httpContext)
{
if (this.client.IsEnabled())
{
// It's possible to host multiple apps (ASP.NET Core or generic hosts) in the same process
// Each of this apps has it's own HostingDiagnosticListener and corresponding Http listener.
// We should ignore events for all of them except one
if (!SubscriptionManager.IsActive(this))
{
AspNetCoreEventSource.Instance.NotActiveListenerNoTracking("Microsoft.AspNetCore.Hosting.HttpRequestIn.Start", Activity.Current?.Id);
return;
}

if (Activity.Current == null)
{
AspNetCoreEventSource.Instance.LogHostingDiagnosticListenerOnHttpRequestInStartActivityNull();
Expand Down Expand Up @@ -170,6 +190,16 @@ public void OnBeginRequest(HttpContext httpContext, long timestamp)
{
if (this.client.IsEnabled() && !IsAspNetCore20)
{
// It's possible to host multiple apps (ASP.NET Core or generic hosts) in the same process
// Each of this apps has it's own HostingDiagnosticListener and corresponding Http listener.
// We should ignore events for all of them except one
if (!SubscriptionManager.IsActive(this))
{
AspNetCoreEventSource.Instance.NotActiveListenerNoTracking(
"Microsoft.AspNetCore.Hosting.BeginRequest", Activity.Current?.Id);
return;
}

var activity = new Activity(ActivityCreatedByHostingDiagnosticListener);
var isActivityCreatedFromRequestIdHeader = false;

Expand Down Expand Up @@ -374,6 +404,16 @@ private void EndRequest(HttpContext httpContext, long timestamp)
{
if (this.client.IsEnabled())
{
// It's possible to host multiple apps (ASP.NET Core or generic hosts) in the same process
// Each of this apps has it's own HostingDiagnosticListener and corresponding Http listener.
// We should ignore events for all of them except one
if (!SubscriptionManager.IsActive(this))
{
AspNetCoreEventSource.Instance.NotActiveListenerNoTracking(
"EndRequest", Activity.Current?.Id);
return;
}

var telemetry = httpContext?.Features.Get<RequestTelemetry>();

if (telemetry == null)
Expand Down Expand Up @@ -415,6 +455,16 @@ private void OnException(HttpContext httpContext, Exception exception)
{
if (this.trackExceptions && this.client.IsEnabled())
{
// It's possible to host multiple apps (ASP.NET Core or generic hosts) in the same process
// Each of this apps has it's own HostingDiagnosticListener and corresponding Http listener.
// We should ignore events for all of them except one
if (!SubscriptionManager.IsActive(this))
{
AspNetCoreEventSource.Instance.NotActiveListenerNoTracking(
"Exception", Activity.Current?.Id);
return;
}

var telemetry = httpContext?.Features.Get<RequestTelemetry>();
if (telemetry != null)
{
Expand Down Expand Up @@ -504,6 +554,11 @@ private static bool TryExtractAppIdFromAzureTracestate(string azTracestate, out
appId = appIds[0];
return true;
}

public void Dispose()
{
SubscriptionManager.Detach(this);
}
}
#pragma warning restore 612, 618
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
{
using System;

/// <summary>
/// Base diagnostic listener type for Application Insight
/// </summary>
internal interface IApplicationInsightDiagnosticListener
internal interface IApplicationInsightDiagnosticListener : IDisposable
{
/// <summary>
/// Gets a value indicating which listener this instance should be subscribed to
/// </summary>
string ListenerName { get; }

/// <summary>
/// Notifies listener that it is subscribed to DiagnosticSource
/// </summary>
void OnSubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void OnBeforeAction(HttpContext httpContext, IRouteData routeData)
}
}

/// <inheritdoc />
public void OnSubscribe()
{
}

private string GetNameFromRouteContext(IRouteData routeData)
{
string name = null;
Expand Down Expand Up @@ -93,6 +98,10 @@ private string GetNameFromRouteContext(IRouteData routeData)
return name;
}

public void Dispose()
{
}

/// <summary>
/// Proxy interface for <c>RouteData</c> class from Microsoft.AspNetCore.Routing.Abstractions
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public void UnableToFindQuickPulseModuleInDI(string appDomainName = "Incorrect")
this.WriteEvent(12, this.ApplicationName);
}

[Event(
13,
Keywords = Keywords.Diagnostics,
Message = "Not tracking operation for event = '{0}', id = '{1}', lisener is not active.",
Level = EventLevel.Verbose)]
public void NotActiveListenerNoTracking(string evntName, string activityId, string appDomainName = "Incorrect")
{
this.WriteEvent(13, evntName, activityId, this.ApplicationName);
}

/// <summary>
/// Keywords for the AspNetEventSource.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
services.AddSingleton<ITelemetryModule, DependencyTrackingTelemetryModule>();
services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
{
module.EnableLegacyCorrelationHeadersInjection =
o.DependencyCollectionOptions.EnableLegacyCorrelationHeadersInjection;
var excludedDomains = module.ExcludeComponentCorrelationHttpHeadersOnDomains;
excludedDomains.Add("core.windows.net");
excludedDomains.Add("core.chinacloudapi.cn");
excludedDomains.Add("core.cloudapi.de");
excludedDomains.Add("core.usgovcloudapi.net");
excludedDomains.Add("localhost");
excludedDomains.Add("127.0.0.1");
if (module.EnableLegacyCorrelationHeadersInjection)
{
excludedDomains.Add("localhost");
excludedDomains.Add("127.0.0.1");
}
var includedActivities = module.IncludeDiagnosticSourceActivities;
includedActivities.Add("Microsoft.Azure.EventHubs");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Microsoft.ApplicationInsights.AspNetCore.Extensions
{
using System.Reflection;
using Microsoft.ApplicationInsights.DependencyCollector;

/// <summary>
/// Application Insights service options defines the custom behavior of the features to add, as opposed to the default selection of features obtained from Application Insights.
Expand All @@ -9,7 +10,7 @@ public class ApplicationInsightsServiceOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationInsightsServiceOptions" /> class.
/// Application Insights service options that controlls the default behavior of application insights features.
/// Application Insights service options that controls the default behavior of application insights features.
/// </summary>
public ApplicationInsightsServiceOptions()
{
Expand All @@ -20,6 +21,7 @@ public ApplicationInsightsServiceOptions()
this.EnableHeartbeat = true;
this.AddAutoCollectedMetricExtractor = true;
this.RequestCollectionOptions = new RequestCollectionOptions();
this.DependencyCollectionOptions = new DependencyCollectionOptions();
this.ApplicationVersion = Assembly.GetEntryAssembly()?.GetName().Version.ToString();
}

Expand Down Expand Up @@ -80,5 +82,11 @@ public ApplicationInsightsServiceOptions()
/// Gets <see cref="RequestCollectionOptions"/> that allow to manage <see cref="RequestTrackingTelemetryModule"/>
/// </summary>
public RequestCollectionOptions RequestCollectionOptions { get; }

/// <summary>
/// Gets <see cref="DependencyCollectionOptions"/> that allow to manage <see cref="DependencyTrackingTelemetryModule"/>
/// </summary>
public DependencyCollectionOptions DependencyCollectionOptions { get; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Extensions.Options;

/// <summary>
/// <see cref="IConfigureOptions&lt;ApplicationInsightsServiceOptions&gt;"/> implemetation that reads options from 'appsettings.json',
/// <see cref="IConfigureOptions&lt;ApplicationInsightsServiceOptions&gt;"/> implementation that reads options from 'appsettings.json',
/// environment variables and sets developer mode based on debugger state.
/// </summary>
internal class DefaultApplicationInsightsServiceConfigureOptions : IConfigureOptions<ApplicationInsightsServiceOptions>
Expand Down Expand Up @@ -41,4 +41,4 @@ public void Configure(ApplicationInsightsServiceOptions options)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Microsoft.ApplicationInsights.AspNetCore.Extensions
{
/// <summary>
/// Default collection options define the custom behavior or non-default features of dependency collection.
/// </summary>
public class DependencyCollectionOptions
{
/// <summary>
/// Creates new instance of <see cref="DependencyCollectionOptions"/> class and fills default values.
/// </summary>
public DependencyCollectionOptions()
{
EnableLegacyCorrelationHeadersInjection = false;
}

/// <summary>
/// Gets or sets a value indicating whether to enable legacy (x-ms*) correlation headers injection.
/// </summary>
public bool EnableLegacyCorrelationHeadersInjection { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Microsoft.ApplicationInsights.AspNetCore.Extensions
{
/// <summary>
/// Request collection options define the custom behavior or non-default features of request collection.
/// </summary>
public class RequestCollectionOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class ApplicationInsightsLoggerFactoryExtensions
/// </summary>
/// <param name="factory"></param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
[Obsolete("Use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package")]
public static ILoggerFactory AddApplicationInsights(this ILoggerFactory factory, IServiceProvider serviceProvider)
{
return factory.AddApplicationInsights(serviceProvider, LogLevel.Warning);
Expand All @@ -27,6 +28,7 @@ public static ILoggerFactory AddApplicationInsights(this ILoggerFactory factory,
/// <param name="factory"></param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
/// <param name="minLevel">The minimum <see cref="LogLevel"/> to be logged</param>
[Obsolete("Use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package")]
public static ILoggerFactory AddApplicationInsights(
this ILoggerFactory factory,
IServiceProvider serviceProvider,
Expand All @@ -42,6 +44,7 @@ public static ILoggerFactory AddApplicationInsights(
/// <param name="factory"></param>
/// <param name="filter"></param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
[Obsolete("Use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package")]
public static ILoggerFactory AddApplicationInsights(
this ILoggerFactory factory,
IServiceProvider serviceProvider,
Expand All @@ -57,6 +60,7 @@ public static ILoggerFactory AddApplicationInsights(
/// <param name="filter"></param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for service resolution.</param>
/// <param name="loggerAddedCallback">The callback that gets executed when another ApplicationInsights logger is added.</param>
[Obsolete("Use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package")]
public static ILoggerFactory AddApplicationInsights(
this ILoggerFactory factory,
IServiceProvider serviceProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.ApplicationInsights.DataContracts;
using System;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.Extensions.Logging;

namespace Microsoft.ApplicationInsights.AspNetCore.Logging
{
/// <summary>
/// <see cref="ApplicationInsightsLoggerOptions"/> defines the custom behavior of the tracing information sent to Application Insights.
/// </summary>
[Obsolete("Use Microsoft.Extensions.Logging.ApplicationInsights.AddApplicationInsights.ApplicationInsightsLoggerOptions from Microsoft.Extensions.Logging.ApplicationInsights package")]
public class ApplicationInsightsLoggerOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Microsoft.ApplicationInsights.AspNetCore</AssemblyName>
<VersionPrefix>2.6.0-beta2</VersionPrefix>
<VersionPrefix>2.6.0-beta3</VersionPrefix>
<Authors>Microsoft</Authors>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<AssemblyTitle>Application Insights for ASP.NET Core Web Applications</AssemblyTitle>
Expand Down Expand Up @@ -81,11 +81,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.9.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.9.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.9.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.9.0-beta2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.0-beta3" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.9.0-beta3" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.9.0-beta3" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.9.0-beta3" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.9.0-beta3" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
Expand Down
Loading

0 comments on commit 322df6c

Please sign in to comment.