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

Commit b0b4fb2

Browse files
Merge branch 'develop' into dmitmatv_signing
2 parents 2699e36 + 86c3bd6 commit b0b4fb2

32 files changed

+601
-300
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Version 2.8.0-beta1
44
- [Add EventCounter collection.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/913)
5+
- [Performance fixes: One DiagSource Listener; Head Sampling Feature; No Concurrent Dictionary; etc...](https://github.com/microsoft/ApplicationInsights-aspnetcore/pull/907)
56
- [Fix: Add `IJavaScriptSnippet` service interface and update the `IServiceCollection` extension to register it for `JavaScriptSnippet`.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/890)
67
- [Make JavaScriptEncoder optional and Fallback to JavaScriptEncoder.Default.](https://github.com/microsoft/ApplicationInsights-aspnetcore/pull/918)
78

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/HostingDiagnosticListener.cs

Lines changed: 256 additions & 101 deletions
Large diffs are not rendered by default.

src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/MvcDiagnosticsListener.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners
1111
/// <summary>
1212
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for evens specific to AspNetCore Mvc layer
1313
/// </summary>
14+
[Obsolete("This class was merged with HostingDiagnosticsListener to optimize Diagnostics Source subscription performance")]
1415
public class MvcDiagnosticsListener : IApplicationInsightDiagnosticListener
1516
{
1617
/// <inheritdoc />

src/Microsoft.ApplicationInsights.AspNetCore/Extensibility/Implementation/Tracing/AspNetCoreEventSource.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ public void TelemetryConfigurationSetupFailure(string errorMessage, string appDo
173173
this.WriteEvent(17, errorMessage, this.ApplicationName);
174174
}
175175

176+
[Event(
177+
18,
178+
Keywords = Keywords.Diagnostics,
179+
Message = "Telemetry item was sampled out at head, OperationId: '{0}'",
180+
Level = EventLevel.Verbose)]
181+
public void TelemetryItemWasSampledOutAtHead(string operationId, string appDomainName = "Incorrect")
182+
{
183+
this.WriteEvent(18, operationId, this.ApplicationName);
184+
}
185+
176186
/// <summary>
177187
/// Keywords for the AspNetEventSource.
178188
/// </summary>

src/Microsoft.ApplicationInsights.AspNetCore/Implementation/TelemetryConfigurationOptionsSetup.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Microsoft.Extensions.DependencyInjection
1313
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
1414
using Microsoft.ApplicationInsights.Extensibility.W3C;
1515
using Microsoft.Extensions.Options;
16+
using Microsoft.ApplicationInsights.WindowsServer.Channel.Implementation;
17+
using Microsoft.ApplicationInsights.DataContracts;
1618

1719
/// <summary>
1820
/// Initializes TelemetryConfiguration based on values in <see cref="ApplicationInsightsServiceOptions"/>
@@ -163,7 +165,17 @@ private void AddSampling(TelemetryConfiguration configuration)
163165
{
164166
if (this.applicationInsightsServiceOptions.EnableAdaptiveSampling)
165167
{
166-
configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder.UseAdaptiveSampling(5, excludedTypes: "Event");
168+
AdaptiveSamplingPercentageEvaluatedCallback samplingCallback = (ratePerSecond, currentPercentage, newPercentage, isChanged, estimatorSettings) =>
169+
{
170+
if (isChanged)
171+
{
172+
configuration.SetLastObservedSamplingPercentage(SamplingTelemetryItemTypes.Request, newPercentage);
173+
}
174+
};
175+
176+
SamplingPercentageEstimatorSettings settings = new SamplingPercentageEstimatorSettings();
177+
settings.MaxTelemetryItemsPerSecond = 5;
178+
configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder.UseAdaptiveSampling(settings, samplingCallback, excludedTypes: "Event");
167179
configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder.UseAdaptiveSampling(5, includedTypes: "Event");
168180
}
169181
}

src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>Microsoft.ApplicationInsights.AspNetCore</AssemblyName>
44
<VersionPrefix>2.8.0-beta1</VersionPrefix>

src/Microsoft.ApplicationInsights.AspNetCore/RequestTrackingTelemetryModule.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace Microsoft.ApplicationInsights.AspNetCore
22
{
33
using System;
44
using System.Collections.Concurrent;
5-
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.Reflection;
87
using System.Threading;
@@ -17,15 +16,20 @@ namespace Microsoft.ApplicationInsights.AspNetCore
1716
/// </summary>
1817
public class RequestTrackingTelemetryModule : ITelemetryModule, IObserver<DiagnosticListener>, IDisposable
1918
{
20-
private TelemetryClient telemetryClient;
19+
// We are only interested in BeforeAction event from Microsoft.AspNetCore.Mvc source.
20+
// We are interested in Microsoft.AspNetCore.Hosting and Microsoft.AspNetCore.Diagnostics as well.
21+
// Below filter achieves acceptable performance, character 22 shoudl not be M unless event is BeforeAction.
22+
private static readonly Predicate<string> HostingPredicate = (string eventName) => (eventName != null) ? !(eventName[21] == 'M') || eventName == "Microsoft.AspNetCore.Mvc.BeforeAction" : false;
23+
private readonly object lockObject = new object();
2124
private readonly IApplicationIdProvider applicationIdProvider;
25+
26+
private TelemetryClient telemetryClient;
2227
private ConcurrentBag<IDisposable> subscriptions;
23-
private readonly List<IApplicationInsightDiagnosticListener> diagnosticListeners;
28+
private HostingDiagnosticListener diagnosticListener;
2429
private bool isInitialized = false;
25-
private readonly object lockObject = new object();
2630

2731
/// <summary>
28-
/// RequestTrackingTelemetryModule.
32+
/// Initializes a new instance of the <see cref="RequestTrackingTelemetryModule"/> class.
2933
/// </summary>
3034
public RequestTrackingTelemetryModule()
3135
: this(null)
@@ -34,14 +38,13 @@ public RequestTrackingTelemetryModule()
3438
}
3539

3640
/// <summary>
37-
/// Creates RequestTrackingTelemetryModule.
41+
/// Initializes a new instance of the <see cref="RequestTrackingTelemetryModule"/> class.
3842
/// </summary>
39-
/// <param name="applicationIdProvider"></param>
43+
/// <param name="applicationIdProvider">Provider to resolve Application Id</param>
4044
public RequestTrackingTelemetryModule(IApplicationIdProvider applicationIdProvider)
4145
{
4246
this.applicationIdProvider = applicationIdProvider;
4347
this.subscriptions = new ConcurrentBag<IDisposable>();
44-
this.diagnosticListeners = new List<IApplicationInsightDiagnosticListener>();
4548
}
4649

4750
/// <summary>
@@ -75,16 +78,14 @@ public void Initialize(TelemetryConfiguration configuration)
7578
// ignore any errors
7679
}
7780

78-
this.diagnosticListeners.Add(new HostingDiagnosticListener(
81+
this.diagnosticListener = new HostingDiagnosticListener(
82+
configuration,
7983
this.telemetryClient,
8084
this.applicationIdProvider,
8185
this.CollectionOptions.InjectResponseHeaders,
8286
this.CollectionOptions.TrackExceptions,
8387
this.CollectionOptions.EnableW3CDistributedTracing,
84-
enableNewDiagnosticEvents));
85-
86-
this.diagnosticListeners.Add
87-
(new MvcDiagnosticsListener());
88+
enableNewDiagnosticEvents);
8889

8990
this.subscriptions?.Add(DiagnosticListener.AllListeners.Subscribe(this));
9091

@@ -108,13 +109,10 @@ void IObserver<DiagnosticListener>.OnNext(DiagnosticListener value)
108109
return;
109110
}
110111

111-
foreach (var applicationInsightDiagnosticListener in this.diagnosticListeners)
112+
if (this.diagnosticListener.ListenerName == value.Name)
112113
{
113-
if (applicationInsightDiagnosticListener.ListenerName == value.Name)
114-
{
115-
subs.Add(value.Subscribe(applicationInsightDiagnosticListener));
116-
applicationInsightDiagnosticListener.OnSubscribe();
117-
}
114+
subs.Add(value.Subscribe(this.diagnosticListener, HostingPredicate));
115+
this.diagnosticListener.OnSubscribe();
118116
}
119117
}
120118

@@ -156,9 +154,9 @@ protected virtual void Dispose(bool disposing)
156154
subscription.Dispose();
157155
}
158156

159-
foreach (var listener in this.diagnosticListeners)
157+
if (this.diagnosticListener != null)
160158
{
161-
listener.Dispose();
159+
this.diagnosticListener.Dispose();
162160
}
163161
}
164162
}

test/ApplicationInsightsTypes/Generated/AvailabilityData_types.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//------------------------------------------------------------------------------
33
// This code was generated by a tool.
44
//
5-
// Tool : Bond Compiler 0.10.0.0
5+
// Tool : Bond Compiler 0.10.1.0
66
// File : AvailabilityData_types.cs
77
//
88
// Changes to this file may cause incorrect behavior and will be lost when
@@ -30,7 +30,7 @@ namespace AI
3030

3131
[global::Bond.Attribute("Description", "Instances of AvailabilityData represent the result of executing an availability test.")]
3232
[global::Bond.Schema]
33-
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.0.0")]
33+
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.1.0")]
3434
public partial class AvailabilityData
3535
: Domain
3636
{
@@ -73,13 +73,13 @@ public partial class AvailabilityData
7373
[global::Bond.Attribute("Description", "Collection of custom properties.")]
7474
[global::Bond.Attribute("MaxKeyLength", "150")]
7575
[global::Bond.Attribute("MaxValueLength", "8192")]
76-
[global::Bond.Id(100), global::Bond.Type(typeof(Dictionary<string, string>))]
77-
public IDictionary<string, string> properties { get; set; }
76+
[global::Bond.Id(100)]
77+
public Dictionary<string, string> properties { get; set; }
7878

7979
[global::Bond.Attribute("Description", "Collection of custom measurements.")]
8080
[global::Bond.Attribute("MaxKeyLength", "150")]
81-
[global::Bond.Id(200), global::Bond.Type(typeof(Dictionary<string, double>))]
82-
public IDictionary<string, double> measurements { get; set; }
81+
[global::Bond.Id(200)]
82+
public Dictionary<string, double> measurements { get; set; }
8383

8484
public AvailabilityData()
8585
: this("AI.AvailabilityData", "AvailabilityData")

test/ApplicationInsightsTypes/Generated/Base_types.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//------------------------------------------------------------------------------
33
// This code was generated by a tool.
44
//
5-
// Tool : Bond Compiler 0.10.0.0
5+
// Tool : Bond Compiler 0.10.1.0
66
// File : Base_types.cs
77
//
88
// Changes to this file may cause incorrect behavior and will be lost when
@@ -30,7 +30,7 @@ namespace AI
3030

3131
[global::Bond.Attribute("Description", "Data struct to contain only C section with custom fields.")]
3232
[global::Bond.Schema]
33-
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.0.0")]
33+
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.1.0")]
3434
public partial class Base
3535
{
3636
[global::Bond.Attribute("Name", "ItemTypeName")]

test/ApplicationInsightsTypes/Generated/ContextTagKeys_types.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//------------------------------------------------------------------------------
33
// This code was generated by a tool.
44
//
5-
// Tool : Bond Compiler 0.10.0.0
5+
// Tool : Bond Compiler 0.10.1.0
66
// File : ContextTagKeys_types.cs
77
//
88
// Changes to this file may cause incorrect behavior and will be lost when
@@ -31,7 +31,7 @@ namespace AI
3131
[global::Bond.Attribute("ContextContract", "Emit")]
3232
[global::Bond.Attribute("PseudoType", "JSMap")]
3333
[global::Bond.Schema]
34-
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.0.0")]
34+
[System.CodeDom.Compiler.GeneratedCode("gbc", "0.10.1.0")]
3535
public partial class ContextTagKeys
3636
{
3737
[global::Bond.Attribute("Description", "Application version. Information in the application context fields is always about the application that is sending the telemetry.")]
@@ -69,7 +69,7 @@ public partial class ContextTagKeys
6969
[global::Bond.Id(160)]
7070
public string DeviceType { get; set; }
7171

72-
[global::Bond.Attribute("Description", "The IP address of the client device. IPv4 and IPv6 is supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service.")]
72+
[global::Bond.Attribute("Description", "The IPv4 IP address of the client device. IPv6 is not currently supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service.")]
7373
[global::Bond.Attribute("MaxStringLength", "45")]
7474
[global::Bond.Id(200)]
7575
public string LocationIp { get; set; }
@@ -115,7 +115,7 @@ public partial class ContextTagKeys
115115
[global::Bond.Id(505)]
116116
public string UserAccountId { get; set; }
117117

118-
[global::Bond.Attribute("Description", "The browser's user agent string as reported by the browser. This property will be used to extract information regarding the customer's browser but will not be stored. Use custom properties to store the original user agent.")]
118+
[global::Bond.Attribute("Description", "The browser's user agent string as reported by the browser. This property will be used to extract informaiton regarding the customer's browser but will not be stored. Use custom properties to store the original user agent.")]
119119
[global::Bond.Attribute("MaxStringLength", "2048")]
120120
[global::Bond.Id(510)]
121121
public string UserAgent { get; set; }
@@ -135,7 +135,7 @@ public partial class ContextTagKeys
135135
[global::Bond.Id(705)]
136136
public string CloudRole { get; set; }
137137

138-
[global::Bond.Attribute("Description", "Name of the instance where the application is running. Computer name for on-premises, instance name for Azure.")]
138+
[global::Bond.Attribute("Description", "Name of the instance where the application is running. Computer name for on-premisis, instance name for Azure.")]
139139
[global::Bond.Attribute("MaxStringLength", "256")]
140140
[global::Bond.Id(715)]
141141
public string CloudRoleInstance { get; set; }
@@ -150,11 +150,6 @@ public partial class ContextTagKeys
150150
[global::Bond.Id(1001)]
151151
public string InternalAgentVersion { get; set; }
152152

153-
[global::Bond.Attribute("Description", "This is the node name used for billing purposes. Use it to override the standard detection of nodes.")]
154-
[global::Bond.Attribute("MaxStringLength", "256")]
155-
[global::Bond.Id(1002)]
156-
public string InternalNodeName { get; set; }
157-
158153
public ContextTagKeys()
159154
: this("AI.ContextTagKeys", "ContextTagKeys")
160155
{}
@@ -184,7 +179,6 @@ protected ContextTagKeys(string fullName, string name)
184179
CloudRoleInstance = "ai.cloud.roleInstance";
185180
InternalSdkVersion = "ai.internal.sdkVersion";
186181
InternalAgentVersion = "ai.internal.agentVersion";
187-
InternalNodeName = "ai.internal.nodeName";
188182
}
189183
}
190184
} // AI

0 commit comments

Comments
 (0)