private bool TryExtractTracestate(string[] tracestateCollection, out Tracestate tracestateResult) { tracestateResult = Tracestate.Empty; var tracestateBuilder = Tracestate.Builder; try { var names = new HashSet <string>(); if (tracestateCollection != null) { // Iterate in reverse order because when call builder set the elements is added in the // front of the list. for (int i = tracestateCollection.Length - 1; i >= 0; i--) { if (!TracestateUtils.TryExtractTracestate(tracestateCollection[i], tracestateBuilder)) { return(false); } } } tracestateResult = tracestateBuilder.Build(); return(true); } catch (Exception) { // failure to parse tracestate should not disregard traceparent // TODO: logging } return(false); }
private void ExtractGenericProperties(SpanData span, out SpanKind resultKind, out DateTimeOffset timestamp, out string name, out string resultCode, out IDictionary <string, string> props, out string traceId, out string spanId, out string parentId, out Tracestate tracestate, out bool?success, out TimeSpan duration) { resultKind = span.Kind; // TODO: Should this be a part of generic logic? if (resultKind == SpanKind.Internal) { resultKind = SpanKind.Client; } // 1 tick is 100 ns timestamp = new DateTimeOffset(span.StartTimestamp); name = span.Name; props = new Dictionary <string, string>(); traceId = span.Context.TraceId.ToHexString(); spanId = span.Context.SpanId.ToHexString(); parentId = null; if (span.ParentSpanId != default) { parentId = span.ParentSpanId.ToHexString(); } resultCode = null; success = null; if (span.Status != null) { resultCode = ((int)span.Status.CanonicalCode).ToString(); success = span.Status.IsOk; if (!string.IsNullOrEmpty(span.Status.Description)) { props["statusDescription"] = span.Status.Description; } } tracestate = span.Context.Tracestate; duration = span.EndTimestamp - span.StartTimestamp; }
private void ExtractGenericProperties(ISpanData span, out SpanKind resultKind, out DateTimeOffset timestamp, out string name, out string resultCode, out IDictionary <string, string> props, out string traceId, out string spanId, out string parentId, out Tracestate tracestate, out bool?success, out TimeSpan duration) { resultKind = span.Kind; // TODO: Should this be a part of generic logic? if (resultKind == SpanKind.Internal) { if (span.HasRemoteParent.HasValue && span.HasRemoteParent.Value) { resultKind = SpanKind.Server; } else { resultKind = SpanKind.Client; } } // 1 tick is 100 ns timestamp = DateTimeOffset.FromUnixTimeSeconds(span.StartTimestamp.Seconds); timestamp = timestamp.Add(TimeSpan.FromTicks(span.StartTimestamp.Nanos / 100)); name = span.Name; props = new Dictionary <string, string>(); traceId = span.Context.TraceId.ToLowerBase16(); spanId = span.Context.SpanId.ToLowerBase16(); parentId = null; if (span.ParentSpanId != null && span.ParentSpanId.IsValid) { parentId = span.ParentSpanId.ToLowerBase16(); } resultCode = null; success = null; if (span.Status != null) { resultCode = ((int)span.Status.CanonicalCode).ToString(); success = span.Status.IsOk; if (!string.IsNullOrEmpty(span.Status.Description)) { props["statusDescription"] = span.Status.Description; } } tracestate = span.Context.Tracestate; var durationTs = span.EndTimestamp.SubtractTimestamp(span.StartTimestamp); duration = TimeSpan.FromTicks((durationTs.Seconds * TimeSpan.TicksPerSecond) + (durationTs.Nanos / 100)); }
/// <summary> /// Creates a new <see cref="SpanContext"/> with the given identifiers and options. /// </summary> /// <param name="traceId">The <see cref="TraceId"/> to associate with the <see cref="SpanContext"/>.</param> /// <param name="spanId">The <see cref="SpanId"/> to associate with the <see cref="SpanContext"/>.</param> /// <param name="traceOptions">The <see cref="TraceOptions"/> to associate with the <see cref="SpanContext"/>.</param> /// <param name="tracestate">The <see cref="Tracestate"/> to associate with the <see cref="SpanContext"/>.</param> /// <returns>A new <see cref="SpanContext"/> with the given identifiers and options.</returns> public static SpanContext Create(TraceId traceId, SpanId spanId, TraceOptions traceOptions, Tracestate tracestate) { return(new SpanContext(traceId, spanId, traceOptions, tracestate)); }
private SpanContext(TraceId traceId, SpanId spanId, TraceOptions traceOptions, Tracestate tracestate) { this.TraceId = traceId; this.SpanId = spanId; this.TraceOptions = traceOptions; this.Tracestate = tracestate; }
private void ExtractGenericProperties(Span span, out string name, out string resultCode, out string statusDescription, out string traceId, out string spanId, out string parentId, out Tracestate tracestate, out bool?success, out TimeSpan duration) { name = span.Name; statusDescription = null; traceId = span.Context.TraceId.ToHexString(); spanId = span.Context.SpanId.ToHexString(); parentId = null; if (span.ParentSpanId != default) { parentId = span.ParentSpanId.ToHexString(); } resultCode = null; success = null; if (span.Status.IsValid) { resultCode = ((int)span.Status.CanonicalCode).ToString(); success = span.Status.IsOk; if (!string.IsNullOrEmpty(span.Status.Description)) { statusDescription = span.Status.Description; } } tracestate = span.Context.Tracestate; duration = span.EndTimestamp - span.StartTimestamp; }