Activity StartIfEnabled(DiagnosticSource source, string name, object args, SendContext context) { if (!source.IsEnabled(name) || context.TryGetPayload <Activity>(out _)) { return(null); } var activity = new Activity(name) .AddTag(DiagnosticHeaders.MessageId, context.MessageId.ToString()) .AddTag(DiagnosticHeaders.InitiatorId, context.InitiatorId.ToString()) .AddTag(DiagnosticHeaders.SourceAddress, context.SourceAddress.ToString()) .AddTag(DiagnosticHeaders.DestinationAddress, context.DestinationAddress.ToString()) .AddBaggage(DiagnosticHeaders.CorrelationId, context.CorrelationId.ToString()) .AddBaggage(DiagnosticHeaders.CorrelationConversationId, context.ConversationId.ToString()); source.StartActivity(activity, args ?? new { }); Inject(context, activity); return(context.AddOrUpdatePayload(() => activity, a => activity)); }
/// <summary> /// Transfer the header information from the ConsumeContext to the SendContext, including any non-MT headers. /// </summary> /// <param name="sendContext"></param> /// <param name="consumeContext"></param> public static void TransferConsumeContextHeaders(this SendContext sendContext, ConsumeContext consumeContext) { sendContext.AddOrUpdatePayload(() => consumeContext, _ => consumeContext); sendContext.SourceAddress = consumeContext.ReceiveContext.InputAddress; if (consumeContext.ConversationId.HasValue) { sendContext.ConversationId = consumeContext.ConversationId; } if (consumeContext.CorrelationId.HasValue) { sendContext.InitiatorId = consumeContext.CorrelationId; } else if (consumeContext.RequestId.HasValue) { sendContext.InitiatorId = consumeContext.RequestId; } foreach (KeyValuePair <string, object> header in consumeContext.Headers.GetAll()) { if (header.Key.StartsWith("MT-")) { continue; } // do not overwrite headers which have already been set if (sendContext.Headers.TryGetHeader(header.Key, out _)) { continue; } sendContext.Headers.Set(header.Key, header.Value); } }