/// <inheritdoc/> public global::OpenTracing.ISpanContext Extract <TCarrier>(global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } ActivityContext activityContext = default; if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { var carrierMap = new Dictionary <string, IEnumerable <string> >(); foreach (var entry in textMapCarrier) { carrierMap.Add(entry.Key, new[] { entry.Value }); } IEnumerable <string> GetCarrierKeyValue(Dictionary <string, IEnumerable <string> > source, string key) { if (key == null || !source.TryGetValue(key, out var value)) { return(null); } return(value); } activityContext = this.textFormat.Extract(default, carrierMap, GetCarrierKeyValue);
/// <inheritdoc/> public void Inject <TCarrier>( global::OpenTracing.ISpanContext spanContext, global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (spanContext is null) { throw new ArgumentNullException(nameof(spanContext)); } if (!(spanContext is SpanContextShim shim)) { throw new ArgumentException("context is not a valid SpanContextShim object"); } if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { this.textFormat.Inject(shim.SpanContext, textMapCarrier, (adapter, key, value) => adapter.Set(key, value)); } }
public void Inject <TCarrier>( global::OpenTracing.ISpanContext spanContext, global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (spanContext is null) { throw new ArgumentNullException(nameof(spanContext)); } if (!(spanContext is SpanContextShim shim)) { throw new ArgumentException("context is not a valid SpanContextShim object"); } if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } // TODO Add binary support post OpenTracing vNext. if (format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) { // We know carrier is of Type ITextMap because we made it in here. this.tracer.TextFormat?.Inject(shim.SpanContext, (ITextMap)carrier, (adapter, key, value) => adapter.Set(key, value)); } }
/// <inheritdoc/> public global::OpenTracing.ISpanContext Extract <TCarrier>(global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } Trace.SpanContext spanContext = default; if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { var carrierMap = new Dictionary <string, IEnumerable <string> >(); foreach (var entry in textMapCarrier) { carrierMap.Add(entry.Key, new[] { entry.Value }); } IEnumerable <string> GetCarrierKeyValue(Dictionary <string, IEnumerable <string> > source, string key) { if (key == null || !source.TryGetValue(key, out var value)) { return(null); } return(value); } if (this.tracer.TextFormat != null) { spanContext = this.tracer.TextFormat.Extract(carrierMap, GetCarrierKeyValue); } } else if (format == BuiltinFormats.Binary && carrier is IBinary binaryCarrier) { var ms = binaryCarrier.Get(); if (ms != null && this.tracer.BinaryFormat != null) { spanContext = this.tracer.BinaryFormat.FromByteArray(ms.ToArray()); } } return(!spanContext.IsValid ? null : new SpanContextShim(spanContext)); }
public global::OpenTracing.ISpanContext Extract <TCarrier>(global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } Trace.SpanContext spanContext = null; // TODO Add binary support post OpenTracing vNext. if (format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) { // We know carrier is of Type ITextMap because we made it in here. var carrierMap = new Dictionary <string, IEnumerable <string> >(); foreach (var entry in (ITextMap)carrier) { carrierMap.Add(entry.Key, new[] { entry.Value }); } IEnumerable <string> GetCarrierKeyValue(Dictionary <string, IEnumerable <string> > source, string key) { if (key == null || !source.TryGetValue(key, out var value)) { return(null); } return(value); } spanContext = this.tracer.TextFormat?.Extract(carrierMap, GetCarrierKeyValue); } return((spanContext == null || !spanContext.IsValid) ? null : new SpanContextShim(spanContext)); }
/// <inheritdoc/> public global::OpenTracing.ISpanContext Extract <TCarrier>(global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } PropagationContext propagationContext = default; if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { var carrierMap = new Dictionary <string, IEnumerable <string> >(); foreach (var entry in textMapCarrier) { carrierMap.Add(entry.Key, new[] { entry.Value }); }
/// <inheritdoc/> public global::OpenTracing.ISpanContext Extract <TCarrier>(global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } Trace.SpanContext spanContext = default; if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { var carrierMap = new Dictionary <string, IEnumerable <string> >(); foreach (var entry in textMapCarrier) { carrierMap.Add(entry.Key, new[] { entry.Value }); } IEnumerable <string> GetCarrierKeyValue(Dictionary <string, IEnumerable <string> > source, string key) { if (key == null || !source.TryGetValue(key, out var value)) { return(null); } return(value); } spanContext = this.textFormat.Extract(carrierMap, GetCarrierKeyValue); } // TODO: remove comment after spanshim changes // return !spanContext.IsValid ? null : new SpanContextShim(spanContext); return(default);
/// <inheritdoc/> public void Inject <TCarrier>( global::OpenTracing.ISpanContext spanContext, global::OpenTracing.Propagation.IFormat <TCarrier> format, TCarrier carrier) { if (spanContext is null) { throw new ArgumentNullException(nameof(spanContext)); } if (!(spanContext is SpanContextShim shim)) { throw new ArgumentException("context is not a valid SpanContextShim object"); } if (format is null) { throw new ArgumentNullException(nameof(format)); } if (carrier == null) { throw new ArgumentNullException(nameof(carrier)); } if ((format == BuiltinFormats.TextMap || format == BuiltinFormats.HttpHeaders) && carrier is ITextMap textMapCarrier) { this.tracer.TextFormat?.Inject(shim.SpanContext, textMapCarrier, (adapter, key, value) => adapter.Set(key, value)); } else if (format == BuiltinFormats.Binary && carrier is IBinary binaryCarrier) { var bytes = this.tracer.BinaryFormat?.ToByteArray(shim.SpanContext); if (bytes != null) { binaryCarrier.Set(new System.IO.MemoryStream(bytes)); } } }