-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cleanup fault extractor * Move to faults folder * Extract fault header keys * Cosmetics * Approve API * Dots can make real differences
- Loading branch information
1 parent
aeef18c
commit 8adaa8b
Showing
4 changed files
with
104 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
src/NServiceBus.Core/Recoverability/FaultMetadataExtractor.cs
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/NServiceBus.Core/Recoverability/Faults/FaultMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace NServiceBus | ||
{ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Faults; | ||
using Transport; | ||
|
||
class FaultMetadataExtractor(Dictionary<string, string> staticFaultMetadata, Action<Dictionary<string, string>> headerCustomizations) | ||
{ | ||
public Dictionary<string, string> Extract(ErrorContext errorContext) | ||
{ | ||
var metadata = new Dictionary<string, string>(staticFaultMetadata) | ||
{ | ||
[FaultsHeaderKeys.FailedQ] = errorContext.ReceiveAddress | ||
}; | ||
|
||
SetExceptionMetadata(metadata, errorContext.Exception); | ||
|
||
headerCustomizations(metadata); | ||
|
||
return metadata; | ||
} | ||
|
||
static void SetExceptionMetadata(Dictionary<string, string> headers, Exception e) | ||
{ | ||
headers[FaultsHeaderKeys.ExceptionType] = e.GetType().FullName; | ||
|
||
if (e.InnerException != null) | ||
{ | ||
headers[FaultsHeaderKeys.InnerExceptionType] = e.InnerException.GetType().FullName; | ||
} | ||
|
||
headers[FaultsHeaderKeys.HelpLink] = e.HelpLink; | ||
headers[FaultsHeaderKeys.Message] = Truncate(e.GetMessage(), 16384); | ||
headers[FaultsHeaderKeys.Source] = e.Source; | ||
headers[FaultsHeaderKeys.StackTrace] = e.ToString(); | ||
headers[FaultsHeaderKeys.TimeOfFailure] = DateTimeOffsetHelper.ToWireFormattedString(DateTimeOffset.UtcNow); | ||
|
||
foreach (DictionaryEntry entry in e.Data) | ||
{ | ||
if (entry.Value == null) | ||
{ | ||
continue; | ||
} | ||
headers[$"{FaultsHeaderKeys.ExceptionInfoDataPrefix}{entry.Key}"] = entry.Value.ToString(); | ||
} | ||
} | ||
|
||
static string Truncate(string value, int maxLength) => | ||
string.IsNullOrEmpty(value) | ||
? value | ||
: value.Length <= maxLength | ||
? value | ||
: value[..maxLength]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters