public override async Task Invoke() { var parentActivity = Activity.Current; if (parentActivity == null) { await _handlerInvokerImplementation.Invoke(); return; } var initialTags = new ActivityTagsCollection(); foreach (var tag in parentActivity.Tags) { initialTags.Add(tag.Key, tag.Value); } initialTags["messaging.operation"] = "process"; using var activity = RebusDiagnosticConstants.ActivitySource.StartActivity($"{_messageType} process", ActivityKind.Internal, parentActivity.Context, initialTags); TagHelper.CopyBaggage(parentActivity, activity); await _handlerInvokerImplementation.Invoke(); }
private static Activity?StartActivity(OutgoingStepContext context) { var parentActivity = Activity.Current; if (parentActivity == null) { return(null); } Activity?activity = null; if (RebusDiagnosticConstants.ActivitySource.HasListeners()) { var message = context.Load <TransportMessage>(); var messageType = message.GetMessageType(); var messageWrapper = new TransportMessageWrapper(message); var activityKind = messageWrapper.GetIntentOption() == Headers.IntentOptions.PublishSubscribe ? ActivityKind.Producer : ActivityKind.Client; var activityName = $"{messageType} send"; var initialTags = TagHelper.ExtractInitialTags(messageWrapper); // Per the spec on how to handle array types: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/common.md#attributes var destinationAddresses = context.Load <DestinationAddresses>(); initialTags.Add("messaging.destination", JsonConvert.SerializeObject(destinationAddresses.ToList())); // TODO: Transport specific tags, like rabbitmq routing key activity = RebusDiagnosticConstants.ActivitySource.StartActivity(activityName, activityKind, parentActivity.Context, initialTags); TagHelper.CopyBaggage(parentActivity, activity); // TODO: Figure out if this is actually needed now // DiagnosticListener.OnActivityImport(activity, context); } SendBeforeSendEvent(context); return(activity); }