public static void SetSpan(this HttpContext httpContext, TraceSpan span)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            httpContext.Items[spanKey] = span;
        }
Exemple #2
0
        public void AsChildren(TraceSpan span)
        {
            var httpContext = _httpContextAccessor.HttpContext;
            var curSpan     = httpContext.GetSpan();

            if (curSpan == null)
            {
                return;
            }
            span.ParentId = curSpan.SpanId;
            span.LaunchId = curSpan.LaunchId;
        }
        public static TraceSpan Exception(this TraceSpan span, Exception exception)
        {
            if (span == null)
            {
                return(span);
            }

            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            span.IsSuccess = false;
            span.Tags.Error(exception.Message);

            return(span);
        }
Exemple #4
0
        public TraceSpan Start()
        {
            var httpContext = _httpContextAccessor.HttpContext;
            var span        = new TraceSpan
            {
                SpanId     = Guid.NewGuid().ToString("N"),
                StartTime  = DateTime.Now,
                SystemName = _options.SystemName,
                Tags       = new TraceTags {
                    { TraceTagKeys.Environment, _options.Environment }
                }
            };

            if (httpContext.Request.Headers.ContainsKey(TracerKeys.TraceId))
            {
                span.TraceId = httpContext.Request.Headers[TracerKeys.TraceId].FirstOrDefault();
            }
            else
            {
                span.TraceId = Guid.NewGuid().ToString("N");
            }

            if (httpContext.Request.Headers.ContainsKey(TracerKeys.TraceSpanId))
            {
                span.ParentId = httpContext.Request.Headers[TracerKeys.TraceSpanId].FirstOrDefault();
            }
            else
            {
                span.ParentId = "0";
            }

            if (httpContext.Request.Headers.ContainsKey(TracerKeys.TraceLaunchId))
            {
                span.LaunchId = httpContext.Request.Headers[TracerKeys.TraceLaunchId].FirstOrDefault();
            }

            return(span);
        }
 public static TraceSpan SetSuccess(this TraceSpan traceSpan, bool isSuccess)
 {
     traceSpan.IsSuccess = isSuccess;
     return(traceSpan);
 }
 public static TraceSpan Finish(this TraceSpan traceSpan)
 {
     traceSpan.EndTime    = DateTime.Now;
     traceSpan.TimeLength = Math.Round((traceSpan.EndTime - traceSpan.StartTime).TotalMilliseconds, 4);
     return(traceSpan);
 }
 public static TraceSpan SetOperationName(this TraceSpan traceSpan, string operationName)
 {
     traceSpan.OperationName = operationName;
     return(traceSpan);
 }