public void Inject_SpanContext_HeadersWithCorrectInfo()
        {
            const ulong spanId      = 10;
            const ulong traceId     = 7;
            var         spanContext = new SpanContext(traceId, spanId);

            HeaderCollectionPropagator.Inject(_headers, spanContext);

            Assert.Equal(spanId.ToString(), _headers.Get(HttpHeaderParentId));
            Assert.Equal(traceId.ToString(), _headers.Get(HttpHeaderTraceId));
        }
Beispiel #2
0
        /// <summary>
        /// Extracts a <see cref="SpanContext"/> from the specified headers.
        /// </summary>
        /// <param name="headers">The headers.</param>
        /// <returns>The <see cref="SpanContext"/></returns>
        public static SpanContext Extract(this IHeaderCollection headers)
        {
            var parentIdHeader = headers.Get(HttpHeaderNames.HttpHeaderParentId);

            if (parentIdHeader == null)
            {
                return(null);
            }

            var traceIdHeader = headers.Get(HttpHeaderNames.HttpHeaderTraceId);

            if (traceIdHeader == null)
            {
                return(null);
            }

            ulong parentId;

            try
            {
                parentId = Convert.ToUInt64(parentIdHeader);
            }
            catch (FormatException)
            {
                return(null);
            }

            ulong traceId;

            try
            {
                traceId = Convert.ToUInt64(traceIdHeader);
            }
            catch (FormatException)
            {
                return(null);
            }

            return(new SpanContext(traceId, parentId));
        }