public void CompositePropagator_UsingSameTag() { const string header01 = "custom-tracestate-01"; const string header02 = "custom-tracestate-02"; var compositePropagator = new CompositePropagator(new List <ITextFormat> { new TestPropagator("custom-traceparent", header01, true), new TestPropagator("custom-traceparent", header02), }); var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null); PropagationContext propagationContext = new PropagationContext(activityContext, null); var carrier = new Dictionary <string, string>(); compositePropagator.Inject(propagationContext, carrier, Setter); Assert.Contains(carrier, kv => kv.Key == "custom-traceparent"); // checking if the latest propagator is the one with the data. So, it will replace the previous one. Assert.Equal($"00-{this.traceId}-{this.spanId}-{header02.Split('-').Last()}", carrier["custom-traceparent"]); // resetting counter count = 0; compositePropagator.Extract(default, carrier, Getter);
public PropagationContext Extract <T>(PropagationContext context, T carrier, Func <T, string, IEnumerable <string> > getter) { if (this.defaultContext) { return(context); } IEnumerable <string> id = getter(carrier, this.idHeaderName); if (id.Count() <= 0) { return(context); } var traceparentParsed = TextMapPropagator.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions); if (!traceparentParsed) { return(context); } string tracestate = string.Empty; IEnumerable <string> tracestateCollection = getter(carrier, this.stateHeaderName); if (tracestateCollection?.Any() ?? false) { TextMapPropagator.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate); } return(new PropagationContext( new ActivityContext(traceId, spanId, traceoptions, tracestate), context.Baggage)); }
public static double[] PropagateInput(PropagationContext context, double[] input, int numOutputs) { Debug.Assert(input.Length == context.OriginalSpec.NumInputs); var outputs = new double[numOutputs]; QMPropagateInput(context.Ptr, input, outputs); return(outputs); }
public static PropagationContext CreatePropagationContext(RNNSpec spec) { var pc = new PropagationContext(QMCreatePropagationContext(Structify(spec.Layers), spec.Layers.Count, spec.NumInputs, spec.Weights.ToArray(), spec.Weights.Count)); pc.OriginalSpec = spec; return(pc); }
private static Activity CreateDummyUnrecordedActivity(PropagationContext ctx) { var activity = new Activity("unrecorded-activity"); activity.SetParentId(ctx.ActivityContext.TraceId, ctx.ActivityContext.SpanId, ctx.ActivityContext.TraceFlags); activity.TraceStateString = ctx.ActivityContext.TraceState; activity.Start(); activity.IsAllDataRequested = false; return(activity); }
/// <inheritdoc/> public global::OpenTracing.ISpanContext Extract <TCarrier>(IFormat <TCarrier> format, TCarrier carrier) { Guard.ThrowIfNull(format); Guard.ThrowIfNull(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 }); }
public void Inject <T>(PropagationContext context, T carrier, Action <T, string, string> setter) { string headerNumber = this.stateHeaderName.Split('-').Last(); var traceparent = string.Concat("00-", context.ActivityContext.TraceId.ToHexString(), "-", context.ActivityContext.SpanId.ToHexString()); traceparent = string.Concat(traceparent, "-", headerNumber); setter(carrier, this.idHeaderName, traceparent); string tracestateStr = context.ActivityContext.TraceState; if (tracestateStr?.Length > 0) { setter(carrier, this.stateHeaderName, tracestateStr); } }
public void CompositePropagator_TestPropagator() { var compositePropagator = new CompositePropagator(new List <ITextFormat> { new TestPropagator("custom-traceparent-1", "custom-tracestate-1"), new TestPropagator("custom-traceparent-2", "custom-tracestate-2"), }); var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null); PropagationContext propagationContext = new PropagationContext(activityContext, null); var carrier = new Dictionary <string, string>(); var activity = new Activity("test"); compositePropagator.Inject(propagationContext, carrier, Setter); Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-1"); Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-2"); }
/// <inheritdoc/> public PropagationContext Extract <T>(PropagationContext context, T carrier, Func <T, string, IEnumerable <string> > getter) { if (context.ActivityContext.IsValid()) { return(context); } if (carrier == null) { AWSXRayEventSource.Log.FailedToExtractActivityContext(nameof(AWSXRayPropagator), "null carrier"); return(context); } if (getter == null) { AWSXRayEventSource.Log.FailedToExtractActivityContext(nameof(AWSXRayPropagator), "null getter"); return(context); } try { var parentTraceHeader = getter(carrier, AWSXRayTraceHeaderKey); if (parentTraceHeader == null || parentTraceHeader.Count() != 1) { return(context); } var parentHeader = parentTraceHeader.First(); if (!TryParseXRayTraceHeader(parentHeader, out var newActivityContext)) { return(context); } return(new PropagationContext(newActivityContext, context.Baggage)); } catch (Exception ex) { AWSXRayEventSource.Log.ActivityContextExtractException(nameof(AWSXRayPropagator), ex); } return(context); }
/// <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 }); }
public override ValidationResult DoDiscardModifierInContextOf(System.Object context) { // verify if context doesn't match requirements of this limiter if (!DoesContextMatch(context)) { // context is not in scope of this limiter // don't limit return(ValidationResult.Pass()); } // verify if context matches battle context if (context is PropagationContext) { // Get propagation context PropagationContext propagationContext = (PropagationContext)context; // verify if destination unit is set if (propagationContext.DestinationPartyUnit != null) { // verify if we need to propagate UPM if (doPropagateUPM) { // don't limit return(ValidationResult.Pass()); } else { // limit (do not propagate this UPM) return(ValidationResult.Discard(onDiscardMessage)); } } else { // limit (do not propagate this UPM) return(ValidationResult.Discard(onDiscardMessage)); } } // don't limit return(ValidationResult.Pass()); }
/// <inheritdoc/> public void Inject <T>(PropagationContext context, T carrier, Action <T, string, string> setter) { if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default) { AWSXRayEventSource.Log.FailedToInjectActivityContext(nameof(AWSXRayPropagator), "Invalid context"); return; } if (carrier == null) { AWSXRayEventSource.Log.FailedToInjectActivityContext(nameof(AWSXRayPropagator), "null carrier"); return; } if (setter == null) { AWSXRayEventSource.Log.FailedToInjectActivityContext(nameof(AWSXRayPropagator), "null setter"); return; } var sb = new StringBuilder(); sb.Append(RootKey); sb.Append(KeyValueDelimiter); sb.Append(ToXRayTraceIdFormat(context.ActivityContext.TraceId.ToHexString())); sb.Append(TraceHeaderDelimiter); sb.Append(ParentKey); sb.Append(KeyValueDelimiter); sb.Append(context.ActivityContext.SpanId.ToHexString()); sb.Append(TraceHeaderDelimiter); sb.Append(SampledKey); sb.Append(KeyValueDelimiter); sb.Append((context.ActivityContext.TraceFlags & ActivityTraceFlags.Recorded) != 0 ? SampledValue : NotSampledValue); setter(carrier, AWSXRayTraceHeaderKey, sb.ToString()); }
/// <summary> /// Creates root (first level) activity that describes incoming request. /// </summary> /// <param name="textMapPropagator"><see cref="TextMapPropagator"/>.</param> /// <param name="context"><see cref="HttpContext"/>.</param> /// <param name="onRequestStartedCallback">Callback action.</param> /// <returns>New root activity.</returns> public static Activity StartAspNetActivity(TextMapPropagator textMapPropagator, HttpContext context, Action <Activity, HttpContext> onRequestStartedCallback) { Debug.Assert(context != null, "Context is null."); PropagationContext propagationContext = textMapPropagator.Extract(default, context.Request, HttpRequestHeaderValuesGetter);
public Activity StartEntrypointActivity(string name, ActivityKind kind, PropagationContext parentContext, IEnumerable <KeyValuePair <string, object> > tags = null, IEnumerable <ActivityLink> links = null, DateTimeOffset startTime = default) { return(this.ActivitySource.StartActivity(name, kind, parentContext.ActivityContext, tags, links, startTime) ?? CreateDummyUnrecordedActivity(parentContext)); }
public override void Inject <T>(PropagationContext context, T carrier, Action <T, string, string> setter) { }
public override PropagationContext Extract <T>(PropagationContext context, T carrier, Func <T, string, IEnumerable <string> > getter) { return(DefaultPropagationContext); }
public override void Inject <T>(PropagationContext context, T carrier, Action <T, string, string> setter) { throw new NotImplementedException(); }
public override PropagationContext Extract <T>(PropagationContext context, T carrier, Func <T, string, IEnumerable <string> > getter) { return(new PropagationContext(this.activityContext, this.baggage)); }
public ActivityContext traceContextFromGrpcContext(Grpc.Core.ServerCallContext context) { var spanCtx = new PropagationContext(); return(b3propagator.Extract(spanCtx, context.RequestHeaders, Getter).ActivityContext); }