public async Task <ClusterResult> ExecuteAsync(IRequestContext context, Func <IRequestContext, Task <ClusterResult> > next) { ClusterResult clusterResult; using (var span = Trace.BeginSpan()) { if (!string.IsNullOrEmpty(serviceName)) { span.SetAnnotation(TracingAnnotationNames.Service, serviceName); } span.SetAnnotation(TracingAnnotationNames.Kind, "cluster-client"); span.SetAnnotation(TracingAnnotationNames.Component, "cluster-client"); span.SetAnnotation(TracingAnnotationNames.ClusterStrategy, context.Strategy.ToString()); span.SetAnnotation(TracingAnnotationNames.HttpUrl, context.Request.Url.ToStringWithoutQuery()); span.SetAnnotation(TracingAnnotationNames.HttpMethod, context.Request.Method); span.SetAnnotation(TracingAnnotationNames.HttpRequestContentLength, context.Request.Content?.Length ?? 0); clusterResult = await next(context).ConfigureAwait(false); span.SetAnnotation(TracingAnnotationNames.ClusterStatus, clusterResult.Status); span.SetAnnotation(TracingAnnotationNames.HttpCode, (int)clusterResult.Response.Code); span.SetAnnotation(TracingAnnotationNames.HttpResponseContentLength, clusterResult.Response.Content.Length); } return(clusterResult); }
public async Task Invoke(HttpContext context) { using (var spanBuilder = Trace.BeginSpan()) { var url = GetUrl(context.Request); spanBuilder.SetAnnotation(TracingAnnotationNames.Operation, GetOperationName(context.Request.Method, url)); spanBuilder.SetAnnotation(TracingAnnotationNames.Kind, "http-server"); spanBuilder.SetAnnotation(TracingAnnotationNames.Service, serviceName); spanBuilder.SetAnnotation(TracingAnnotationNames.Host, HostnameProvider.Get()); spanBuilder.SetAnnotation(TracingAnnotationNames.HttpUrl, url.ToStringWithoutQuery()); if (context.Request.ContentLength.HasValue) { spanBuilder.SetAnnotation(TracingAnnotationNames.HttpRequestContentLength, context.Request.ContentLength); } try { await next.Invoke(context).ConfigureAwait(false); if (context.Response.ContentLength.HasValue) { spanBuilder.SetAnnotation(TracingAnnotationNames.HttpResponseContentLength, context.Response.ContentLength); } spanBuilder.SetAnnotation(TracingAnnotationNames.HttpCode, context.Response.StatusCode); } catch { spanBuilder.SetAnnotation(TracingAnnotationNames.HttpCode, (int)HttpStatusCode.InternalServerError); context.Response.StatusCode = 500; } } }
public async Task <Response> SendAsync(Request request, TimeSpan timeout, CancellationToken cancellationToken) { Response response; using (var span = Trace.BeginSpan()) { span.SetAnnotation(TracingAnnotationNames.Kind, "http-client"); span.SetAnnotation(TracingAnnotationNames.Component, "cluster-client"); span.SetAnnotation(TracingAnnotationNames.HttpUrl, request.Url.ToStringWithoutQuery()); span.SetAnnotation(TracingAnnotationNames.HttpMethod, request.Method); span.SetAnnotation(TracingAnnotationNames.HttpRequestContentLength, request.Content?.Length ?? 0); response = await transport.SendAsync(request, timeout, cancellationToken).ConfigureAwait(false); span.SetAnnotation(TracingAnnotationNames.HttpCode, (int)response.Code); span.SetAnnotation(TracingAnnotationNames.HttpResponseContentLength, response.Content.Length); } return(response); }