1
0
Форкнуть 0
This commit is contained in:
Anastasia Baranchenkova 2015-05-01 22:50:50 -07:00
Родитель 241881db3f
Коммит ec93fcf4a2
13 изменённых файлов: 114 добавлений и 301 удалений

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

@ -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;
}
}
}

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

@ -58,7 +58,7 @@
services.AddScoped<RequestTelemetry>((svcs) => {
var rt = new RequestTelemetry();
// this is workaround to inject proper instrumentation key into javascript:
rt.Context.InstrumentationKey = svcs.GetService<TelemetryClient>().Context.InstrumentationKey;
rt.Context.InstrumentationKey = svcs.GetService<TelemetryConfiguration>().InstrumentationKey;
return rt;
});
}

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

@ -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<string, string> 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<string, string> properties)
{
}
public void TrackTrace(string message, SeverityLevel? severityLevel, IDictionary<string, string> 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<string, double> Metrics { get; }
public string Name { get; set; }
public IDictionary<string, string> 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<string, double> Metrics { get; set; }
public IDictionary<string, string> 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<IContextInitializer> ContextInitializers { get; }
public IList<ITelemetryInitializer> 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

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

@ -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" ]
}
}
}

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

@ -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)

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

@ -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"
}
}
}

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

@ -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);
}

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

@ -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<TelemetryConfiguration>();
configuration.InstrumentationKey = Guid.NewGuid().ToString();
configuration.TelemetryChannel = telemetryChannel;
var telemetryClient = serviceProvider.GetRequiredService<TelemetryClient>();
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);
}
}

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

@ -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);

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

@ -19,6 +19,10 @@
"System.Runtime": "4.0.20-beta-*"
}
},
"dnxcore50": { }
"dnxcore50": {
"compilationOptions": {
"define": [ "dnxcore50" ]
}
}
}
}

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

@ -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": [

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

@ -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"
]
}

8
test/runAllTests.cmd Normal file
Просмотреть файл

@ -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