#16 Create a lightup package for Application Insights

This commit is contained in:
Chris R 2017-03-31 12:01:45 -07:00
parent c3a01be904
commit 975cfcb8ce
7 changed files with 185 additions and 1 deletions

View File

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

View File

@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<AspNetCoreVersion>1.2.0-*</AspNetCoreVersion>
<AppInsightsVersion>2.0.0</AppInsightsVersion>
<CoreFxVersion>4.3.0</CoreFxVersion>
<InternalAspNetCoreSdkVersion>2.0.0-*</InternalAspNetCoreSdkVersion>
<MoqVersion>4.7.1</MoqVersion>

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="..\..\build\dependencies.props" />
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(PackageTargetFallback);portable-net40+sl5+win8+wp8+wpa81;portable-net45+win8+wp8+wpa81</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.HttpSys" Version="$(AspNetCoreVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.ApplicationInsightsLightup\Microsoft.AspNetCore.ApplicationInsightsLightup.csproj" />
</ItemGroup>
</Project>

View File

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

View File

@ -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<string>().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<Startup>()
.Build();
host.Run();
}
}
}

View File

@ -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
{
/// <summary>
/// A dynamic Application Insights lightup experiance
/// </summary>
public class ApplicationInsightsStartupLoader : IHostingStartup
{
/// <summary>
/// Calls UseApplicationInsights
/// </summary>
/// <param name="builder"></param>
public void Configure(IWebHostBuilder builder)
{
builder.UseApplicationInsights();
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>ASP.NET Core lightup integration with Application Insights.</Description>
<TargetFramework>netstandard1.6</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;ApplicationInsights;Analytics;Telemetry;AppInsights</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="$(AppInsightsVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>