public async Task Invoke(HttpContext context, ITracingContextProvider tracingContextProvider)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (tracingContextProvider == null)
            {
                throw new ArgumentNullException(nameof(tracingContextProvider));
            }

            var unitOfWorkId = GetHeaderValueOrDefault(context.Request, TracingContextHeaders.RequestIdHeaderName);
            var causationId  = GetHeaderValueOrDefault(context.Request, TracingContextHeaders.CausationIdHeaderName);
            var flowId       = GetHeaderValueOrDefault(context.Request, TracingContextHeaders.FlowIdHeaderName);

            tracingContextProvider.SetTracingContext(new TracingContext(unitOfWorkId, causationId, flowId));

            await _next.Invoke(context);
        }
        /// <summary>
        ///     Asks the service container for the tracingcontext for the current call
        ///     and adds it to the logcontext for this call
        /// </summary>
        /// <param name="context"></param>
        /// <param name="tracingContextProvider"></param>
        /// <returns>Task</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public async Task Invoke(HttpContext context, ITracingContextProvider tracingContextProvider)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (tracingContextProvider == null)
            {
                throw new ArgumentNullException(nameof(tracingContextProvider));
            }

            if (tracingContextProvider.GetTracingContext() is TracingContext tracingContext)
            {
                using (LogContext.PushProperty("TracingContext", tracingContext, true))
                {
                    await _next(context);
                }
            }
            else
            {
                await _next(context);
            }
        }
 public SetTracingContextFromRequestHandler(ITracingContextProvider tracingContextProvider)
 {
     _tracingContextProvider = tracingContextProvider;
 }
 public AddTracingContextToRequestHandler(ITracingContextProvider tracingContextProvider,
                                          HttpMessageHandler innerHandler = null)
 {
     _tracingContextProvider = tracingContextProvider;
     InnerHandler            = innerHandler ?? new HttpClientHandler();
 }
Example #5
0
 public AddTracingContextToSerilogHandler(ITracingContextProvider tracingContextProvider)
 {
     _tracingContextProvider = tracingContextProvider;
 }