Exemple #1
0
        public async Task <TracingContext> TestServerContext(string requestId, string causationId, string flowId)
        {
            var serverTracingContextProvider = new SingleTracingContextProvider();

            var serverWithTracingContext = CreateServerWithTracingContext(serverTracingContextProvider);
            var httpClient = new System.Net.Http.HttpClient(serverWithTracingContext);

            if (requestId != null)
            {
                httpClient.DefaultRequestHeaders.Add(TracingContextHeaders.RequestIdHeaderName, new[] { requestId });
            }

            if (flowId != null)
            {
                httpClient.DefaultRequestHeaders.Add(TracingContextHeaders.FlowIdHeaderName, new[] { flowId });
            }

            if (causationId != null)
            {
                httpClient.DefaultRequestHeaders.Add(TracingContextHeaders.CausationIdHeaderName, new[] { causationId });
            }

            await httpClient.GetAsync(new Uri("http://niks.nl/api/Home/Index"));

            return(serverTracingContextProvider.GetTracingContext());
        }
Exemple #2
0
        public void no_tracingContext_only_sets_requestId()
        {
            var singleTracingContextProvider      = new SingleTracingContextProvider();
            var httpMessageHandler                = new DummyHandler();
            var addTracingContextToRequestHandler = new AddTracingContextToRequestHandler(singleTracingContextProvider, httpMessageHandler);
            var client = new System.Net.Http.HttpClient(addTracingContextToRequestHandler);

            var result = client.GetAsync("http://niks.nl");

            var requestId   = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.RequestIdHeaderName);
            var causationId = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.CausationIdHeaderName);
            var flowId      = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.FlowIdHeaderName);

            Assert.Equal(HttpStatusCode.OK, result.Result.StatusCode);
            Assert.False(string.IsNullOrWhiteSpace(requestId));
            Assert.Null(causationId);
            Assert.Null(flowId);
        }
Exemple #3
0
        public void tracingContext_with_uow_and_flowId_sets_all()
        {
            var singleTracingContextProvider      = new SingleTracingContextProvider();
            var httpMessageHandler                = new DummyHandler();
            var addTracingContextToRequestHandler = new AddTracingContextToRequestHandler(singleTracingContextProvider, httpMessageHandler);
            var client = new System.Net.Http.HttpClient(addTracingContextToRequestHandler);

            var tracingContext = TracingContext.CreateFromUnitOfWorkId("req1");

            singleTracingContextProvider.SetTracingContext(tracingContext);
            var result = client.GetAsync("http://niks.nl");

            var requestId   = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.RequestIdHeaderName);
            var causationId = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.CausationIdHeaderName);
            var flowId      = GetHeaderValueOrDefault(httpMessageHandler.Request, TracingContextHeaders.FlowIdHeaderName);

            Assert.Equal(HttpStatusCode.OK, result.Result.StatusCode);
            Assert.StartsWith("req1.", requestId);
            Assert.Equal("req1", causationId);
            Assert.Equal("req1", flowId);
        }