private static Thrift.Endpoint ConvertToThrift(IPEndPoint ipEndPoint, string serviceName) { return(new Thrift.Endpoint() { Ipv4 = SerializerUtils.IpToInt(ipEndPoint.Address), Port = (short)ipEndPoint.Port, Service_name = serviceName }); }
private void SerializeSpan(StreamWriter writer, Span span) { var serviceName = SerializerUtils.GetServiceNameOrDefault(span); var endPoint = span.Endpoint ?? SerializerUtils.DefaultEndPoint; writer.Write(openingBrace); if (span.Annotations.Count != 0) { writer.WriteList( SerializeAnnotation, annotations, span.Annotations, endPoint, serviceName ); } if (span.BinaryAnnotations.Count != 0) { writer.Write(comma); writer.WriteList( SerializeBinaryAnnotation, binaryAnnotations, span.BinaryAnnotations, endPoint, serviceName ); } writer.Write(comma); writer.WriteField(debug, false); writer.Write(comma); writer.WriteField(id, NumberUtils.EncodeLongToLowerHexString(span.SpanState.SpanId)); writer.Write(comma); writer.WriteField(name, span.Name ?? SerializerUtils.DefaultRpcMethodName); writer.Write(comma); var hexTraceIdHigh = TraceManager.Trace128Bits ? NumberUtils.EncodeLongToHexString(span.SpanState.TraceIdHigh) : ""; writer.WriteField(traceId, hexTraceIdHigh + NumberUtils.EncodeLongToHexString(span.SpanState.TraceId)); if (span.SpanStarted.HasValue) { writer.Write(comma); writer.WriteField(timestamp, span.SpanStarted.Value.ToUnixTimestamp()); } if (span.Duration.HasValue && span.Duration.Value.TotalMilliseconds > 0) { writer.Write(comma); writer.WriteField(duration, (long)(span.Duration.Value.TotalMilliseconds * 1000)); // microseconds } if (!span.IsRoot) { writer.Write(comma); writer.WriteField(parentId, NumberUtils.EncodeLongToLowerHexString(span.SpanState.ParentSpanId.Value)); } writer.Write(closingBrace); }
private static void SerializeEndPoint(StreamWriter writer, IPEndPoint endPoint, string serviceName) { writer.Write(openingBrace); writer.WriteField(ipv4, SerializerUtils.IpToInt(endPoint.Address)); writer.Write(comma); writer.WriteField(port, (short)endPoint.Port); writer.Write(comma); writer.WriteField(JSONSpanSerializer.serviceName, serviceName); writer.Write(closingBrace); }
/// <summary> /// Convert this span object to its Thrift equivalent. /// </summary> /// <returns></returns> public static Thrift.Span ConvertToThrift(Span span) { var thriftSpan = new Thrift.Span() { Id = span.SpanState.SpanId, Trace_id_high = span.SpanState.TraceIdHigh, Trace_id = span.SpanState.TraceId, Name = span.Name ?? SerializerUtils.DefaultRpcMethodName, Debug = false }; if (!span.IsRoot) { thriftSpan.Parent_id = span.SpanState.ParentSpanId; } if (span.SpanStarted.HasValue) { thriftSpan.Timestamp = span.SpanStarted.Value.ToUnixTimestamp(); } // Use default value if no information were recorded var spanEndpoint = span.Endpoint ?? SerializerUtils.DefaultEndPoint; var spanServiceName = SerializerUtils.GetServiceNameOrDefault(span); var host = ConvertToThrift(spanEndpoint, spanServiceName); var thriftAnnotations = span.Annotations.Select(ann => ConvertToThrift(ann, host)).ToList(); if (thriftAnnotations.Count > 0) { thriftSpan.Annotations = thriftAnnotations; } var thriftBinaryAnnotations = span.BinaryAnnotations.Select(ann => ConvertToThrift(ann, host)).ToList(); if (thriftBinaryAnnotations.Count > 0) { thriftSpan.Binary_annotations = thriftBinaryAnnotations; } if (span.Duration.HasValue && span.Duration.Value.TotalMilliseconds > 0) { thriftSpan.Duration = (long)(span.Duration.Value.TotalMilliseconds * 1000); // microseconds } return(thriftSpan); }