1
0
Форкнуть 0

Reverting component version telemetry intializer and more updates with respect to RC2

This commit is contained in:
kartang 2016-05-06 11:00:56 -07:00
Родитель ddd4d47ea7
Коммит 758506e48f
17 изменённых файлов: 136 добавлений и 118 удалений

Просмотреть файл

@ -8,6 +8,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{62AD20FD-640F-4F99-94EF-96A7581F1CF9}"
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
build.ps1 = build.ps1
Common.targets = Common.targets
dirs.proj = dirs.proj
global.json = global.json

Просмотреть файл

@ -1,3 +1,3 @@
{
"sources": [ "src", "test" ]
"projects": [ "src", "test" ]
}

Просмотреть файл

@ -112,16 +112,6 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
this.WriteEvent(7, this.ApplicationName);
}
/// <summary>
/// Logs an event for the ComponentVersionTelemetryInitializer constructor method when accessing project.json throws an exception.
/// </summary>
/// <param name="appDomainName">An ignored placeholder to make EventSource happy.</param>
[Event(8, Message = "ComponentVersionTelemetryInitializer - acessing project.json failed.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void LogComponentVersionTelemetryInitializerFailsToAccessProjectJson(string appDomainName = "Incorrect")
{
this.WriteEvent(8, this.ApplicationName);
}
/// <summary>
/// Keywords for the AspNetEventSource.
/// </summary>

Просмотреть файл

@ -13,6 +13,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using AspNetCore.Http;
using AspNetCore.Mvc.Infrastructure;
#if NET451
using ApplicationInsights.Extensibility.PerfCounterCollector;
@ -44,8 +46,14 @@
{
var options = serviceOptions ?? new ApplicationInsightsServiceOptions();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddSingleton<ITelemetryInitializer, DomainNameRoleInstanceTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, ComponentVersionTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer>(serviceProvider =>
{
return new ComponentVersionTelemetryInitializer(config);
});
services.AddSingleton<ITelemetryInitializer, ClientIpHeaderTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, OperationIdTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, OperationNameTelemetryInitializer>();

Просмотреть файл

@ -1,45 +1,37 @@
namespace Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers
{
using System;
using Channel;
using Extensibility.Implementation.Tracing;
using Microsoft.Extensions.Configuration;
using ApplicationInsights.Extensibility;
/// <summary>
/// A telemetry initializer that populates telemetry.Context.Component.Version to the value read from project.json
/// A telemetry initializer that populates telemetry.Context.Component.Version to the value read from configuration
/// </summary>
public class ComponentVersionTelemetryInitializer : ITelemetryInitializer
{
private const string _versionConfigurationOption = "version";
private bool _isConfigBuilt = false;
private IConfiguration _configuration;
private string _appVersion;
public ComponentVersionTelemetryInitializer()
public ComponentVersionTelemetryInitializer(IConfiguration configuration)
{
try
if (configuration != null)
{
if (!this._isConfigBuilt)
{
var config = new ConfigurationBuilder()
.AddJsonFile("project.json")
.Build();
this._appVersion = config[_versionConfigurationOption];
this._isConfigBuilt = true;
}
}
catch(Exception e)
{
AspNetCoreEventSource.Instance.LogComponentVersionTelemetryInitializerFailsToAccessProjectJson();
this._configuration = configuration;
}
}
public void Initialize(ITelemetry telemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Component.Version) && !string.IsNullOrEmpty(this._appVersion))
if (string.IsNullOrEmpty(telemetry.Context.Component.Version))
{
telemetry.Context.Component.Version = this._appVersion;
if (this._configuration != null)
{
string version = this._configuration[_versionConfigurationOption];
if (!string.IsNullOrEmpty(version))
{
telemetry.Context.Component.Version = version;
}
}
}
}
}

Просмотреть файл

@ -26,9 +26,7 @@
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-*",
"Microsoft.Extensions.Configuration": "1.0.0-rc2-*",
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-rc2-*",
"Microsoft.ApplicationInsights": "2.1.0-beta4",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-*"
"Microsoft.ApplicationInsights": "2.1.0-beta4"
},
"frameworks": {

Просмотреть файл

@ -8,7 +8,7 @@
},
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
"FunctionalTestUtils": "*",
"FunctionalTestUtils": { "target": "project" },
"Microsoft.NETCore.Platforms": "1.0.1-*",
"dotnet-test-xunit": "1.0.0-*",
"xunit": "2.1.0"

Просмотреть файл

@ -43,7 +43,6 @@
Assert.InRange<DateTimeOffset>(actual.Timestamp, testStart, DateTimeOffset.Now);
Assert.True(actual.Duration < timer.Elapsed, "duration");
Assert.Equal(expected.HttpMethod, actual.HttpMethod);
// Assert.True(actual.Context.Component.Version.StartsWith("1.0.0"));
}
public void ValidateBasicException(InProcessServer server, string requestPath, ExceptionTelemetry expected)
@ -64,7 +63,6 @@
Assert.Equal(actual.HandledAt, actual.HandledAt);
Assert.NotEmpty(actual.Context.Operation.Name);
Assert.NotEmpty(actual.Context.Operation.Id);
// Assert.True(actual.Context.Component.Version.StartsWith("1.0.0"));
}
#if NET451

Просмотреть файл

@ -1,35 +1,37 @@
{
"buildOptions": {
"buildOptions": {
"keyFile": "../../keys/35MSSharedLib1024.snk",
"delaySign": true,
"preserveCompilationContext": true
},
"dependencies": {
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
"xunit": "2.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2"
},
"testRunner": "xunit",
"frameworks": {
"net451": {
"dependencies": {
"System.Net.Http": "4.0.1-rc2-*"
"preserveCompilationContext": true,
},
"dependencies": {
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
"xunit": "2.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*",
"Microsoft.ApplicationInsights.AspNetCore": {
"target": "project"
}
},
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"dotnet5.4",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002520"
"testRunner": "xunit",
"frameworks": {
"net451": {
"dependencies": {
"System.Net.Http": "4.0.1-rc2-*"
}
},
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"dotnet5.4",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002520"
}
}
}
}
}
}

Просмотреть файл

@ -32,7 +32,7 @@ namespace MVCFramework45.FunctionalTests.Controllers
return View();
}
public async Task<IActionResult> Contact()
public IActionResult Contact()
{
this.telemetryClient.TrackEvent("GetContact");
this.telemetryClient.TrackMetric("ContactFile", 1);

Просмотреть файл

@ -73,7 +73,6 @@ namespace MVCFramework45.FunctionalTests
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{

Просмотреть файл

@ -21,7 +21,8 @@
"type": "build",
"version": "1.0.0-*"
},
"FunctionalTestUtils": "*",
"FunctionalTestUtils": { "target": "project" },
"Microsoft.ApplicationInsights.AspNetCore": { "target": "project" },
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-*",
@ -41,7 +42,6 @@
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-*",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-*",
"xunit": "2.1.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-*",
"dotnet-test-xunit": "1.0.0-*"
},
"testRunner": "xunit",

Просмотреть файл

@ -21,11 +21,11 @@ namespace Microsoft.ApplicationInsights.AspNet.Tests.Extensibility.Implementatio
[Fact]
public void TestThatEventSourceMethodsAreImplementedConsistentlyWithTheirAttributes()
{
Assembly asm = Assembly.Load(new AssemblyName("Microsoft.ApplicationInsights.AspNet"));
Type eventSourceType = asm.GetType("Microsoft.ApplicationInsights.AspNet.Extensibility.Implementation.Tracing.AspNetEventSource");
EventSource aspNetEventSource = (EventSource)eventSourceType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
Assembly asm = Assembly.Load(new AssemblyName("Microsoft.ApplicationInsights.AspNetCore"));
Type eventSourceType = asm.GetType("Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing.AspNetCoreEventSource");
EventSource aspNetCoreEventSource = (EventSource)eventSourceType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
EventSourceTests.MethodsAreImplementedConsistentlyWithTheirAttributes(aspNetEventSource);
EventSourceTests.MethodsAreImplementedConsistentlyWithTheirAttributes(aspNetCoreEventSource);
}
}
}

Просмотреть файл

@ -122,13 +122,15 @@ namespace Microsoft.Extensions.DependencyInjection.Test
Assert.Equal("http://localhost:1234/v2/track/", telemetryConfiguration.TelemetryChannel.EndpointAddress);
}
[Fact]
public static void RegistersTelemetryConfigurationFactoryMethodThatReadsInstrumentationKeyFromEnvironment()
{
var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor();
services.AddSingleton<ITelemetryChannel>(new InMemoryChannel());
Environment.SetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", TestInstrumentationKey);
var config = new ConfigurationBuilder().Build();
var config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
try
{
services.AddApplicationInsightsTelemetry(config);
@ -143,12 +145,15 @@ namespace Microsoft.Extensions.DependencyInjection.Test
}
}
[Fact]
public static void RegistersTelemetryConfigurationFactoryMethodThatReadsDeveloperModeFromEnvironment()
{
var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor();
services.AddSingleton<ITelemetryChannel>(new InMemoryChannel());
Environment.SetEnvironmentVariable("APPINSIGHTS_DEVELOPER_MODE", "true");
var config = new ConfigurationBuilder().Build();
var config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
try
{
services.AddApplicationInsightsTelemetry(config);
@ -163,13 +168,15 @@ namespace Microsoft.Extensions.DependencyInjection.Test
}
}
[Fact]
public static void RegistersTelemetryConfigurationFactoryMethodThatReadsEndpointAddressFromEnvironment()
{
var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor();
services.AddSingleton<ITelemetryChannel>(new InMemoryChannel());
Environment.SetEnvironmentVariable("APPINSIGHTS_ENDPOINTADDRESS", "http://localhost:1234/v2/track/");
var config = new ConfigurationBuilder().Build();
var config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
try
{
services.AddApplicationInsightsTelemetry(config);

Просмотреть файл

@ -1,9 +1,11 @@
namespace Microsoft.ApplicationInsights.AspNet.Tests.TelemetryInitializers
{
using Extensions.Configuration;
using Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using System.IO;
using Xunit;
public class ComponentVersionTelemetryInitializerTests
@ -11,22 +13,43 @@
[Fact]
public void InitializeDoesNotThrowIfHttpContextIsUnavailable()
{
var initializer = new ComponentVersionTelemetryInitializer();
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("project.json")
.Build(); var initializer = new ComponentVersionTelemetryInitializer(config);
initializer.Initialize(new RequestTelemetry());
}
[Fact]
public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
{
var ac = new HttpContextAccessor() { HttpContext = null };
var initializer = new ComponentVersionTelemetryInitializer();
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("project.json")
.Build(); var initializer = new ComponentVersionTelemetryInitializer(config);
initializer.Initialize(new RequestTelemetry());
}
[Fact]
public void InitializeAssignsVersionToTelemetry()
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("project.json")
.Build();
var initializer = new ComponentVersionTelemetryInitializer(config);
var telemetry = new RequestTelemetry();
initializer.Initialize(telemetry);
Assert.NotNull(telemetry.Context.Component.Version);
}
[Fact]
public void InitializeDoesNotOverrideExistingVersion()
{
var initializer = new ComponentVersionTelemetryInitializer();
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("project.json")
.Build(); var initializer = new ComponentVersionTelemetryInitializer(config);
var telemetry = new RequestTelemetry();
telemetry.Context.Component.Version = "TestVersion";

Просмотреть файл

@ -1,46 +1,45 @@
{
"version": "1.0.0",
"buildOptions": {
"keyFile": "../../keys/35MSSharedLib1024.snk",
"delaySign": true,
"preserveCompilationContext": true,
"copyToOutput": {
"include": [ "content/*" ]
}
},
"dependencies": {
"Microsoft.AspNetCore.Http.Features": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Http": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-*",
"Microsoft.Extensions.Logging": "1.0.0-rc2-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-*",
"FunctionalTestUtils": "*"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"dotnet5.4",
"portable-net451+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002520"
}
}
},
"net451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
},
"dependencies": {
"Microsoft.AspNetCore.Http.Features": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Http": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-*",
"Microsoft.Extensions.Logging": "1.0.0-rc2-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-*",
"Microsoft.ApplicationInsights.AspNetCore": { "target": "project" },
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-*"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"dotnet5.4",
"portable-net451+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002520"
}
}
},
"content": [
]
"net451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
}
}
}

Просмотреть файл

@ -10,7 +10,8 @@
},
"testRunner": "xunit",
"dependencies": {
"FunctionalTestUtils": "*",
"FunctionalTestUtils": { "target": "project" },
"Microsoft.ApplicationInsights.AspNetCore": { "target": "project" },
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0-rc2-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-*",