From 975cfcb8ce2bf9efde1bce795c38595e615603c7 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 31 Mar 2017 12:01:45 -0700 Subject: [PATCH] #16 Create a lightup package for Application Insights --- AzureIntegration.sln | 18 ++++- build/dependencies.props | 1 + .../ApplicationInsightsLightupSample.csproj | 19 +++++ .../Properties/launchSettings.json | 28 +++++++ .../Startup.cs | 79 +++++++++++++++++++ .../ApplicationInsightsStartupLoader.cs | 24 ++++++ ...pNetCore.ApplicationInsightsLightup.csproj | 17 ++++ 7 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 sample/ApplicationInsightsLightupSample/ApplicationInsightsLightupSample.csproj create mode 100644 sample/ApplicationInsightsLightupSample/Properties/launchSettings.json create mode 100644 sample/ApplicationInsightsLightupSample/Startup.cs create mode 100644 src/Microsoft.AspNetCore.ApplicationInsightsLightup/ApplicationInsightsStartupLoader.cs create mode 100644 src/Microsoft.AspNetCore.ApplicationInsightsLightup/Microsoft.AspNetCore.ApplicationInsightsLightup.csproj diff --git a/AzureIntegration.sln b/AzureIntegration.sln index b2fc8fd520..7a2b00e4e3 100644 --- a/AzureIntegration.sln +++ b/AzureIntegration.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26323.1 +VisualStudioVersion = 15.0.26329.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.AzureAppServicesIntegration", "src\Microsoft.AspNetCore.AzureAppServicesIntegration\Microsoft.AspNetCore.AzureAppServicesIntegration.csproj", "{5916BEB5-0969-469B-976C-A392E015DFAC}" EndProject @@ -8,6 +8,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FF9B744E-6C5 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FFE2B87-BF8A-4B38-ADAB-2FE2F9BC4A7C}" ProjectSection(SolutionItems) = preProject + build\common.props = build\common.props + build\dependencies.props = build\dependencies.props NuGet.config = NuGet.config EndProjectSection EndProject @@ -23,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.AzureL EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureAppServicesLightupSample", "sample\AzureAppServicesLightupSample\AzureAppServicesLightupSample.csproj", "{939EA897-CA31-4F2E-BA51-22B570B64671}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.ApplicationInsightsLightup", "src\Microsoft.AspNetCore.ApplicationInsightsLightup\Microsoft.AspNetCore.ApplicationInsightsLightup.csproj", "{2849A2D9-7C08-4198-BF2B-8BFB4B13554D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationInsightsLightupSample", "sample\ApplicationInsightsLightupSample\ApplicationInsightsLightupSample.csproj", "{33E245F0-2566-4B5B-BA7C-8895B7A697AE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +55,14 @@ Global {939EA897-CA31-4F2E-BA51-22B570B64671}.Debug|Any CPU.Build.0 = Debug|Any CPU {939EA897-CA31-4F2E-BA51-22B570B64671}.Release|Any CPU.ActiveCfg = Release|Any CPU {939EA897-CA31-4F2E-BA51-22B570B64671}.Release|Any CPU.Build.0 = Release|Any CPU + {2849A2D9-7C08-4198-BF2B-8BFB4B13554D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2849A2D9-7C08-4198-BF2B-8BFB4B13554D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2849A2D9-7C08-4198-BF2B-8BFB4B13554D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2849A2D9-7C08-4198-BF2B-8BFB4B13554D}.Release|Any CPU.Build.0 = Release|Any CPU + {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -59,5 +73,7 @@ Global {9BA1B692-B313-4E22-A864-F0ADBBE3C3FA} = {CD650B4B-81C2-4A44-AEF2-A251A877C1F0} {AC023B45-7995-4D4A-8108-E512AE8E5734} = {FF9B744E-6C59-40CC-9E41-9D2EBD292435} {939EA897-CA31-4F2E-BA51-22B570B64671} = {37237C93-6855-40D9-9E60-418B093EF49A} + {2849A2D9-7C08-4198-BF2B-8BFB4B13554D} = {FF9B744E-6C59-40CC-9E41-9D2EBD292435} + {33E245F0-2566-4B5B-BA7C-8895B7A697AE} = {37237C93-6855-40D9-9E60-418B093EF49A} EndGlobalSection EndGlobal diff --git a/build/dependencies.props b/build/dependencies.props index cf4424fae5..4ecf8aef18 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,6 +1,7 @@ 1.2.0-* + 2.0.0 4.3.0 2.0.0-* 4.7.1 diff --git a/sample/ApplicationInsightsLightupSample/ApplicationInsightsLightupSample.csproj b/sample/ApplicationInsightsLightupSample/ApplicationInsightsLightupSample.csproj new file mode 100644 index 0000000000..2d0664466c --- /dev/null +++ b/sample/ApplicationInsightsLightupSample/ApplicationInsightsLightupSample.csproj @@ -0,0 +1,19 @@ + + + + + + netcoreapp2.0 + $(PackageTargetFallback);portable-net40+sl5+win8+wp8+wpa81;portable-net45+win8+wp8+wpa81 + + + + + + + + + + + + diff --git a/sample/ApplicationInsightsLightupSample/Properties/launchSettings.json b/sample/ApplicationInsightsLightupSample/Properties/launchSettings.json new file mode 100644 index 0000000000..ef56b247ce --- /dev/null +++ b/sample/ApplicationInsightsLightupSample/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:22071/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.ApplicationInsightsLightup;Microsoft.AspNetCore.Server.IISIntegration" + } + }, + "AzureAppServicesSample": { + "commandName": "project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.ApplicationInsightsLightup" + } + } + } +} \ No newline at end of file diff --git a/sample/ApplicationInsightsLightupSample/Startup.cs b/sample/ApplicationInsightsLightupSample/Startup.cs new file mode 100644 index 0000000000..cbb697e1e9 --- /dev/null +++ b/sample/ApplicationInsightsLightupSample/Startup.cs @@ -0,0 +1,79 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace IISSample +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) + { + loggerfactory.AddConsole(LogLevel.Debug); + + var logger = loggerfactory.CreateLogger("Requests"); + + app.Run(async (context) => + { + logger.LogDebug("Received request: " + context.Request.Method + " " + context.Request.Path); + + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); + await context.Response.WriteAsync(Environment.NewLine); + + await context.Response.WriteAsync("Address:" + Environment.NewLine); + await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); + await context.Response.WriteAsync("Host: " + context.Request.Headers["Host"] + Environment.NewLine); + await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine); + await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine); + await context.Response.WriteAsync("Query: " + context.Request.QueryString.Value + Environment.NewLine); + await context.Response.WriteAsync(Environment.NewLine); + + await context.Response.WriteAsync("Connection:" + Environment.NewLine); + await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); + await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); + await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); + await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); + await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); + await context.Response.WriteAsync(Environment.NewLine); + + await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); + await context.Response.WriteAsync(Environment.NewLine); + + await context.Response.WriteAsync("Headers:" + Environment.NewLine); + foreach (var header in context.Request.Headers) + { + await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); + } + await context.Response.WriteAsync(Environment.NewLine); + + await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); + var vars = Environment.GetEnvironmentVariables(); + foreach (var key in vars.Keys.Cast().OrderBy(key => key, StringComparer.OrdinalIgnoreCase)) + { + var value = vars[key]; + await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); + } + await context.Response.WriteAsync(Environment.NewLine); + }); + } + + public static void Main(string[] args) + { + var host = new WebHostBuilder() + .UseKestrel() + .UseStartup() + .Build(); + + host.Run(); + } + } +} + diff --git a/src/Microsoft.AspNetCore.ApplicationInsightsLightup/ApplicationInsightsStartupLoader.cs b/src/Microsoft.AspNetCore.ApplicationInsightsLightup/ApplicationInsightsStartupLoader.cs new file mode 100644 index 0000000000..67852a50c2 --- /dev/null +++ b/src/Microsoft.AspNetCore.ApplicationInsightsLightup/ApplicationInsightsStartupLoader.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Hosting; + +[assembly: HostingStartup(typeof(Microsoft.AspNetCore.ApplicationInsightsLightup.ApplicationInsightsStartupLoader))] + +namespace Microsoft.AspNetCore.ApplicationInsightsLightup +{ + /// + /// A dynamic Application Insights lightup experiance + /// + public class ApplicationInsightsStartupLoader : IHostingStartup + { + /// + /// Calls UseApplicationInsights + /// + /// + public void Configure(IWebHostBuilder builder) + { + builder.UseApplicationInsights(); + } + } +} diff --git a/src/Microsoft.AspNetCore.ApplicationInsightsLightup/Microsoft.AspNetCore.ApplicationInsightsLightup.csproj b/src/Microsoft.AspNetCore.ApplicationInsightsLightup/Microsoft.AspNetCore.ApplicationInsightsLightup.csproj new file mode 100644 index 0000000000..4f67f79380 --- /dev/null +++ b/src/Microsoft.AspNetCore.ApplicationInsightsLightup/Microsoft.AspNetCore.ApplicationInsightsLightup.csproj @@ -0,0 +1,17 @@ + + + + + + ASP.NET Core lightup integration with Application Insights. + netstandard1.6 + true + aspnetcore;ApplicationInsights;Analytics;Telemetry;AppInsights + + + + + + + + \ No newline at end of file