Skip to content

Commit

Permalink
propagating Exception Stack Traces
Browse files Browse the repository at this point in the history
  • Loading branch information
ppossanzini committed Jan 13, 2025
1 parent e2ee495 commit 4bb64f5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Arbitrer.GRPC/RequestsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class RequestsManager : global::Arbitrer.GRPC.GrpcServices.GrpcServicesBa
public RequestsManager(IOptions<MessageDispatcherOptions> options, ILogger<RequestsManager> logger, IServiceProvider provider,
IOptions<ArbitrerOptions> arbitrerOptions, IOptions<RequestsManagerOptions> requestsManagerOptions)
{

if (requestsManagerOptions.Value.AcceptMessageTypes.Count == 0)
{
foreach (var t in arbitrerOptions.Value.LocalTypes)
Expand Down Expand Up @@ -96,7 +95,12 @@ private async Task<string> ManageGenericArbitrerMessage<T>(RequestMessage reques
}
catch (Exception ex)
{
responseMsg = JsonConvert.SerializeObject(new Messages.ResponseMessage { Exception = ex, Status = Messages.StatusEnum.Exception ,Content = Unit.Value },
responseMsg = JsonConvert.SerializeObject(new Messages.ResponseMessage
{
Exception = ex,
OriginaStackTrace = ex.StackTrace?.ToString(),
Status = Messages.StatusEnum.Exception, Content = Unit.Value
},
_options.SerializerSettings);
_logger.LogError(ex, $"Error executing message of type {typeof(T)} from external service");
}
Expand Down
7 changes: 6 additions & 1 deletion Arbitrer.Kafka/RequestsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ private async Task ConsumeChannelMessage<T>(string msg)
responseMsg = JsonConvert.SerializeObject(
new KafkaReply()
{
Reply = new Messages.ResponseMessage { Exception = ex, Status = Messages.StatusEnum.Exception , Content = Unit.Value},
Reply = new Messages.ResponseMessage
{
Exception = ex,
OriginaStackTrace = ex.StackTrace?.ToString(),
Status = Messages.StatusEnum.Exception, Content = Unit.Value
},
CorrelationId = message.CorrelationId
}
, _options.SerializerSettings);
Expand Down
9 changes: 7 additions & 2 deletions Arbitrer.RabbitMQ/RequestsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private async void Watchguard()
await CheckRequestsConsumers(CancellationToken.None);
await ValidateConnectionQos(CancellationToken.None);
}


torebind.Clear();
await Task.Delay(TimeSpan.FromMinutes(2));
Expand Down Expand Up @@ -312,7 +312,12 @@ private async Task ConsumeChannelMessage<T>(object sender, BasicDeliverEventArgs
}
catch (Exception ex)
{
responseMsg = JsonConvert.SerializeObject(new Messages.ResponseMessage { Exception = ex, Status = Messages.StatusEnum.Exception, Content = Unit.Value},
responseMsg = JsonConvert.SerializeObject(new Messages.ResponseMessage
{
Exception = ex,
OriginaStackTrace = ex.StackTrace?.ToString(),
Status = Messages.StatusEnum.Exception, Content = Unit.Value
},
_options.SerializerSettings);
_logger.LogError(ex, $"Error executing message of type {typeof(T)} from external service");
}
Expand Down
1 change: 1 addition & 0 deletions Arbitrer/Arbitrer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public async Task<TResponse> InvokeRemoteHandler<TRequest, TResponse>(TRequest r

if (result.Status == Messages.StatusEnum.Exception)
{
_logger.LogError($"Remote handler returned an exception: {result.Exception?.Message} at {result.OriginaStackTrace}");
throw result.Exception ?? new Exception("Error executing remote command");
}

Expand Down
2 changes: 2 additions & 0 deletions Arbitrer/messages/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ResponseMessage<T>
public StatusEnum Status { get; set; }
public T Content { get; set; }
public Exception Exception { get; set; }
public string OriginaStackTrace { get; set; }
}


Expand All @@ -24,6 +25,7 @@ public class ResponseMessage
public StatusEnum Status { get; set; }
public object Content { get; set; }
public Exception Exception { get; set; }
public string OriginaStackTrace { get; set; }
}

/// <summary>
Expand Down

0 comments on commit 4bb64f5

Please sign in to comment.