internal ZipkinSpan GenerateSpan(ISpanData spanData, ZipkinEndpoint localEndpoint)
        {
            ISpanContext context        = spanData.Context;
            long         startTimestamp = this.ToEpochMicroseconds(spanData.StartTimestamp);
            long         endTimestamp   = this.ToEpochMicroseconds(spanData.EndTimestamp);

            ZipkinSpan.Builder spanBuilder =
                ZipkinSpan.NewBuilder()
                .TraceId(this.EncodeTraceId(context.TraceId))
                .Id(this.EncodeSpanId(context.SpanId))
                .Kind(this.ToSpanKind(spanData))
                .Name(spanData.Name)
                .Timestamp(this.ToEpochMicroseconds(spanData.StartTimestamp))
                .Duration(endTimestamp - startTimestamp)
                .LocalEndpoint(localEndpoint);

            if (spanData.ParentSpanId != null && spanData.ParentSpanId.IsValid)
            {
                spanBuilder.ParentId(this.EncodeSpanId(spanData.ParentSpanId));
            }

            foreach (var label in spanData.Attributes.AttributeMap)
            {
                spanBuilder.PutTag(label.Key, this.AttributeValueToString(label.Value));
            }

            Status status = spanData.Status;

            if (status != null)
            {
                spanBuilder.PutTag(StatusCode, status.CanonicalCode.ToString());

                if (status.Description != null)
                {
                    spanBuilder.PutTag(StatusDescription, status.Description);
                }
            }

            foreach (var annotation in spanData.Annotations.Events)
            {
                spanBuilder.AddAnnotation(this.ToEpochMicroseconds(annotation.Timestamp), annotation.Event.Description);
            }

            foreach (var networkEvent in spanData.MessageEvents.Events)
            {
                spanBuilder.AddAnnotation(this.ToEpochMicroseconds(networkEvent.Timestamp), networkEvent.Event.Type.ToString());
            }

            return(spanBuilder.Build());
        }
        private ZipkinEndpoint GetLocalZipkinEndpoint()
        {
            var result = new ZipkinEndpoint()
            {
                ServiceName = this.options.ServiceName,
            };

            string hostName = this.ResolveHostName();

            if (!string.IsNullOrEmpty(hostName))
            {
                result.Ipv4 = this.ResolveHostAddress(hostName, AddressFamily.InterNetwork);

                result.Ipv6 = this.ResolveHostAddress(hostName, AddressFamily.InterNetworkV6);
            }

            return(result);
        }
 public TraceExporterHandler(ZipkinTraceExporterOptions options, HttpClient client)
 {
     this.options       = options;
     this.localEndpoint = this.GetLocalZipkinEndpoint();
     this.httpClient    = client ?? new HttpClient();
 }
Exemplo n.º 4
0
 internal Builder RemoteEndpoint(ZipkinEndpoint val)
 {
     this.result.RemoteEndpoint = val;
     return(this);
 }
Exemplo n.º 5
0
 internal Builder LocalEndpoint(ZipkinEndpoint val)
 {
     this.result.LocalEndpoint = val;
     return(this);
 }