reacting to telemetry rename

This commit is contained in:
John Luo 2015-10-19 12:40:23 -07:00
parent 8bab053107
commit 828e8d755e
6 changed files with 33 additions and 45 deletions

View File

@ -1,3 +1,3 @@
{
"projects": ["src","c:/github/testing/src","/home/kiran/github/testing/src"]
"projects": ["src"]
}

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.AspNet.Builder;
@ -88,9 +88,7 @@ namespace Microsoft.AspNet.Hosting.Internal
var logger = _applicationServices.GetRequiredService<ILogger<HostingEngine>>();
var contextFactory = _applicationServices.GetRequiredService<IHttpContextFactory>();
var contextAccessor = _applicationServices.GetRequiredService<IHttpContextAccessor>();
#pragma warning disable 0618
var telemetrySource = _applicationServices.GetRequiredService<TelemetrySource>();
#pragma warning restore 0618
var diagnosticSource = _applicationServices.GetRequiredService<DiagnosticSource>();
var server = ServerFactory.Start(_serverInstance,
async features =>
{
@ -98,12 +96,10 @@ namespace Microsoft.AspNet.Hosting.Internal
httpContext.ApplicationServices = _applicationServices;
var requestIdentifier = GetRequestIdentifier(httpContext);
contextAccessor.HttpContext = httpContext;
#pragma warning disable 0618
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"))
if (diagnosticSource.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
{
using (logger.IsEnabled(LogLevel.Critical)
@ -115,20 +111,16 @@ namespace Microsoft.AspNet.Hosting.Internal
}
catch (Exception ex)
{
#pragma warning disable 0618
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"))
if (diagnosticSource.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;
}
#pragma warning disable 0618
if (telemetrySource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"))
if (diagnosticSource.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();

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting.Builder;
using Microsoft.AspNet.Hosting.Internal;
@ -98,12 +98,10 @@ namespace Microsoft.AspNet.Hosting
services.AddTransient<IHttpContextFactory, HttpContextFactory>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddLogging();
#pragma warning disable 0618
var telemetrySource = new TelemetryListener("Microsoft.AspNet");
services.AddInstance<TelemetrySource>(telemetrySource);
services.AddInstance<TelemetryListener>(telemetrySource);
#pragma warning restore 0618
var diagnosticSource = new DiagnosticListener("Microsoft.AspNet");
services.AddInstance<DiagnosticSource>(diagnosticSource);
services.AddInstance<DiagnosticListener>(diagnosticSource);
// Conjure up a RequestServices
services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>();

View File

@ -24,7 +24,7 @@
"Microsoft.Dnx.Compilation.Abstractions": "1.0.0-*",
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*",
"Newtonsoft.Json": "6.0.6",
"System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*"
"System.Diagnostics.DiagnosticSource": "4.0.0-beta-*"
},
"frameworks": {
"dnx451": {

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
@ -16,7 +16,7 @@ using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.TelemetryAdapter;
using Microsoft.Extensions.DiagnosticAdapter;
using Xunit;
namespace Microsoft.AspNet.TestHost
@ -436,22 +436,21 @@ namespace Microsoft.AspNet.TestHost
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.Equal("FoundFoo:False", await result.Content.ReadAsStringAsync());
}
#pragma warning disable 0618
[Fact]
public async Task BeginEndTelemetryAvailable()
public async Task BeginEndDiagnosticAvailable()
{
TelemetryListener telemetryListener = null;
DiagnosticListener diagnosticListener = null;
var server = TestServer.Create(app =>
{
telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
app.Run(context =>
{
return context.Response.WriteAsync("Hello World");
});
});
var listener = new TestTelemetryListener();
telemetryListener.SubscribeWithAdapter(listener);
var listener = new TestDiagnosticListener();
diagnosticListener.SubscribeWithAdapter(listener);
var result = await server.CreateClient().GetStringAsync("/path");
Assert.Equal("Hello World", result);
@ -461,19 +460,19 @@ namespace Microsoft.AspNet.TestHost
}
[Fact]
public async Task ExceptionTelemetryAvailable()
public async Task ExceptionDiagnosticAvailable()
{
TelemetryListener telemetryListener = null;
DiagnosticListener diagnosticListener = null;
var server = TestServer.Create(app =>
{
telemetryListener = app.ApplicationServices.GetRequiredService<TelemetryListener>();
diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
app.Run(context =>
{
throw new Exception("Test exception");
});
});
var listener = new TestTelemetryListener();
telemetryListener.SubscribeWithAdapter(listener);
var listener = new TestDiagnosticListener();
diagnosticListener.SubscribeWithAdapter(listener);
await Assert.ThrowsAsync<Exception>(() => server.CreateClient().GetAsync("/path"));
Assert.NotNull(listener.BeginRequest?.HttpContext);
@ -481,9 +480,8 @@ namespace Microsoft.AspNet.TestHost
Assert.NotNull(listener.UnhandledException?.HttpContext);
Assert.NotNull(listener.UnhandledException?.Exception);
}
#pragma warning restore 0618
public class TestTelemetryListener
public class TestDiagnosticListener
{
public class OnBeginRequestEventData
{
@ -492,7 +490,7 @@ namespace Microsoft.AspNet.TestHost
public OnBeginRequestEventData BeginRequest { get; set; }
[TelemetryName("Microsoft.AspNet.Hosting.BeginRequest")]
[DiagnosticName("Microsoft.AspNet.Hosting.BeginRequest")]
public virtual void OnBeginRequest(IProxyHttpContext httpContext)
{
BeginRequest = new OnBeginRequestEventData()
@ -508,7 +506,7 @@ namespace Microsoft.AspNet.TestHost
public OnEndRequestEventData EndRequest { get; set; }
[TelemetryName("Microsoft.AspNet.Hosting.EndRequest")]
[DiagnosticName("Microsoft.AspNet.Hosting.EndRequest")]
public virtual void OnEndRequest(IProxyHttpContext httpContext)
{
EndRequest = new OnEndRequestEventData()
@ -525,7 +523,7 @@ namespace Microsoft.AspNet.TestHost
public OnUnhandledExceptionEventData UnhandledException { get; set; }
[TelemetryName("Microsoft.AspNet.Hosting.UnhandledException")]
[DiagnosticName("Microsoft.AspNet.Hosting.UnhandledException")]
public virtual void OnUnhandledException(IProxyHttpContext httpContext, IProxyException exception)
{
UnhandledException = new OnUnhandledExceptionEventData()

View File

@ -2,7 +2,7 @@
"dependencies": {
"Microsoft.AspNet.Testing": "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-*"
},
"commands": {