/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TContext">Controller context</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="controllerContext">The context of the controller</param> /// <param name="actionName">Name of the action</param> /// <param name="callback">Async callback</param> /// <param name="state">The state of the method</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget, TContext>(TTarget instance, TContext controllerContext, string actionName, AsyncCallback callback, object state) { Scope scope = null; try { if (HttpContext.Current != null) { var duckedControllerContext = controllerContext.DuckCast <ControllerContextStruct>(); scope = AspNetMvcIntegration.CreateScope(duckedControllerContext); SharedItems.PushScope(HttpContext.Current, AspNetMvcIntegration.HttpContextKey, scope); } } catch (Exception ex) { Log.Error(ex, "Error instrumenting method {MethodName}", "System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction()"); } if (scope == null) { return(CallTargetState.GetDefault()); } return(new CallTargetState(scope)); }
public void TestOneItem() { // Arrange const string key = "key"; var scope = new Scope(null, null, null, false); var context = CreateContext(); // Act SharedItems.PushScope(context, key, scope); // Assert Assert.Equal(scope, SharedItems.TryPopScope(context, key)); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TController">Type of the controller context</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="controllerContext">The context of the controller</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget, TController>(TTarget instance, TController controllerContext, CancellationToken cancellationToken) where TController : IHttpControllerContext { // Make sure to box the controllerContext proxy only once var boxedControllerContext = (IHttpControllerContext)controllerContext; var scope = AspNetWebApi2Integration.CreateScope(boxedControllerContext, out _); if (scope != null) { SharedItems.PushScope(HttpContext.Current, AspNetWebApi2Integration.HttpContextKey, scope); return(new CallTargetState(scope, boxedControllerContext)); } return(CallTargetState.GetDefault()); }
public void TestStackingItems() { // Arrange const string key = "key"; var scope1 = new Scope(null, null, null, false); var scope2 = new Scope(scope1, null, null, false); var scope3 = new Scope(scope2, null, null, false); var context = CreateContext(); // Act SharedItems.PushScope(context, key, scope1); SharedItems.PushScope(context, key, scope2); SharedItems.PushScope(context, key, scope3); // Assert Assert.Equal(scope3, SharedItems.TryPopScope(context, key)); Assert.Equal(scope2, SharedItems.TryPopScope(context, key)); Assert.Equal(scope1, SharedItems.TryPopScope(context, key)); }