Beispiel #1
0
        public void FormatTraceId_should_correctly_format_trace_context_with_full_trace_id()
        {
            var context = new TraceContext(Guid.NewGuid(), Guid.NewGuid());

            var expectedValue = $"{context.TraceId:N}";

            TracingLogPropertiesFormatter.FormatTraceId(context).Should().Be(expectedValue);
        }
Beispiel #2
0
        public void FormatSpanIdPrefix_should_produce_same_result_as_a_substring_of_guids_tostring()
        {
            var context = new TraceContext(Guid.NewGuid(), Guid.NewGuid());

            var expectedValue = context.SpanId.ToString().Substring(0, 8);

            TracingLogPropertiesFormatter.FormatSpanIdPrefix(context).Should().Be(expectedValue);
        }
        public async Task InvokeAsync(HttpContext context)
        {
            var requestInfo = FlowingContext.Globals.Get <IRequestInfo>();

            using (var spanBuilder = tracer.BeginHttpServerSpan())
                using (new OperationContextToken(
                           TracingLogPropertiesFormatter.FormatPrefix(
                               spanBuilder.CurrentSpan.ParentSpanId ?? spanBuilder.CurrentSpan.SpanId) ?? string.Empty))
                {
                    spanBuilder.SetClientDetails(requestInfo?.ClientApplicationIdentity, requestInfo?.ClientIpAddress);
                    spanBuilder.SetRequestDetails(context.Request.Path, context.Request.Method, context.Request.ContentLength);

                    SetResponseHeaderIfRequired(context, spanBuilder);

                    await next(context);

                    SetResponseHeaderIfRequired(context, spanBuilder);

                    spanBuilder.SetResponseDetails(context.Response.StatusCode, context.Response.ContentLength);
                }
        }
Beispiel #4
0
 public void FormatTraceId_should_return_null_for_null_context()
 => TracingLogPropertiesFormatter.FormatTraceId(null).Should().BeNull();
Beispiel #5
0
 public void FormatSpanIdPrefix_should_return_null_for_null_context()
 => TracingLogPropertiesFormatter.FormatSpanIdPrefix(null).Should().BeNull();