Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set correct span status for Send and SendAsync #2397

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions src/Paramore.Brighter/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ public void Send<T>(T command) where T : class, IRequest

using (var builder = new PipelineBuilder<T>(_subscriberRegistry, _handlerFactorySync, _inboxConfiguration))
{
bool success = false;
try
{
s_logger.LogInformation("Building send pipeline for command: {CommandType} {Id}", command.GetType(),
Expand All @@ -290,16 +289,15 @@ public void Send<T>(T command) where T : class, IRequest
AssertValidSendPipeline(command, handlerChain.Count());

handlerChain.First().Handle(command);
success = true;
}
catch (Exception)
{
success = false;
span.span?.SetStatus(ActivityStatusCode.Error);
throw;
}
finally
{
EndSpan(span.span, success);
EndSpan(span.span);
}

}
Expand Down Expand Up @@ -328,25 +326,23 @@ public void Send<T>(T command) where T : class, IRequest

using (var builder = new PipelineBuilder<T>(_subscriberRegistry, _handlerFactoryAsync, _inboxConfiguration))
{
bool success = false;
try
{
s_logger.LogInformation("Building send async pipeline for command: {CommandType} {Id}", command.GetType(), command.Id);
var handlerChain = builder.BuildAsync(requestContext, continueOnCapturedContext);
s_logger.LogInformation("Building send async pipeline for command: {CommandType} {Id}", command.GetType(), command.Id);
var handlerChain = builder.BuildAsync(requestContext, continueOnCapturedContext);

AssertValidSendPipeline(command, handlerChain.Count());
AssertValidSendPipeline(command, handlerChain.Count());

await handlerChain.First().HandleAsync(command, cancellationToken).ConfigureAwait(continueOnCapturedContext);
success = true;
await handlerChain.First().HandleAsync(command, cancellationToken).ConfigureAwait(continueOnCapturedContext);
}
catch (Exception e)
catch (Exception e)
{
success = false;
span.span?.SetStatus(ActivityStatusCode.Error);
throw;
}
finally
{
EndSpan(span.span, success);
EndSpan(span.span);
}
}
}
Expand Down Expand Up @@ -390,12 +386,15 @@ public void Publish<T>(T @event) where T : class, IRequest
}
catch (Exception e)
{
exceptions.Add(e);
exceptions.Add(e);
}
}

if (span.created)
EndSpan(span.span, exceptions.Any());
if (span.created) {
if (exceptions.Any())
span.span?.SetStatus(ActivityStatusCode.Error);
EndSpan(span.span);
}

if (exceptions.Any())
{
Expand Down Expand Up @@ -447,12 +446,16 @@ public void Publish<T>(T @event) where T : class, IRequest
}
catch (Exception e)
{
exceptions.Add(e);
exceptions.Add(e);
}
}

if (span.created)
EndSpan(span.span, exceptions.Any());


if (span.created) {
if (exceptions.Any())
span.span?.SetStatus(ActivityStatusCode.Error);
EndSpan(span.span);
}

if (exceptions.Count > 0)
{
Expand All @@ -471,10 +474,10 @@ public void Publish<T>(T @event) where T : class, IRequest
return (Activity.Current, create);
}

private void EndSpan(Activity span, bool success)
private void EndSpan(Activity span)
{
var status = success ? ActivityStatusCode.Error : ActivityStatusCode.Ok;
span?.SetStatus(status);
if (span?.Status == ActivityStatusCode.Unset)
span.SetStatus(ActivityStatusCode.Ok);
span?.Dispose();
}

Expand Down