reacting to telemetry rename
This commit is contained in:
parent
8bab053107
commit
828e8d755e
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"projects": ["src","c:/github/testing/src","/home/kiran/github/testing/src"]
|
"projects": ["src"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.Tracing;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
|
|
@ -88,9 +88,7 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
|
||||||
var contextFactory = _applicationServices.GetRequiredService<IHttpContextFactory>();
|
var contextFactory = _applicationServices.GetRequiredService<IHttpContextFactory>();
|
||||||
var contextAccessor = _applicationServices.GetRequiredService<IHttpContextAccessor>();
|
var contextAccessor = _applicationServices.GetRequiredService<IHttpContextAccessor>();
|
||||||
#pragma warning disable 0618
|
var diagnosticSource = _applicationServices.GetRequiredService<DiagnosticSource>();
|
||||||
var telemetrySource = _applicationServices.GetRequiredService<TelemetrySource>();
|
|
||||||
#pragma warning restore 0618
|
|
||||||
var server = ServerFactory.Start(_serverInstance,
|
var server = ServerFactory.Start(_serverInstance,
|
||||||
async features =>
|
async features =>
|
||||||
{
|
{
|
||||||
|
|
@ -98,12 +96,10 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
httpContext.ApplicationServices = _applicationServices;
|
httpContext.ApplicationServices = _applicationServices;
|
||||||
var requestIdentifier = GetRequestIdentifier(httpContext);
|
var requestIdentifier = GetRequestIdentifier(httpContext);
|
||||||
contextAccessor.HttpContext = httpContext;
|
contextAccessor.HttpContext = httpContext;
|
||||||
#pragma warning disable 0618
|
if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"))
|
||||||
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"))
|
|
||||||
{
|
{
|
||||||
telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext });
|
diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext });
|
||||||
}
|
}
|
||||||
#pragma warning restore 0618
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (logger.IsEnabled(LogLevel.Critical)
|
using (logger.IsEnabled(LogLevel.Critical)
|
||||||
|
|
@ -115,20 +111,16 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
#pragma warning disable 0618
|
if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"))
|
||||||
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"))
|
|
||||||
{
|
{
|
||||||
telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex });
|
diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, exception = ex });
|
||||||
}
|
}
|
||||||
#pragma warning restore 0618
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
#pragma warning disable 0618
|
if (diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"))
|
||||||
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"))
|
|
||||||
{
|
{
|
||||||
telemetrySource.WriteTelemetry("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext });
|
diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext });
|
||||||
}
|
}
|
||||||
#pragma warning restore 0618
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_applicationLifetime.NotifyStarted();
|
_applicationLifetime.NotifyStarted();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.Tracing;
|
using System.Diagnostics;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Hosting.Builder;
|
using Microsoft.AspNet.Hosting.Builder;
|
||||||
using Microsoft.AspNet.Hosting.Internal;
|
using Microsoft.AspNet.Hosting.Internal;
|
||||||
|
|
@ -99,11 +99,9 @@ namespace Microsoft.AspNet.Hosting
|
||||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
|
|
||||||
#pragma warning disable 0618
|
var diagnosticSource = new DiagnosticListener("Microsoft.AspNet");
|
||||||
var telemetrySource = new TelemetryListener("Microsoft.AspNet");
|
services.AddInstance<DiagnosticSource>(diagnosticSource);
|
||||||
services.AddInstance<TelemetrySource>(telemetrySource);
|
services.AddInstance<DiagnosticListener>(diagnosticSource);
|
||||||
services.AddInstance<TelemetryListener>(telemetrySource);
|
|
||||||
#pragma warning restore 0618
|
|
||||||
|
|
||||||
// Conjure up a RequestServices
|
// Conjure up a RequestServices
|
||||||
services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>();
|
services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
"Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*",
|
"Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*",
|
||||||
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*",
|
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*",
|
||||||
"Newtonsoft.Json": "6.0.6",
|
"Newtonsoft.Json": "6.0.6",
|
||||||
"System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*"
|
"System.Diagnostics.DiagnosticSource": "4.0.0-beta-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnx451": {
|
"dnx451": {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.Tracing;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
@ -16,7 +16,7 @@ using Microsoft.AspNet.Http.Features.Internal;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.TelemetryAdapter;
|
using Microsoft.Extensions.DiagnosticAdapter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.TestHost
|
namespace Microsoft.AspNet.TestHost
|
||||||
|
|
@ -437,21 +437,20 @@ namespace Microsoft.AspNet.TestHost
|
||||||
Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync());
|
Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable 0618
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BeginEndTelemetryAvailable()
|
public async Task BeginEndDiagnosticAvailable()
|
||||||
{
|
{
|
||||||
TelemetryListener telemetryListener = null;
|
DiagnosticListener diagnosticListener = null;
|
||||||
var server = TestServer.Create(app =>
|
var server = TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
|
diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
|
||||||
app.Run(context =>
|
app.Run(context =>
|
||||||
{
|
{
|
||||||
return context.Response.WriteAsync("Hello World");
|
return context.Response.WriteAsync("Hello World");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var listener = new TestTelemetryListener();
|
var listener = new TestDiagnosticListener();
|
||||||
telemetryListener.SubscribeWithAdapter(listener);
|
diagnosticListener.SubscribeWithAdapter(listener);
|
||||||
var result = await server.CreateClient().GetStringAsync("/path");
|
var result = await server.CreateClient().GetStringAsync("/path");
|
||||||
|
|
||||||
Assert.Equal("Hello World", result);
|
Assert.Equal("Hello World", result);
|
||||||
|
|
@ -461,19 +460,19 @@ namespace Microsoft.AspNet.TestHost
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ExceptionTelemetryAvailable()
|
public async Task ExceptionDiagnosticAvailable()
|
||||||
{
|
{
|
||||||
TelemetryListener telemetryListener = null;
|
DiagnosticListener diagnosticListener = null;
|
||||||
var server = TestServer.Create(app =>
|
var server = TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
|
diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
|
||||||
app.Run(context =>
|
app.Run(context =>
|
||||||
{
|
{
|
||||||
throw new Exception("Test exception");
|
throw new Exception("Test exception");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var listener = new TestTelemetryListener();
|
var listener = new TestDiagnosticListener();
|
||||||
telemetryListener.SubscribeWithAdapter(listener);
|
diagnosticListener.SubscribeWithAdapter(listener);
|
||||||
await Assert.ThrowsAsync<Exception>(() => server.CreateClient().GetAsync("/path"));
|
await Assert.ThrowsAsync<Exception>(() => server.CreateClient().GetAsync("/path"));
|
||||||
|
|
||||||
Assert.NotNull(listener.BeginRequest?.HttpContext);
|
Assert.NotNull(listener.BeginRequest?.HttpContext);
|
||||||
|
|
@ -481,9 +480,8 @@ namespace Microsoft.AspNet.TestHost
|
||||||
Assert.NotNull(listener.UnhandledException?.HttpContext);
|
Assert.NotNull(listener.UnhandledException?.HttpContext);
|
||||||
Assert.NotNull(listener.UnhandledException?.Exception);
|
Assert.NotNull(listener.UnhandledException?.Exception);
|
||||||
}
|
}
|
||||||
#pragma warning restore 0618
|
|
||||||
|
|
||||||
public class TestTelemetryListener
|
public class TestDiagnosticListener
|
||||||
{
|
{
|
||||||
public class OnBeginRequestEventData
|
public class OnBeginRequestEventData
|
||||||
{
|
{
|
||||||
|
|
@ -492,7 +490,7 @@ namespace Microsoft.AspNet.TestHost
|
||||||
|
|
||||||
public OnBeginRequestEventData BeginRequest { get; set; }
|
public OnBeginRequestEventData BeginRequest { get; set; }
|
||||||
|
|
||||||
[TelemetryName("Microsoft.AspNet.Hosting.BeginRequest")]
|
[DiagnosticName("Microsoft.AspNet.Hosting.BeginRequest")]
|
||||||
public virtual void OnBeginRequest(IProxyHttpContext httpContext)
|
public virtual void OnBeginRequest(IProxyHttpContext httpContext)
|
||||||
{
|
{
|
||||||
BeginRequest = new OnBeginRequestEventData()
|
BeginRequest = new OnBeginRequestEventData()
|
||||||
|
|
@ -508,7 +506,7 @@ namespace Microsoft.AspNet.TestHost
|
||||||
|
|
||||||
public OnEndRequestEventData EndRequest { get; set; }
|
public OnEndRequestEventData EndRequest { get; set; }
|
||||||
|
|
||||||
[TelemetryName("Microsoft.AspNet.Hosting.EndRequest")]
|
[DiagnosticName("Microsoft.AspNet.Hosting.EndRequest")]
|
||||||
public virtual void OnEndRequest(IProxyHttpContext httpContext)
|
public virtual void OnEndRequest(IProxyHttpContext httpContext)
|
||||||
{
|
{
|
||||||
EndRequest = new OnEndRequestEventData()
|
EndRequest = new OnEndRequestEventData()
|
||||||
|
|
@ -525,7 +523,7 @@ namespace Microsoft.AspNet.TestHost
|
||||||
|
|
||||||
public OnUnhandledExceptionEventData UnhandledException { get; set; }
|
public OnUnhandledExceptionEventData UnhandledException { get; set; }
|
||||||
|
|
||||||
[TelemetryName("Microsoft.AspNet.Hosting.UnhandledException")]
|
[DiagnosticName("Microsoft.AspNet.Hosting.UnhandledException")]
|
||||||
public virtual void OnUnhandledException(IProxyHttpContext httpContext, IProxyException exception)
|
public virtual void OnUnhandledException(IProxyHttpContext httpContext, IProxyException exception)
|
||||||
{
|
{
|
||||||
UnhandledException = new OnUnhandledExceptionEventData()
|
UnhandledException = new OnUnhandledExceptionEventData()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||||
"Microsoft.AspNet.TestHost": "1.0.0-*",
|
"Microsoft.AspNet.TestHost": "1.0.0-*",
|
||||||
"Microsoft.Extensions.TelemetryAdapter": "1.0.0-*",
|
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
|
||||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue