diff --git a/src/Microsoft.ApplicationInsights.AspNet/ContextInitializers/DomainNameRoleInstanceContextInitializer.cs b/src/Microsoft.ApplicationInsights.AspNet/ContextInitializers/DomainNameRoleInstanceContextInitializer.cs index 5840f3f..3a3e565 100644 --- a/src/Microsoft.ApplicationInsights.AspNet/ContextInitializers/DomainNameRoleInstanceContextInitializer.cs +++ b/src/Microsoft.ApplicationInsights.AspNet/ContextInitializers/DomainNameRoleInstanceContextInitializer.cs @@ -34,17 +34,16 @@ private string GetMachineName() { - string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; string hostName = Dns.GetHostName(); - + +#if !dnxcore50 + string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; if (!hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase)) { hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName); } - +#endif return hostName; } - - } } \ No newline at end of file diff --git a/src/Microsoft.ApplicationInsights.AspNet/Extensions/ApplicationInsightsExtensions.cs b/src/Microsoft.ApplicationInsights.AspNet/Extensions/ApplicationInsightsExtensions.cs index 47ae86c..5212423 100644 --- a/src/Microsoft.ApplicationInsights.AspNet/Extensions/ApplicationInsightsExtensions.cs +++ b/src/Microsoft.ApplicationInsights.AspNet/Extensions/ApplicationInsightsExtensions.cs @@ -58,7 +58,7 @@ services.AddScoped((svcs) => { var rt = new RequestTelemetry(); // this is workaround to inject proper instrumentation key into javascript: - rt.Context.InstrumentationKey = svcs.GetService().Context.InstrumentationKey; + rt.Context.InstrumentationKey = svcs.GetService().InstrumentationKey; return rt; }); } diff --git a/src/Microsoft.ApplicationInsights.AspNet/Fakes.cs b/src/Microsoft.ApplicationInsights.AspNet/Fakes.cs deleted file mode 100644 index 2d44b02..0000000 --- a/src/Microsoft.ApplicationInsights.AspNet/Fakes.cs +++ /dev/null @@ -1,239 +0,0 @@ -#if fakeportable -using Microsoft.ApplicationInsights.Channel; -using Microsoft.ApplicationInsights.DataContracts; -using Microsoft.ApplicationInsights.Extensibility; -using System; -using System.Collections.Generic; - -namespace Microsoft.ApplicationInsights -{ - public class TelemetryClient - { - public TelemetryClient() - { - } - - public TelemetryClient(TelemetryConfiguration telemetryConfiguration) - { - } - - public TelemetryContext Context { get; } - public void TrackEvent(string eventName) - { - } - public void TrackEvent(EventTelemetry telemetry) - { - } - public void TrackMetric(string name, double value) - { - } - public void TrackMetric(string name, double average, int sampleCount, double min, double max, IDictionary properties) - { - } - public void TrackRequest(RequestTelemetry request) - { - } - public void TrackException(Exception exception) - { - } - public void TrackTrace(string message) - { - } - public void TrackTrace(string message, SeverityLevel? severityLevel) - { - } - public void TrackTrace(string message, IDictionary properties) - { - } - public void TrackTrace(string message, SeverityLevel? severityLevel, IDictionary properties) - { - } - public void Track(ITelemetry telemetry) - { - } - } -} -namespace Microsoft.ApplicationInsights.Channel -{ - public interface ITelemetry - { - TelemetryContext Context { get; } - } - public interface ITelemetryChannel : IDisposable - { - bool DeveloperMode { get; set; } - } -} - -namespace Microsoft.ApplicationInsights.DataContracts -{ - public class TelemetryContext - { - public string InstrumentationKey { get; set; } - public OperationContext Operation { get; } - public LocationContext Location { get; } - public DeviceContext Device { get; } - public SessionContext Session { get; } - public UserContext User { get; } - } - - public class OperationContext - { - public string Id { get; set; } - public string Name { get; set; } - } - - public class LocationContext - { - public string Ip { get; set; } - } - - public class DeviceContext - { - public string RoleInstance { get; set; } - } - - public class SessionContext - { - public string Id { get; set; } - } - - public class UserContext - { - public string Id { get; set; } - public string UserAgent { get; set; } - public string AccountId { get; set; } - public DateTimeOffset? AcquisitionDate { get; set; } - } - - public class RequestTelemetry : ITelemetry - { - public ITelemetryChannel TelemetryChannel { get; set; } - public TelemetryContext Context { get; } - public TimeSpan Duration { get; set; } - public string HttpMethod { get; set; } - public string Id { get; set; } - public IDictionary Metrics { get; } - public string Name { get; set; } - public IDictionary Properties { get; } - public string ResponseCode { get; set; } - public string Sequence { get; set; } - public bool Success { get; set; } - public DateTimeOffset Timestamp { get; set; } - public Uri Url { get; set; } - } - - public class EventTelemetry : ITelemetry - { - private TelemetryContext context = new TelemetryContext(); - public DateTimeOffset Timestamp { get; set; } - public string Sequence { get; set; } - - public TelemetryContext Context - { - get - { - return this.context; - } - } - } - - public enum ExceptionHandledAt - { - Unhandled, - UserCode, - Platform - } - - public class ExceptionTelemetry : ITelemetry - { - public ExceptionTelemetry() {} - public ExceptionTelemetry(Exception exception) {} - public DateTimeOffset Timestamp { get; set; } - public string Sequence { get; set; } - public TelemetryContext Context { get; set; } - public ExceptionHandledAt HandledAt { get; set; } - public Exception Exception { get; set; } - public IDictionary Metrics { get; set; } - public IDictionary Properties { get; set; } - public SeverityLevel? SeverityLevel { get; set; } - } - - public class MetricTelemetry : ITelemetry - { - private TelemetryContext context = new TelemetryContext(); - public DateTimeOffset Timestamp { get; set; } - public string Sequence { get; set; } - public TelemetryContext Context - { - get - { - return this.context; - } - } - } - - public class TraceTelemetry : ITelemetry - { - private TelemetryContext context = new TelemetryContext(); - public DateTimeOffset Timestamp { get; set; } - public string Sequence { get; set; } - public TelemetryContext Context - { - get - { - return this.context; - } - } - } - - public enum SeverityLevel - { - Verbose, - Information, - Warning, - Error, - Critical - } -} - -namespace Microsoft.ApplicationInsights.Extensibility -{ - public class TelemetryConfiguration - { - public ITelemetryChannel TelemetryChannel { get; set; } - public string InstrumentationKey { get; set; } - public IList ContextInitializers { get; } - public IList TelemetryInitializers { get; } - public static TelemetryConfiguration CreateDefault() - { - return new TelemetryConfiguration(); - } - } - - public class TimestampPropertyInitializer - { - } - - public interface IContextInitializer - { - } - - public interface ITelemetryInitializer - { - } -} - -namespace System.Net.NetworkInformation -{ - public class IPGlobalProperties - { - public string DomainName { get; } - public static IPGlobalProperties GetIPGlobalProperties() - { - return new IPGlobalProperties(); - } - } -} -#endif - diff --git a/src/Microsoft.ApplicationInsights.AspNet/project.json b/src/Microsoft.ApplicationInsights.AspNet/project.json index 4147320..7ef67c3 100644 --- a/src/Microsoft.ApplicationInsights.AspNet/project.json +++ b/src/Microsoft.ApplicationInsights.AspNet/project.json @@ -1,11 +1,11 @@ -{ +{ "title": "Application Insights for ASP.NET 5 Web Applications", "description": "Application Insights for ASP.NET 5 web applications. See http://go.microsoft.com/fwlink/?LinkID=510752 for more information.", "authors": [ "Microsoft" ], "version": "0.30.0.1-beta", "copyright": "Copyright © Microsoft. All Rights Reserved.", "projectUrl": "https://github.com/Microsoft/AppInsights-aspnetv5", - "licenseUrl": "http://go.microsoft.com/fwlink/?LinkID=510709", + "licenseUrl": "http://go.microsoft.com/fwlink/?LinkID=510709", "requireLicenseAcceptance": true, "iconUrl": "http://appanacdn.blob.core.windows.net/cdn/icons/aic.png", "tags": [ "Analytics", "ApplicationInsights", "Telemetry", "AppInsights" ], @@ -15,18 +15,15 @@ "Microsoft.AspNet.Http": "1.0.0-beta4-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-beta4-*", "Microsoft.AspNet.Mvc.Core": "6.0.0-beta4-*", - "System.Net.NameResolution": "4.0.0-beta-*" + "System.Net.NameResolution": "4.0.0-beta-*", + "Microsoft.ApplicationInsights": "0.16.1-build00185" }, "frameworks": { - "dnx451": { - "dependencies": { - "Microsoft.ApplicationInsights": "0.13.4-build00460" - } - }, + "dnx451": { }, "dnxcore50": { "compilationOptions": { - "define": [ "fakeportable" ] + "define": [ "dnxcore50" ] } } } diff --git a/test/FunctionalTestUtils/BackTelemetryChannel.cs b/test/FunctionalTestUtils/BackTelemetryChannel.cs index a91c437..778eb82 100644 --- a/test/FunctionalTestUtils/BackTelemetryChannel.cs +++ b/test/FunctionalTestUtils/BackTelemetryChannel.cs @@ -3,6 +3,7 @@ namespace FunctionalTestUtils { using Microsoft.ApplicationInsights.Channel; using System.Collections.Generic; + using System; internal class BackTelemetryChannel : ITelemetryChannel { @@ -14,10 +15,28 @@ namespace FunctionalTestUtils public bool DeveloperMode { get; set; } + public string EndpointAddress + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + public void Dispose() { } + public void Flush() + { + throw new NotImplementedException(); + } + public void Send(ITelemetry item) { if (this.buffer != null) diff --git a/test/FunctionalTestUtils/project.json b/test/FunctionalTestUtils/project.json index 0a48f40..05ea013 100644 --- a/test/FunctionalTestUtils/project.json +++ b/test/FunctionalTestUtils/project.json @@ -7,18 +7,17 @@ "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4-*", "Microsoft.Net.Http.Client": "1.0.0-*", "xunit": "2.0.0-beta4-build2738", - "Microsoft.Framework.Runtime": "1.0.0-beta4-*" + "Microsoft.Framework.Runtime": "1.0.0-beta4-*", + "Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta" }, "frameworks": { "dnx451": { "dependencies": { - "Microsoft.ApplicationInsights": "0.13.4-build00460" } }, "dnxcore50": { "dependencies": { - "Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta" } } } diff --git a/test/Microsoft.ApplicationInsights.AspNet.Tests/ContextInitializers/DomainNameRoleInstanceContextInitializerTests.cs b/test/Microsoft.ApplicationInsights.AspNet.Tests/ContextInitializers/DomainNameRoleInstanceContextInitializerTests.cs index 481f2a4..9f21241 100644 --- a/test/Microsoft.ApplicationInsights.AspNet.Tests/ContextInitializers/DomainNameRoleInstanceContextInitializerTests.cs +++ b/test/Microsoft.ApplicationInsights.AspNet.Tests/ContextInitializers/DomainNameRoleInstanceContextInitializerTests.cs @@ -17,14 +17,16 @@ var telemetryContext = new TelemetryContext(); source.Initialize(telemetryContext); - - string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; + string hostName = Dns.GetHostName(); +#if !dnxcore50 + string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; if (hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase) == false) { hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName); } +#endif Assert.Equal(hostName, telemetryContext.Device.RoleInstance); } diff --git a/test/Microsoft.ApplicationInsights.AspNet.Tests/Extensions/ApplicationInsightsExtensionsTests.cs b/test/Microsoft.ApplicationInsights.AspNet.Tests/Extensions/ApplicationInsightsExtensionsTests.cs index f33d2e5..8094f4b 100644 --- a/test/Microsoft.ApplicationInsights.AspNet.Tests/Extensions/ApplicationInsightsExtensionsTests.cs +++ b/test/Microsoft.ApplicationInsights.AspNet.Tests/Extensions/ApplicationInsightsExtensionsTests.cs @@ -14,7 +14,7 @@ using Microsoft.AspNet.Hosting; using Microsoft.Framework.ConfigurationModel; using Xunit; - + public static class ApplicationInsightsExtensionsTests { public static ServiceCollection GetServiceCollectionWithContextAccessor() @@ -157,6 +157,9 @@ [Fact] public static void RegistersTelemetryClientToGetTelemetryConfigurationFromContainerAndNotGlobalInstance() { + ITelemetry sentTelemetry = null; + var telemetryChannel = new FakeTelemetryChannel { OnSend = telemetry => sentTelemetry = telemetry }; + var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor(); services.AddApplicationInsightsTelemetry(new Configuration()); @@ -164,8 +167,14 @@ IServiceProvider serviceProvider = services.BuildServiceProvider(); var configuration = serviceProvider.GetRequiredService(); configuration.InstrumentationKey = Guid.NewGuid().ToString(); + configuration.TelemetryChannel = telemetryChannel; + var telemetryClient = serviceProvider.GetRequiredService(); - Assert.Equal(configuration.InstrumentationKey, telemetryClient.Context.InstrumentationKey); + telemetryClient.TrackEvent("myevent"); + + // We want to check that configuration from contaier was used but configuration is a private field so we check + // instrumentation key instead + Assert.Equal(configuration.InstrumentationKey, sentTelemetry.Context.InstrumentationKey); } } diff --git a/test/Microsoft.ApplicationInsights.AspNet.Tests/FakeTelemetryChannel.cs b/test/Microsoft.ApplicationInsights.AspNet.Tests/FakeTelemetryChannel.cs index e1a86d6..1e9a832 100644 --- a/test/Microsoft.ApplicationInsights.AspNet.Tests/FakeTelemetryChannel.cs +++ b/test/Microsoft.ApplicationInsights.AspNet.Tests/FakeTelemetryChannel.cs @@ -10,11 +10,29 @@ public bool DeveloperMode { get; set; } + public string EndpointAddress + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + public void Dispose() { throw new NotImplementedException(); } + public void Flush() + { + throw new NotImplementedException(); + } + public void Send(ITelemetry item) { this.OnSend(item); diff --git a/test/Microsoft.ApplicationInsights.AspNet.Tests/project.json b/test/Microsoft.ApplicationInsights.AspNet.Tests/project.json index 421202d..53ae3fb 100644 --- a/test/Microsoft.ApplicationInsights.AspNet.Tests/project.json +++ b/test/Microsoft.ApplicationInsights.AspNet.Tests/project.json @@ -19,6 +19,10 @@ "System.Runtime": "4.0.20-beta-*" } }, - "dnxcore50": { } + "dnxcore50": { + "compilationOptions": { + "define": [ "dnxcore50" ] + } + } } } diff --git a/test/Mvc6Framework45.FunctionalTests/project.json b/test/Mvc6Framework45.FunctionalTests/project.json index de38f76..c8d390a 100644 --- a/test/Mvc6Framework45.FunctionalTests/project.json +++ b/test/Mvc6Framework45.FunctionalTests/project.json @@ -24,7 +24,7 @@ "xunit.runner.aspnet": "2.0.0-aspnet-beta4-10239", "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta4-*", "System.Runtime": "4.0.20-beta-*", - "Microsoft.Framework.Runtime": "1.0.0-beta4-*" + "Microsoft.Framework.Runtime": "1.0.0-beta4-*", }, "commands": { /* Change the port number when you are self hosting this application */ @@ -36,14 +36,10 @@ "frameworks": { "dnx451": { "dependencies": { - "Microsoft.ApplicationInsights": "0.13.4-build00460", "System.Runtime": "4.0.20-beta-*" } }, "dnxcore50": { - "dependencies": { - "Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta" - } } }, "exclude": [ diff --git a/test/WebApiShimFw46.FunctionalTests/project.json b/test/WebApiShimFw46.FunctionalTests/project.json index ec1adc8..c9faef5 100644 --- a/test/WebApiShimFw46.FunctionalTests/project.json +++ b/test/WebApiShimFw46.FunctionalTests/project.json @@ -1,39 +1,40 @@ -{ - "webroot": "wwwroot", - "version": "1.0.0-*", +{ + "webroot": "wwwroot", + "version": "1.0.0-*", - "dependencies": { - "Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta", - "Microsoft.AspNet.Mvc": "6.0.0-beta4", - "Microsoft.AspNet.Server.IIS": "1.0.0-beta4", - "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", - "Microsoft.AspNet.StaticFiles": "1.0.0-beta4", - "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", - "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta4", - "FunctionalTestUtils": "1.0.0-*", - "xunit.runner.aspnet": "2.0.0-aspnet-beta4-10239" - }, + "dependencies": { + "Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta", + "Microsoft.AspNet.Mvc": "6.0.0-beta4", + "Microsoft.AspNet.Server.IIS": "1.0.0-beta4", + "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", + "Microsoft.AspNet.StaticFiles": "1.0.0-beta4", + "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", + "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta4", + "FunctionalTestUtils": "1.0.0-*", + "xunit.runner.aspnet": "2.0.0-aspnet-beta4-10239", + "Microsoft.ApplicationInsights": "0.16.1-build00185" + }, - "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000", - "test": "xunit.runner.aspnet" - }, + "commands": { + "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000", + "test": "xunit.runner.aspnet" + }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { } - }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + }, - "exclude": [ - "wwwroot", - "node_modules", - "bower_components" - ], - "publishExclude": [ - "node_modules", - "bower_components", - "**.xproj", - "**.user", - "**.vspscc" - ] + "exclude": [ + "wwwroot", + "node_modules", + "bower_components" + ], + "publishExclude": [ + "node_modules", + "bower_components", + "**.xproj", + "**.user", + "**.vspscc" + ] } diff --git a/test/runAllTests.cmd b/test/runAllTests.cmd new file mode 100644 index 0000000..267ea86 --- /dev/null +++ b/test/runAllTests.cmd @@ -0,0 +1,8 @@ +%DNX_HOME%\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe .\Microsoft.ApplicationInsights.AspNet.Tests test +%DNX_HOME%\runtimes\dnx-coreclr-win-x86.1.0.0-beta4\bin\dnx.exe .\Microsoft.ApplicationInsights.AspNet.Tests test + +%DNX_HOME%\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe .\Mvc6Framework45.FunctionalTests test +%DNX_HOME%\runtimes\dnx-coreclr-win-x86.1.0.0-beta4\bin\dnx.exe .\Mvc6Framework45.FunctionalTests test + +%DNX_HOME%\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe .\WebApiShimFw46.FunctionalTests test +%DNX_HOME%\runtimes\dnx-coreclr-win-x86.1.0.0-beta4\bin\dnx.exe .\WebApiShimFw46.FunctionalTests test \ No newline at end of file