/// <summary> /// Responsible for setting up an overarching Scope and then registering with the end of pipeline disposal. /// </summary> /// <param name="httpContext">Instance of Microsoft.AspNetCore.Http.DefaultHttpContext</param> internal static void Initialize(object httpContext) { var context = new AspNetAmbientContext(TopLevelOperationName, httpContext); if (context.AbortRegistration) { return; } if (httpContext.TryGetPropertyValue("Items", out IDictionary <object, object> contextItems)) { contextItems[HttpContextKey] = context; } }
/// <summary> /// Entry method for invoking the beginning of every web server request pipeline /// </summary> /// <param name="httpContext">Instance being instrumented.</param> /// <param name="features">Initialize features.</param> /// <param name="opCode">The OpCode used in the original method call.</param> /// <param name="mdToken">The mdToken of the original method call.</param> /// <param name="moduleVersionPtr">A pointer to the module version GUID.</param> // [InterceptMethod( // TargetAssembly = "Microsoft.AspNetCore.Http.Abstractions", // TargetType = DefaultHttpContextTypeName, // TargetSignatureTypes = new[] { ClrNames.Void, ClrNames.Ignore })] // *************************************************************** // DISABLED UNTIL WE FIX SCOPING ISSUES AT HTTP CONTEXT LEVEL // *************************************************************** public static void Initialize(object httpContext, object features, int opCode, int mdToken, long moduleVersionPtr) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } var httpContextType = httpContext.GetInstrumentedType(DefaultHttpContextTypeName); Action <object, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Action <object, object> > .Start(moduleVersionPtr, mdToken, opCode, nameof(Initialize)) .WithConcreteType(httpContextType) .WithParameters(features) .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: DefaultHttpContextTypeName, methodName: nameof(Initialize), instanceType: httpContext.GetType().AssemblyQualifiedName); throw; } try { instrumentedMethod.Invoke(httpContext, features); } catch (Exception ex) { Log.Error(ex, $"Error calling {DefaultHttpContextTypeName}.{nameof(Initialize)}(...)"); throw; } if (Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationName)) { AspNetAmbientContext.Initialize(httpContext); } }
internal static AspNetAmbientContext RetrieveFromHttpContext(object httpContext) { AspNetAmbientContext context = null; try { if (httpContext.TryGetPropertyValue("Items", out IDictionary <object, object> contextItems)) { if (contextItems?.ContainsKey(HttpContextKey) ?? false) { context = contextItems[HttpContextKey] as AspNetAmbientContext; } } } catch (Exception ex) { Log.Error(ex, $"Error accessing {nameof(AspNetAmbientContext)}."); } return(context); }
/// <summary> /// Entry method for invoking the beginning of every web server request pipeline /// </summary> /// <param name="httpContext">Instance being instrumented.</param> /// <param name="features">Initialize features.</param> /// <param name="opCode">The OpCode used in the original method call.</param> /// <param name="mdToken">The mdToken of the original method call.</param> // [InterceptMethod( // TargetAssembly = "Microsoft.AspNetCore.Http.Abstractions", // TargetType = "Microsoft.AspNetCore.Http.DefaultHttpContext", // TargetSignatureTypes = new[] { ClrNames.Void, ClrNames.Ignore })] // *************************************************************** // DISABLED UNTIL WE FIX SCOPING ISSUES AT HTTP CONTEXT LEVEL // *************************************************************** public static void Initialize(object httpContext, object features, int opCode, int mdToken) { var httpContextType = httpContext.GetType(); string methodDef = $"{httpContextType.FullName}.Initialize(IFeatureCollection features)"; Action <object, object> instrumentedMethod = null; try { instrumentedMethod = MethodBuilder <Action <object, object> > .Start(Assembly.GetCallingAssembly(), mdToken, opCode, nameof(Initialize)) .WithConcreteType(httpContextType) .WithParameters(features) .Build(); } catch (Exception ex) { Log.ErrorException($"Error retrieving {methodDef}", ex); throw; } try { instrumentedMethod.Invoke(httpContext, features); } catch (Exception ex) { Log.ErrorException($"Error calling {methodDef}", ex); throw; } if (Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationName)) { AspNetAmbientContext.Initialize(httpContext); } }