internal static async Task Receive(MessageEnvelope envelope, SpanSetup receiveSpanSetup, ITracer tracer, Func <Task> receive) { var message = envelope.Message; var parentSpanCtx = envelope.Header != null ? tracer.Extract(BuiltinFormats.TextMap, new TextMapExtractAdapter(envelope.Header.ToDictionary())) : null; using (var scope = tracer.BuildStartedScope(parentSpanCtx, nameof(Receive), message, receiveSpanSetup)) { try { var span = scope.Span; if (envelope.Sender != null) { ProtoTags.SenderPID.Set(span, envelope.Sender.ToShortString()); } receiveSpanSetup?.Invoke(span, message); await receive().ConfigureAwait(false); } catch (Exception ex) { ex.SetupSpan(scope.Span); throw; } } }
public static IScope BuildStartedScope(this ITracer tracer, ISpanContext parentSpan, string verb, object message, SpanSetup spanSetup) { var messageType = message?.GetType().Name ?? "Unknown"; var scope = tracer .BuildSpan($"{verb} {messageType}") // <= perhaps is not good to have the operation name mentioning the message type .AsChildOf(parentSpan) .StartActive(true); ProtoTags.MessageType.Set(scope.Span, messageType); spanSetup?.Invoke(scope.Span, message); return(scope); }