public async Task Forward_PropagateAsPredefined_ExpectPredefinedHeader(CorrelationContext correlationContext)
        {
            // arrange
            var incomingHeader      = HttpHeaders.RequestId;
            var outgoindHeader      = "X-MyRequest-Id";
            var propagationSettings = PropagationSettings.PropagateAs(outgoindHeader);

            _correlationContextAccessor
            .Setup(a => a.CorrelationContext)
            .Returns(correlationContext);

            void AssertRequest(HttpRequestMessage r)
            {
                Assert.True(r.Headers.Contains(outgoindHeader));
                Assert.Contains(TestCorrelationId.Value, r.Headers.GetValues(outgoindHeader));
            }

            var handler = CreateMessageHandler(propagationSettings, _correlationContextAccessor, AssertRequest);

            // act & assert (via test delegating handler)
            var client = new HttpClient(handler);

            _ = await client
                .GetAsync("https://www.example.com/")
                .ConfigureAwait(false);
        }
Example #2
0
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddDefaultCorrelator(options =>
                {
                    options.ReadFrom.Clear();
                    options.ReadFrom.Add("X-Correlation-Id");

                    options.Factory = (_) => CorrelationId.FromString("le_correlation");
                    options.Emit    = PropagationSettings.PropagateAs("X-Correlation-Id");
                    options.ReplaceTraceIdentifier = false;
                    options.LoggingScope           = LoggingScopeSettings.IncludeLoggingScope("Correlation");
                });
            }
Example #3
0
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddDefaultCorrelator(o =>
                {
                    o.Forward = PropagationSettings.PropagateAs("X-Request-Id");
                });

                services
                .AddHttpClient(
                    BetaClientName,
                    httpClient => httpClient.BaseAddress = new Uri("http://localhost:8082"))
                .WithCorrelation();
            }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDefaultCorrelator(options =>
            {
                options.Forward      = PropagationSettings.PropagateAs("X-Correlation-Id");
                options.Emit         = PropagationSettings.PropagateAs("X-Correlation-Id");
                options.LoggingScope = LoggingScopeSettings.IncludeLoggingScope("Correlation");
            });

            services
            .AddHttpClient("DummyClient")
            .WithCorrelation();

            services.AddControllers();
        }
Example #5
0
        public async Task Emits_WhenEmmitingUsingCustomHeader_ExpectCorrelationIdEmittedWithPredefinedHeader()
        {
            // arrange
            var incomingHeader = HttpHeaders.AspNetRequestId;
            var outgoingHeader = "X-Le-Custom-Request-Id";

            var options = CreateEmitOptions(PropagationSettings.PropagateAs(outgoingHeader));

            var httpContext        = new DefaultHttpContext();
            var correlationContext = new RequestCorrelationContext(
                CorrelationId.FromString("123"),
                incomingHeader);

            // act
            var emitter = new CorrelationEmitter(options, _logger);
            await emitter
            .Emit(httpContext, correlationContext)
            .ConfigureAwait(false);

            // assert
            Assert.Contains(outgoingHeader, httpContext.Response.Headers);
            Assert.Equal("123", httpContext.Response.Headers[outgoingHeader]);
        }